You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

396 lines
17 KiB
PHP

<?php
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
redirectIfNotLoggedIn();
$editing = false;
$data = [
"id" => null,
"camperid" => null,
"adultid" => null,
"youthid" => null,
"firstname" => "",
"lastname" => "",
"address" => "",
"zip" => "",
"phone1" => "",
"phone2" => "",
"email" => "",
"unit" => "",
"shirt" => "",
"sex" => "",
"parentname" => "",
"rank" => ""
];
$type = "camper";
if (!empty($VARS['type']) && preg_match("/(camper|adult|youth)/", $VARS['type'])) {
$type = $VARS['type'];
}
if (!empty($VARS['id']) && $database->has('people', ['personid' => $VARS['id']])) {
$personid = $VARS['id'];
$data = $database->get('people', ['personid (id)',
'camperid',
'adultid',
'youthid',
'firstname',
'lastname',
'address',
'zip',
'phone1',
'phone2',
'email',
'unit',
'shirt',
'sex'], ['personid' => $personid]);
if (!empty($data["camperid"])) {
$type = "camper";
$data = array_merge($data, $database->get('campers', ['parentname', 'rank'], ['camperid' => $data["camperid"]]));
} else if (!empty($data["adultid"])) {
$type = "adult";
$data = array_merge($data, $database->get('adults', ['days', 'position'], ['adultid' => $data["adultid"]]));
} else if (!empty($data["youthid"])) {
$type = "youth";
$data = array_merge($data, $database->get('youth', ['days', 'position'], ['youthid' => $data["youthid"]]));
}
$editing = true;
}
?>
<form action="action.php" method="post" id="editform">
<div class="card">
<h3 class="card-header d-flex">
<div>
<?php
if ($editing) {
?>
<i class="fas fa-edit"></i> <?php $Strings->build("Editing $type", ['person' => "<span id=\"name_title\">" . htmlentities($data["firstname"] . " " . $data["lastname"]) . "</span>"]); ?>
<?php
} else {
?>
<i class="fas fa-edit"></i> <?php $Strings->get("Adding $type"); ?>
<?php
}
?>
</div>
<a href="./app.php?page=people" class="ml-auto btn btn-outline-info btn-sm">
<i class="fas fa-times"></i> <?php $Strings->get("Cancel"); ?>
</a>
</h3>
<div class="card-body">
<div class="row">
<?php
$textboxes = [
[
"label" => "First Name",
"name" => "firstname",
"maxlength" => 255,
"width" => 6,
"value" => $data["firstname"],
"error" => "Enter the person's first name."
],
[
"label" => "Last Name",
"name" => "lastname",
"width" => 6,
"maxlength" => 255,
"value" => $data["lastname"],
"error" => "Enter the person's last name."
]
];
if ($type == "camper") {
$textboxes = array_merge($textboxes, [
[
"label" => "Parent/Guardian Name",
"name" => "parentname",
"width" => 12,
"maxlength" => 255,
"value" => $data["parentname"],
"error" => "Enter the parent or guardian's full name."
]
]);
}
$textboxes = array_merge($textboxes, [
[
"label" => "Address",
"name" => "address",
"maxlength" => 500,
"width" => 8,
"value" => $data["address"],
"error" => "Enter the person's home address."
],
[
"label" => "ZIP Code",
"name" => "zip",
"maxlength" => 10,
"width" => 4,
"value" => $data["zip"],
"pattern" => "[0-9]{5}(-?[0-9]{4})?",
"error" => "Enter a valid 5 or 9 digit ZIP code."
],
[
"label" => "Phone Number",
"name" => "phone1",
"type" => "tel",
"maxlength" => 20,
"width" => 3,
"value" => $data["phone1"],
"pattern" => "[0-9]{10}",
"error" => "Enter a 10-digit phone number (numbers only)."
],
[
"label" => "Email",
"name" => "email",
"maxlength" => 255,
"width" => 5,
"type" => "email",
"value" => $data["email"],
"error" => "Enter your email address."
]
]);
if ($type == "camper") {
$textboxes = array_merge($textboxes, [
[
"label" => "Pack #",
"name" => "unit",
"width" => 2,
"maxlength" => 4,
"pattern" => "[0-9]{3,4}",
"value" => $data["unit"],
"error" => "Enter the pack number."
],
[
"label" => "Rank",
"name" => "rank",
"type" => "select",
"width" => 2,
"value" => $data["rank"],
"options" => [
"" => "Choose...",
"Tiger" => "Tiger",
"Wolf" => "Wolf",
"Bear" => "Bear",
"Webelos" => "Webelos",
"Arrow of Light" => "Arrow of Light",
],
"error" => "Choose a rank."
]
]);
}
if ($type == "youth") {
$textboxes = array_merge($textboxes, [
[
"label" => "Parent Name",
"name" => "parentname",
"width" => 4,
"maxlength" => 255,
"value" => $data["parentname"],
"error" => "Enter the parent or guardian's full name."
],
[
"label" => "Parent Phone",
"name" => "phone2",
"type" => "tel",
"maxlength" => 20,
"width" => 3,
"value" => $data["phone2"],
"pattern" => "[0-9]{10}",
"error" => "Enter a 10-digit phone number (numbers only)."
]
]);
}
if ($type == "adult" || $type == "youth") {
if ($type == "adult") {
$positions = [
"None" => "No Preference",
"Den Walker" => "Den Walker",
"Station Leader" => "Station Leader",
"Tot Lot" => "Tot Lot",
"First Aid" => "First Aid",
"Floater" => "Floater"
];
} else {
$positions = [
"None" => "No Preference",
"Den Chief" => "Den Chief",
"Station" => "Station",
"Tot Lot" => "Tot Lot",
"Floater" => "Floater"
];
}
$textboxes = array_merge($textboxes, [
[
"label" => "Available Days",
"name" => "days",
"type" => "checkboxes",
"options" => [
"Tu" => "Tuesday",
"We" => "Wednesday",
"Th" => "Thursday",
"Fr" => "Friday",
],
"error" => "Choose at least one day."
],
[
"label" => "Preferred Position",
"name" => "position",
"type" => "select",
"width" => 5,
"options" => $positions,
"error" => "Choose a position."
]
]);
}
$textboxes = array_merge($textboxes, [
[
"label" => "Shirt Size",
"name" => "shirt",
"type" => "select",
"value" => $data["shirt"],
"options" => [
"" => "Choose...",
"YS" => "Youth Small",
"YM" => "Youth Medium",
"YL" => "Youth Large",
"AS" => "Adult Small",
"AM" => "Adult Medium",
"AL" => "Adult Large",
"AX" => "Adult Extra Large",
"A2" => "Adult 2X Large"
],
"error" => "Choose a shirt size."
],
[
"label" => "Gender",
"name" => "sex",
"type" => "select",
"width" => 3,
"value" => $data["sex"],
"options" => [
"" => "Choose...",
"M" => "Male",
"F" => "Female"
],
"error" => "Choose a gender."
],
]);
foreach ($textboxes as $item) {
?>
<div class="col-12 col-md-<?php echo (empty($item['width']) ? "4" : $item['width']); ?>">
<div class="form-group mb-3">
<label class="mb-0"><?php echo $item['label']; ?>:</label>
<div class="input-group">
<?php if (empty($item['type']) || ($item['type'] != "select" && $item['type'] != "checkboxes")) { ?>
<input type="<?php echo (empty($item['type']) ? "text" : $item['type']); ?>"
name="<?php echo $item['name']; ?>"
data-name="<?php echo $item['name']; ?>"
class="form-control"
placeholder=""
aria-label="<?php echo $item['label']; ?>"
maxlength="<?php echo $item['maxlength']; ?>"
<?php
if (!empty($item['pattern'])) {
?>
pattern="<?php echo $item['pattern']; ?>"
<?php
}
?>
<?php
if (!empty($item['value'])) {
?>
value="<?php echo htmlspecialchars($item['value']); ?>"
<?php
}
if (empty($item['optional'])) {
echo "required";
}
?> />
<?php } else if ($item['type'] == "select") { ?>
<select class="form-control"
name="<?php echo $item['name']; ?>"
data-name="<?php echo $item['name']; ?>"
aria-label="<?php echo $item['label']; ?>"
<?php
if (empty($item['optional'])) {
echo "required";
}
?>>
<?php
foreach ($item['options'] as $value => $label) {
$selected = "";
if (!empty($item['value']) && $value == $item['value']) {
$selected = " selected";
}
echo "<option value=\"$value\"$selected>$label</option>\n";
}
?>
</select>
<?php
} else if ($item['type'] == "checkboxes") {
?>
<div class="d-flex justify-content-left flex-wrap">
<?php
foreach ($item['options'] as $value => $label) {
?>
<div class="form-check m-1">
<input class="form-check-input" type="checkbox" data-name="<?php echo $item['name']; ?>" name="<?php echo $item['name']; ?>[]" value="<?php echo $value; ?>">
<label class="form-check-label">
<?php echo $label; ?>
</label>
</div>
<?php
}
?>
</div>
<?php
}
?>
<div class="invalid-feedback">
<?php echo $item['error']; ?>
</div>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>
<?php
if ($editing) {
?>
<input type="hidden" name="personid" value="<?php echo $data['id']; ?>" />
<?php
}
?>
<input type="hidden" name="type" value="<?php echo $type; ?>" />
<input type="hidden" name="source" value="editperson" />
<input type="hidden" name="action" value="editperson" />
<div class="card-footer d-flex">
<button type="submit" class="btn btn-success mr-1" id="savebutton">
<i class="fas fa-save"></i> <?php $Strings->get("Save"); ?>
</button>
<?php if ($editing) { ?>
<a href="./app.php?page=confirmdelete&id=<?php echo $data['id']; ?>" class="btn btn-danger ml-auto">
<i class="fas fa-times"></i> <?php $Strings->get("Delete"); ?>
</a>
<?php } ?>
</div>
</div>
</form>