Add more fields to person editor, fix some fields not saving/displaying

master
Skylar Ittner 5 years ago
parent c28ea2a492
commit 653fcd7f22

@ -54,7 +54,11 @@ switch ($VARS['action']) {
"shirt" => "", "shirt" => "",
"sex" => "", "sex" => "",
"parentname" => "", "parentname" => "",
"rank" => "" "rank" => "",
"den" => "",
"health" => "",
"notes" => "",
"position" => ""
]; ];
if (!empty($VARS['personid']) && $database->has("people", ['personid' => $VARS['personid']])) { if (!empty($VARS['personid']) && $database->has("people", ['personid' => $VARS['personid']])) {
$person = $database->get('people', ['personid (id)', $person = $database->get('people', ['personid (id)',
@ -71,7 +75,8 @@ switch ($VARS['action']) {
'email', 'email',
'unit', 'unit',
'shirt', 'shirt',
'sex'], ['personid' => $VARS['personid']]); 'sex',
'notes'], ['personid' => $VARS['personid']]);
$editing = true; $editing = true;
} }
@ -186,7 +191,9 @@ switch ($VARS['action']) {
case "camper": case "camper":
$data = [ $data = [
"parentname" => $people["parentname"], "parentname" => $people["parentname"],
"rank" => $people["rank"] "rank" => $people["rank"],
"den" => (empty($people["den"]) ? "" : $people["den"]),
"health" => (empty($people["health"]) ? "" : $people["health"])
]; ];
if ($editing) { if ($editing) {
$database->update("campers", $data, ['camperid' => $person['camperid']]); $database->update("campers", $data, ['camperid' => $person['camperid']]);
@ -239,7 +246,8 @@ switch ($VARS['action']) {
"email" => empty($people["email"]) ? "" : $people["email"], "email" => empty($people["email"]) ? "" : $people["email"],
"unit" => $people["unit"], "unit" => $people["unit"],
"shirt" => $people["shirt"], "shirt" => $people["shirt"],
"sex" => $people["sex"] "sex" => $people["sex"],
"notes" => (empty($people["notes"]) ? "" : $people["notes"])
]; ];
if ($editing) { if ($editing) {
@ -253,7 +261,7 @@ switch ($VARS['action']) {
} }
}); });
returnToSender("person_saved"); returnToSender("person_saved", "&id=" . htmlentities($VARS['personid']));
break; break;
case "deleteperson": case "deleteperson":
if (!empty($VARS['id']) && $database->count("people", ['personid' => $VARS['id']]) === 1) { if (!empty($VARS['id']) && $database->count("people", ['personid' => $VARS['id']]) === 1) {

Binary file not shown.

@ -6,5 +6,7 @@
"Are you sure you want to delete this person?": "Are you sure you want to delete this person?", "Are you sure you want to delete this person?": "Are you sure you want to delete this person?",
"This action cannot be undone!": "This action cannot be undone!", "This action cannot be undone!": "This action cannot be undone!",
"Payment saved.": "Payment saved.", "Payment saved.": "Payment saved.",
"Only showing {x}s.": "Only showing {x}s." "Only showing {x}s.": "Only showing {x}s.",
"Person saved.": "Person saved.",
"Person deleted.": "Person deleted."
} }

@ -26,7 +26,10 @@ $data = [
"sex" => "", "sex" => "",
"parentname" => "", "parentname" => "",
"rank" => "", "rank" => "",
"days" => "" "days" => "",
"den" => "",
"health" => "",
"notes" => ""
]; ];
$type = "camper"; $type = "camper";
if (!empty($VARS['type']) && preg_match("/(camper|adult|youth)/", $VARS['type'])) { if (!empty($VARS['type']) && preg_match("/(camper|adult|youth)/", $VARS['type'])) {
@ -48,10 +51,11 @@ if (!empty($VARS['id']) && $database->has('people', ['personid' => $VARS['id']])
'email', 'email',
'unit', 'unit',
'shirt', 'shirt',
'sex'], ['personid' => $personid]); 'sex',
'notes'], ['personid' => $personid]);
if (!empty($data["camperid"])) { if (!empty($data["camperid"])) {
$type = "camper"; $type = "camper";
$data = array_merge($data, $database->get('campers', ['parentname', 'rank'], ['camperid' => $data["camperid"]])); $data = array_merge($data, $database->get('campers', ['parentname', 'rank', 'den', 'health'], ['camperid' => $data["camperid"]]));
} else if (!empty($data["adultid"])) { } else if (!empty($data["adultid"])) {
$type = "adult"; $type = "adult";
$data = array_merge($data, $database->get('adults', ['days', 'position'], ['adultid' => $data["adultid"]])); $data = array_merge($data, $database->get('adults', ['days', 'position'], ['adultid' => $data["adultid"]]));
@ -288,6 +292,7 @@ if (!empty($VARS['id']) && $database->has('people', ['personid' => $VARS['id']])
"type" => "select", "type" => "select",
"width" => 5, "width" => 5,
"options" => $positions, "options" => $positions,
"value" => $data["position"],
"error" => "Choose a position." "error" => "Choose a position."
] ]
]); ]);
@ -326,6 +331,39 @@ if (!empty($VARS['id']) && $database->has('people', ['personid' => $VARS['id']])
"error" => "Choose a gender." "error" => "Choose a gender."
], ],
]); ]);
if ($type == "camper") {
$textboxes = array_merge($textboxes, [
[
"label" => "Den",
"name" => "den",
"width" => 5,
"maxlength" => 255,
"value" => $data["den"],
"optional" => true,
"error" => "Enter a den"
],
[
"label" => "Health",
"name" => "health",
"type" => "textarea",
"width" => 6,
"value" => $data["health"],
"optional" => true,
"error" => "Error"
]
]);
}
$textboxes = array_merge($textboxes, [
[
"label" => "Notes",
"name" => "notes",
"type" => "textarea",
"width" => 6,
"value" => $data["notes"],
"optional" => true,
"error" => "Error"
]
]);
foreach ($textboxes as $item) { foreach ($textboxes as $item) {
?> ?>
@ -334,81 +372,112 @@ if (!empty($VARS['id']) && $database->has('people', ['personid' => $VARS['id']])
<div class="form-group mb-3"> <div class="form-group mb-3">
<label class="mb-0"><?php echo $item['label']; ?>:</label> <label class="mb-0"><?php echo $item['label']; ?>:</label>
<div class="input-group"> <div class="input-group">
<?php if (empty($item['type']) || ($item['type'] != "select" && $item['type'] != "checkboxes")) { ?> <?php
<input type="<?php echo (empty($item['type']) ? "text" : $item['type']); ?>" if (empty($item['type'])) {
name="<?php echo $item['name']; ?>" $item['type'] = "text";
data-name="<?php echo $item['name']; ?>" }
class="form-control" switch ($item['type']) {
placeholder="" case "select":
aria-label="<?php echo $item['label']; ?>" ?>
maxlength="<?php echo $item['maxlength']; ?>" <select class="form-control"
<?php name="<?php echo $item['name']; ?>"
if (!empty($item['pattern'])) { data-name="<?php echo $item['name']; ?>"
?> aria-label="<?php echo $item['label']; ?>"
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 <?php
foreach ($item['options'] as $value => $label) { if (empty($item['optional'])) {
$selected = ""; echo "required";
if (!empty($item['value']) && $value == $item['value']) {
$selected = " selected";
}
echo "<option value=\"$value\"$selected>$label</option>\n";
} }
?> ?>>
</select> <?php
<?php foreach ($item['options'] as $value => $label) {
} else if ($item['type'] == "checkboxes") { $selected = "";
?> if (!empty($item['value']) && $value == $item['value']) {
<div class="d-flex justify-content-left flex-wrap"> $selected = " selected";
}
echo "<option value=\"$value\"$selected>$label</option>\n";
}
?>
</select>
<?php <?php
foreach ($item['options'] as $value => $label) { break;
?> case "checkboxes":
<div class="form-check m-1"> ?>
<input class="form-check-input" <div class="d-flex justify-content-left flex-wrap">
type="checkbox"
data-name="<?php echo $item['name']; ?>"
name="<?php echo $item['name']; ?>[]"
value="<?php echo $value; ?>"
<?php
if (in_array($value, $item['selected'])) {
echo "checked";
}
?>
>
<label class="form-check-label">
<?php echo $label; ?>
</label>
</div>
<?php <?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; ?>"
<?php
if (in_array($value, $item['selected'])) {
echo "checked";
}
?>>
<label class="form-check-label">
<?php echo $label; ?>
</label>
</div>
<?php
}
?>
</div>
<?php
break;
case "textarea":
?> ?>
</div> <textarea class="form-control"
<?php name="<?php echo $item['name']; ?>"
} data-name="<?php echo $item['name']; ?>"
?> aria-label="<?php echo $item['label']; ?>"
rows="4"
placeholder=""
<?php
if (empty($item['optional'])) {
echo "required";
}
?>><?php echo $item['value']; ?></textarea>
<?php
break;
default:
?>
<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['min'])) {
?>
min="<?php echo $item['min']; ?>"
<?php
}
?>
<?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
}
?>
<div class="invalid-feedback"> <div class="invalid-feedback">
<?php echo $item['error']; ?> <?php echo $item['error']; ?>
</div> </div>
@ -432,7 +501,7 @@ if (!empty($VARS['id']) && $database->has('people', ['personid' => $VARS['id']])
} }
?> ?>
<input type="hidden" name="type" value="<?php echo $type; ?>" /> <input type="hidden" name="type" value="<?php echo $type; ?>" />
<input type="hidden" name="source" value="people" /> <input type="hidden" name="source" value="editperson" />
<input type="hidden" name="action" value="editperson" /> <input type="hidden" name="action" value="editperson" />
<div class="card-footer d-flex"> <div class="card-footer d-flex">

Loading…
Cancel
Save