From be440a56f4e3ec4a845f12d4227cf48eb1581d01 Mon Sep 17 00:00:00 2001 From: Robert Spencer Date: Tue, 7 May 2024 16:40:01 +0200 Subject: [PATCH] Use default country as standard --- src/CartToFamily.php | 278 +++++++++++---------- src/ChurchCRM/data/States.php | 3 +- src/ChurchCRM/dto/CountryDropDown.php | 30 +++ src/ChurchCRM/dto/StateDropDown.php | 42 ++++ src/Include/StateDropDown.php | 35 --- src/PersonEditor.php | 334 ++++++++++---------------- src/Reports/ConfirmLabels.php | 2 +- src/Reports/NewsLetterLabels.php | 2 +- src/Reports/TaxReport.php | 11 +- 9 files changed, 348 insertions(+), 389 deletions(-) create mode 100644 src/ChurchCRM/dto/CountryDropDown.php create mode 100644 src/ChurchCRM/dto/StateDropDown.php delete mode 100644 src/Include/StateDropDown.php diff --git a/src/CartToFamily.php b/src/CartToFamily.php index 43b39c369d..a4b5b3e229 100644 --- a/src/CartToFamily.php +++ b/src/CartToFamily.php @@ -1,28 +1,18 @@ isAddRecordsEnabled()); +if (AuthenticationManager::getCurrentUser()->isAddRecordsEnabled() === false) { + RedirectUtils::securityRedirect('AddRecords'); +}; // Was the form submitted? if (isset($_POST['Submit']) && count($_SESSION['aPeopleCart']) > 0) { @@ -50,18 +40,20 @@ $sCity = SelectWhichInfo(InputUtils::legacyFilterInput($_POST['City']), $per_City); $sZip = SelectWhichInfo(InputUtils::legacyFilterInput($_POST['Zip']), $per_Zip); $sCountry = SelectWhichInfo(InputUtils::legacyFilterInput($_POST['Country']), $per_Country); + $sDefaultCountry = SystemConfig::getValue('sDefaultCountry'); - if ($sCountry == 'United States' || $sCountry == 'Canada') { + if ($sCountry == $sDefaultCountry && empty($_POST['State']) === false) { $sState = InputUtils::legacyFilterInput($_POST['State']); } else { $sState = InputUtils::legacyFilterInput($_POST['StateTextbox']); } $sState = SelectWhichInfo($sState, $per_State); - // Get and format any phone data from the form. + // Get and format any phone data from the form $sHomePhone = InputUtils::legacyFilterInput($_POST['HomePhone']); $sWorkPhone = InputUtils::legacyFilterInput($_POST['WorkPhone']); $sCellPhone = InputUtils::legacyFilterInput($_POST['CellPhone']); + if (!isset($_POST['NoFormat_HomePhone'])) { $sHomePhone = CollapsePhoneNumber($sHomePhone, $sCountry); } @@ -97,8 +89,8 @@ 'fam_DateEntered' => date('YmdHis'), 'fam_EnteredBy' => AuthenticationManager::getCurrentUser()->getId(), ]; - $familyValues = array_filter($familyValues, fn($var) => !empty($var)); - $familyValues = array_map(fn($var) => '"' . mysqli_real_escape_string($cnInfoCentral, $var) . '"', $familyValues); + $familyValues = array_filter($familyValues, fn ($var) => !empty($var)); + $familyValues = array_map(fn ($var) => '"' . mysqli_real_escape_string($cnInfoCentral, $var) . '"', $familyValues); $sSQL = 'INSERT INTO family_fam (' . implode(',', array_keys($familyValues)) . ') VALUES (' . implode(',', array_values($familyValues)) . ')'; RunQuery($sSQL); @@ -152,7 +144,7 @@ echo $sError; ?>
-
+ 0) { @@ -216,13 +208,13 @@ } echo ''; ?> -
-
-
- - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
: + +
+
+ + + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
: '; @@ -231,28 +223,30 @@ echo sprintf('', $aRow['fam_ID'], $aRow['fam_Name']); } echo ''; ?> -

:
:' . $sWeddingDateError ?>
: +
+

+
:
:' . $sWeddingDateError ?>
: '; echo ''; @@ -265,102 +259,100 @@ } echo ''; ?> -
1:
2:
:
: +
1:
2:
:
: - OR - -
-
: - -
: - -
 
: - - > -
: - - > -
: - - > -
:
-
-

-
- -

-

- - + +
: + +
: + +
 
: + + > +
: + + > +
: + + > +
:
+
+

+
+ +

+

+ +" . gettext('Your cart is empty!') . '

'; + echo "

" . gettext('Your cart is empty!') . '

'; } - ?> +?>
- +countryCode = $countryCode; - $stateFileName = SystemURLs::getDocumentRoot() . '/locale/states/' . $countryCode . '.json'; + if (is_file($stateFileName)) { $statesFile = file_get_contents($stateFileName); MiscUtils::throwIfFailed($statesFile); diff --git a/src/ChurchCRM/dto/CountryDropDown.php b/src/ChurchCRM/dto/CountryDropDown.php new file mode 100644 index 0000000000..622c1491ec --- /dev/null +++ b/src/ChurchCRM/dto/CountryDropDown.php @@ -0,0 +1,30 @@ +'; + $optionTags = [ + '', + '', + ]; + + foreach (Countries::getNames() as $country) { + if ($country == $selected) { + $selected = 'selected'; + } + $optionTags[] = ''; + $selected = ''; + } + + $result .= implode('', $optionTags); + $result .= ''; + + return $result; + } +} diff --git a/src/ChurchCRM/dto/StateDropDown.php b/src/ChurchCRM/dto/StateDropDown.php new file mode 100644 index 0000000000..1618ae1933 --- /dev/null +++ b/src/ChurchCRM/dto/StateDropDown.php @@ -0,0 +1,42 @@ +warning("Lookup of <" . $Country . "> returns value not of Country class?"); + } + + // Must cast to lowercase because ultimately this looks up files with lowercase names + parent::__construct(strtolower($Country->getCountryCode())); + } + + public static function getDropDown($selectedState = ''): string + { + $result = ''; + + return $result; + } +} diff --git a/src/Include/StateDropDown.php b/src/Include/StateDropDown.php deleted file mode 100644 index 9ff80ce4d0..0000000000 --- a/src/Include/StateDropDown.php +++ /dev/null @@ -1,35 +0,0 @@ -' . gettext('Unassigned') . '', - '', -]; -$Country = Countries::getCountryByName($sCountry); -if (!$Country instanceof Country) { - LoggerUtils::getAppLogger()->warning("Lookup of <" . $sCountry . "> returns value not of Country class?"); -} else { - $lowerCountryCode = strtolower($Country->getCountryCode()); - // Must cast to lowercase because ultimately this looks up files with lc names - $TheStates = new States($lowerCountryCode); - foreach ($TheStates->getNames() as $state) { - $selected = ''; - if ($sState === $state) { - $selected = 'selected'; - } - $optionTags[] = ''; - } -} -$optionsHtmlString = implode('', $optionTags); - -echo << -$optionsHtmlString - -HTML; diff --git a/src/PersonEditor.php b/src/PersonEditor.php index 3ed4bfe435..2878930c7f 100644 --- a/src/PersonEditor.php +++ b/src/PersonEditor.php @@ -1,19 +1,11 @@ - + + ?>
-
@@ -639,57 +626,47 @@ + echo 'selected'; + } ?>> + echo 'selected'; + } ?>>
- +

- +
+ ?>
- +
+ ?>
- +
+ ?>
- +

@@ -698,44 +675,44 @@ class="form-control">

@@ -748,29 +725,27 @@ class="form-control"> $sDay = '0' . $x; } ?> - > +
- +
+ ?>
+ } ?> + ?>

/>
@@ -844,9 +819,7 @@ class="form-control"> echo ''; } ?> - +
- +
- +

-
- - + +
@@ -919,18 +887,15 @@ class="form-control"> echo ''; } ?> - - maxlength="10" size="8"> + echo 'value="' . htmlentities(stripslashes($sZip), ENT_NOQUOTES, 'UTF-8') . '" '; ?> maxlength="10" size="8">
-

- - - - - - - - - + + + + + + + +

@@ -978,14 +939,10 @@ class="form-control">
- "' data-mask> -
> + "' data-mask> +
>
@@ -1002,15 +959,10 @@ class="form-control">
- "' - data-mask /> -
> + "' data-mask /> +
>
@@ -1028,14 +980,10 @@ class="form-control">
- "' data-mask> -
> + "' data-mask> +
> @@ -1055,12 +1003,10 @@ class="form-control">
- + + ?>
@@ -1069,12 +1015,10 @@ class="form-control">
- + + ?>
@@ -1093,12 +1037,10 @@ class="form-control">
- + + ?>
@@ -1107,12 +1049,10 @@ class="form-control">
- + + ?>
@@ -1121,12 +1061,10 @@ class="form-control">
- + + ?>
@@ -1164,13 +1102,10 @@ class="form-control"> - "> + "> + ?> @@ -1180,22 +1115,19 @@ class="form-control">
- "> + "> + ?> - 0) { - ?> + ?>

@@ -1233,16 +1165,14 @@ class="form-control"> } ?>
-
- + isAddRecordsEnabled()) { echo ''; } ?> - +


@@ -1253,5 +1183,5 @@ class="form-control"> $("#familyId").select2(); }); - - +getCity(), $family->getState(), $family->getZip()); - if ($family->getCountry() != '' && $family->getCountry() != 'USA' && $family->getCountry() != 'United States') { + if ($family->getCountry() != '' && $family->getCountry() != $sDefaultCountry) { $labelText .= "\n" . $family->getCountry(); } diff --git a/src/Reports/NewsLetterLabels.php b/src/Reports/NewsLetterLabels.php index 6840f6abbc..4f0863e5e5 100644 --- a/src/Reports/NewsLetterLabels.php +++ b/src/Reports/NewsLetterLabels.php @@ -44,7 +44,7 @@ } $labelText .= sprintf("\n%s, %s %s", $family->getCity(), $family->getState(), $family->getZip()); - if ($family->getCountry() != '' && $family->getCountry() != 'US' && $family->getCountry() != 'USA' && $family->getCountry() != 'United States') { + if ($family->getCountry() != '' && $family->getCountry() != $sDefaultCountry) { $labelText .= "\n" . $family->getCountry(); } diff --git a/src/Reports/TaxReport.php b/src/Reports/TaxReport.php index 115bba09b1..a14c551d4b 100644 --- a/src/Reports/TaxReport.php +++ b/src/Reports/TaxReport.php @@ -65,8 +65,8 @@ } $sSQL = 'SELECT fam_ID, fam_Name, fam_Address1, fam_Address2, fam_City, fam_State, fam_Zip, fam_Country, fam_envelope, plg_date, plg_amount, plg_method, plg_comment, plg_CheckNo, fun_Name, plg_PledgeOrPayment, plg_NonDeductible FROM family_fam - INNER JOIN pledge_plg ON fam_ID=plg_FamID - LEFT JOIN donationfund_fun ON plg_fundID=fun_ID'; + INNER JOIN pledge_plg ON fam_ID=plg_FamID + LEFT JOIN donationfund_fun ON plg_fundID=fun_ID'; $sSQL .= " WHERE plg_PledgeOrPayment='Payment' "; @@ -241,7 +241,8 @@ public function finishPage($curY, $fam_ID, $fam_Name, $fam_Address1, $fam_Addres } $this->writeAt(SystemConfig::getValue('leftX'), $curY, $fam_City . ', ' . $fam_State . ' ' . $fam_Zip); $curY += SystemConfig::getValue('incrementY'); - if ($fam_Country != '' && $fam_Country != 'USA' && $fam_Country != 'United States') { + $sDefaultCountry = SystemConfig::getValue('sDefaultCountry'); + if ($fam_Country != '' && $fam_Country != $sDefaultCountry) { $this->writeAt(SystemConfig::getValue('leftX'), $curY, $fam_Country); $curY += SystemConfig::getValue('incrementY'); } @@ -255,7 +256,7 @@ public function finishPage($curY, $fam_ID, $fam_Name, $fam_Address1, $fam_Addres } $this->writeAt(SystemConfig::getValue('leftX') + 5, $curY, SystemConfig::getValue('sChurchCity') . ', ' . SystemConfig::getValue('sChurchState') . ' ' . SystemConfig::getValue('sChurchZip')); $curY += SystemConfig::getValue('incrementY'); - if ($fam_Country != '' && $fam_Country != 'USA' && $fam_Country != 'United States') { + if ($fam_Country != '' && $fam_Country != $sDefaultCountry) { $this->writeAt(SystemConfig::getValue('leftX') + 5, $curY, $fam_Country); $curY += SystemConfig::getValue('incrementY'); } @@ -282,7 +283,7 @@ public function finishPage($curY, $fam_ID, $fam_Name, $fam_Address1, $fam_Addres // Check for minimum amount if ($iMinimum > 0) { $temp = "SELECT SUM(plg_amount) AS total_gifts FROM pledge_plg - WHERE plg_FamID=$fam_ID AND $aSQLCriteria[1]"; + WHERE plg_FamID=$fam_ID AND $aSQLCriteria[1]"; $rsMinimum = RunQuery($temp); [$total_gifts] = mysqli_fetch_row($rsMinimum); if ($iMinimum > $total_gifts) {