Skip to content

Commit

Permalink
Use default country as standard
Browse files Browse the repository at this point in the history
  • Loading branch information
respencer committed Jun 14, 2024
1 parent 67f76f3 commit be440a5
Show file tree
Hide file tree
Showing 9 changed files with 348 additions and 389 deletions.
278 changes: 135 additions & 143 deletions src/CartToFamily.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
<?php

/*******************************************************************************
*
* filename : CartToFamily.php
* last change : 2003-10-09
* description : Add cart records to a family
*
* https://churchcrm.io/
* Copyright 2003 Chris Gebhardt
*
******************************************************************************/

// Include the function library
require 'Include/Config.php';
require 'Include/Functions.php';

use ChurchCRM\Authentication\AuthenticationManager;
use ChurchCRM\dto\SystemConfig;
use ChurchCRM\dto\SystemURLs;
use ChurchCRM\model\ChurchCRM\PersonQuery;
use ChurchCRM\Utils\InputUtils;
use ChurchCRM\Utils\RedirectUtils;

// Security: User must have add records permission
AuthenticationManager::redirectHomeIfFalse(AuthenticationManager::getCurrentUser()->isAddRecordsEnabled());
if (AuthenticationManager::getCurrentUser()->isAddRecordsEnabled() === false) {
RedirectUtils::securityRedirect('AddRecords');
};

// Was the form submitted?
if (isset($_POST['Submit']) && count($_SESSION['aPeopleCart']) > 0) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -152,7 +144,7 @@
echo $sError;
?>
<div class="card">
<form method="post">
<form method="post">

<?php
if (count($_SESSION['aPeopleCart']) > 0) {
Expand Down Expand Up @@ -216,13 +208,13 @@
}

echo '</table>'; ?>
</div>
<div class="card">
<div class="table-responsive">
<table align="center" class="table table-hover">
<tr>
<td class="LabelColumn"><?= gettext('Add to Family') ?>:</td>
<td class="TextColumn">
</div>
<div class="card">
<div class="table-responsive">
<table align="center" class="table table-hover">
<tr>
<td class="LabelColumn"><?= gettext('Add to Family') ?>:</td>
<td class="TextColumn">
<?php
// Create the family select drop-down
echo '<select name="FamilyID">';
Expand All @@ -231,28 +223,30 @@
echo sprintf('<option value="%s">%s</option>', $aRow['fam_ID'], $aRow['fam_Name']);
}
echo '</select>'; ?>
</td>
</tr>

<tr>
<td></td>
<td><p class="MediumLargeText"><?= gettext('If adding a new family, enter data below.') ?></p></td>
</tr>


<tr>
<td class="LabelColumn"><?= gettext('Family Name') ?>:</td>
<td class="TextColumnWithBottomBorder"><input type="text" Name="FamilyName" value="<?= $sName ?>" maxlength="48"><span style="color: red;"><?= $sNameError ?></span></td>
</tr>

<tr>
<td class="LabelColumn"><?= gettext('Wedding Date') ?>:</td>
<td class="TextColumnWithBottomBorder"><input type="text" Name="WeddingDate" value="<?= $dWeddingDate ?>" maxlength="10" id="sel1" size="15" class="form-control pull-right active date-picker"><span style="color: red;"><?php echo '<BR>' . $sWeddingDateError ?></span></td>
</tr>

<tr>
<td class="LabelColumn"><?= gettext('Use address/contact data from') ?>:</td>
<td class="TextColumn">
</td>
</tr>

<tr>
<td></td>
<td>
<p class="MediumLargeText"><?= gettext('If adding a new family, enter data below.') ?></p>
</td>
</tr>


<tr>
<td class="LabelColumn"><?= gettext('Family Name') ?>:</td>
<td class="TextColumnWithBottomBorder"><input type="text" Name="FamilyName" value="<?= $sName ?>" maxlength="48"><span style="color: red;"><?= $sNameError ?></span></td>
</tr>

<tr>
<td class="LabelColumn"><?= gettext('Wedding Date') ?>:</td>
<td class="TextColumnWithBottomBorder"><input type="text" Name="WeddingDate" value="<?= $dWeddingDate ?>" maxlength="10" id="sel1" size="15" class="form-control pull-right active date-picker"><span style="color: red;"><?php echo '<BR>' . $sWeddingDateError ?></span></td>
</tr>

<tr>
<td class="LabelColumn"><?= gettext('Use address/contact data from') ?>:</td>
<td class="TextColumn">
<?php
echo '<select name="PersonAddress">';
echo '<option value="0">' . gettext('Only the new data below') . '</option>';
Expand All @@ -265,102 +259,100 @@
}

echo '</select>'; ?>
</td>
</tr>

<tr>
<td class="LabelColumn"><?= gettext('Address') ?> 1:</td>
<td class="TextColumn"><input type="text" Name="Address1" value="<?= $sAddress1 ?>" size="50" maxlength="250"></td>
</tr>

<tr>
<td class="LabelColumn"><?= gettext('Address') ?> 2:</td>
<td class="TextColumn"><input type="text" Name="Address2" value="<?= $sAddress2 ?>" size="50" maxlength="250"></td>
</tr>

<tr>
<td class="LabelColumn"><?= gettext('City') ?>:</td>
<td class="TextColumn"><input type="text" Name="City" value="<?= $sCity ?>" maxlength="50"></td>
</tr>

<tr>
<td class="LabelColumn"><?= gettext('State') ?>:</td>
<td class="TextColumn">
</td>
</tr>

<tr>
<td class="LabelColumn"><?= gettext('Address') ?> 1:</td>
<td class="TextColumn"><input type="text" Name="Address1" value="<?= $sAddress1 ?>" size="50" maxlength="250"></td>
</tr>

<tr>
<td class="LabelColumn"><?= gettext('Address') ?> 2:</td>
<td class="TextColumn"><input type="text" Name="Address2" value="<?= $sAddress2 ?>" size="50" maxlength="250"></td>
</tr>

<tr>
<td class="LabelColumn"><?= gettext('City') ?>:</td>
<td class="TextColumn"><input type="text" Name="City" value="<?= $sCity ?>" maxlength="50"></td>
</tr>

<tr>
<td class="LabelColumn"><?= gettext('State') ?>:</td>
<td class="TextColumn">
<?php require 'Include/StateDropDown.php'; ?>
OR
<input type="text" name="StateTextbox" value="<?php if ($sCountry != 'United States' && $sCountry != 'Canada') {
echo $sState;
} ?>" size="20" maxlength="30">
<BR><?= gettext('(Use the textbox for countries other than US and Canada)') ?>
</td>
</tr>

<tr>
<td class="LabelColumn"><?= gettext('Zip')?>:</td>
<td class="TextColumn">
<input type="text" Name="Zip" value="<?= $sZip ?>" maxlength="10" size="8">
</td>

</tr>

<tr>
<td class="LabelColumn"><?= gettext('Country') ?>:</td>
<td class="TextColumnWithBottomBorder">
<?php require 'Include/CountryDropDown.php' ?>
</td>
</tr>

<tr>
<td>&nbsp;</td>
</tr>

<tr>
<td class="LabelColumn"><?= gettext('Home Phone') ?>:</td>
<td class="TextColumn">
<input type="text" Name="HomePhone" value="<?= $sHomePhone ?>" size="30" maxlength="30">
<input type="checkbox" name="NoFormat_HomePhone" value="1" <?php if ($bNoFormat_HomePhone) {
echo ' checked';
} ?>><?= gettext('Do not auto-format') ?>
</td>
</tr>

<tr>
<td class="LabelColumn"><?= gettext('Work Phone') ?>:</td>
<td class="TextColumn">
<input type="text" name="WorkPhone" value="<?php echo $sWorkPhone ?>" size="30" maxlength="30">
<input type="checkbox" name="NoFormat_WorkPhone" value="1" <?php if ($bNoFormat_WorkPhone) {
echo ' checked';
} ?>><?= gettext('Do not auto-format') ?>
</td>
</tr>

<tr>
<td class="LabelColumn"><?= gettext('Mobile Phone') ?>:</td>
<td class="TextColumn">
<input type="text" name="CellPhone" value="<?php echo $sCellPhone ?>" size="30" maxlength="30">
<input type="checkbox" name="NoFormat_CellPhone" value="1" <?php if ($bNoFormat_CellPhone) {
echo ' checked';
} ?>><?= gettext('Do not auto-format') ?>
</td>
</tr>

<tr>
<td class="LabelColumn"><?= gettext('Email') ?>:</td>
<td class="TextColumnWithBottomBorder"><input type="text" Name="Email" value="<?= $sEmail ?>" size="30" maxlength="50"></td>
</tr>

</table>
</div>
<p align="center">
<BR>
<input type="submit" class="btn btn-default" name="Submit" value="<?= gettext('Add to Family') ?>">
<BR><BR>
</p>
</form>
<?php
<?= gettext('OR') ?>
<input type="text" name="StateTextbox" value="<?= $sState ?>" size="20" maxlength="30">
</td>
</tr>

<tr>
<td class="LabelColumn"><?= gettext('Zip') ?>:</td>
<td class="TextColumn">
<input type="text" Name="Zip" value="<?= $sZip ?>" maxlength="10" size="8">
</td>

</tr>

<tr>
<td class="LabelColumn"><?= gettext('Country') ?>:</td>
<td class="TextColumnWithBottomBorder">
<?php require 'Include/CountryDropDown.php'; ?>
</td>
</tr>

<tr>
<td>&nbsp;</td>
</tr>

<tr>
<td class="LabelColumn"><?= gettext('Home Phone') ?>:</td>
<td class="TextColumn">
<input type="text" Name="HomePhone" value="<?= $sHomePhone ?>" size="30" maxlength="30">
<input type="checkbox" name="NoFormat_HomePhone" value="1" <?php if ($bNoFormat_HomePhone) {
echo ' checked';
} ?>><?= gettext('Do not auto-format') ?>
</td>
</tr>

<tr>
<td class="LabelColumn"><?= gettext('Work Phone') ?>:</td>
<td class="TextColumn">
<input type="text" name="WorkPhone" value="<?php echo $sWorkPhone ?>" size="30" maxlength="30">
<input type="checkbox" name="NoFormat_WorkPhone" value="1" <?php if ($bNoFormat_WorkPhone) {
echo ' checked';
} ?>><?= gettext('Do not auto-format') ?>
</td>
</tr>

<tr>
<td class="LabelColumn"><?= gettext('Mobile Phone') ?>:</td>
<td class="TextColumn">
<input type="text" name="CellPhone" value="<?php echo $sCellPhone ?>" size="30" maxlength="30">
<input type="checkbox" name="NoFormat_CellPhone" value="1" <?php if ($bNoFormat_CellPhone) {
echo ' checked';
} ?>><?= gettext('Do not auto-format') ?>
</td>
</tr>

<tr>
<td class="LabelColumn"><?= gettext('Email') ?>:</td>
<td class="TextColumnWithBottomBorder"><input type="text" Name="Email" value="<?= $sEmail ?>" size="30" maxlength="50"></td>
</tr>

</table>
</div>
<p align="center">
<BR>
<input type="submit" class="btn btn-default" name="Submit" value="<?= gettext('Add to Family') ?>">
<BR><BR>
</p>
</form>
<?php
} else {
echo "<p align=\"center\" class='callout callout-warning'>" . gettext('Your cart is empty!') . '</p>';
echo "<p align=\"center\" class='callout callout-warning'>" . gettext('Your cart is empty!') . '</p>';
}
?>
?>
</div>
<?php require 'Include/Footer.php'; ?>
<?php
require 'Include/Footer.php';
3 changes: 1 addition & 2 deletions src/ChurchCRM/data/States.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ class States

public function __construct(string $countryCode)
{
$this->countryCode = $countryCode;

$stateFileName = SystemURLs::getDocumentRoot() . '/locale/states/' . $countryCode . '.json';

if (is_file($stateFileName)) {
$statesFile = file_get_contents($stateFileName);
MiscUtils::throwIfFailed($statesFile);
Expand Down
30 changes: 30 additions & 0 deletions src/ChurchCRM/dto/CountryDropDown.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace ChurchCRM\dto;

use ChurchCRM\data\Countries;

class CountryDropDown extends Countries
{
public static function getDropDown($selected = ''): string
{
$result = '<select name="Country" class="form-control select2" id="country-input">';
$optionTags = [
'<option value="">' . gettext('Unassigned') . '</option>',
'<option value="" disabled>--------------------</option>',
];

foreach (Countries::getNames() as $country) {
if ($country == $selected) {
$selected = 'selected';
}
$optionTags[] = '<option value="' . $country . '" ' . $selected . '>' . gettext($country) . '</option>';
$selected = '';
}

$result .= implode('', $optionTags);
$result .= '</select>';

return $result;
}
}
Loading

0 comments on commit be440a5

Please sign in to comment.