Add family ID search tool, fixes
This commit is contained in:
parent
17009bd496
commit
628366379b
46
action.php
46
action.php
@ -83,8 +83,9 @@ switch ($VARS['action']) {
|
||||
global $person, $VARS, $editing;
|
||||
|
||||
try {
|
||||
|
||||
if ($editing) {
|
||||
if (!empty($VARS['familyid']) && $database->has('families', ['familyid' => $VARS['familyid']])) {
|
||||
$familyid = $VARS['familyid'];
|
||||
} else if ($editing) {
|
||||
$familyid = $person['familyid'];
|
||||
} else {
|
||||
$database->insert("families", []);
|
||||
@ -132,7 +133,8 @@ switch ($VARS['action']) {
|
||||
"Station",
|
||||
"Tot Lot",
|
||||
"Floater"
|
||||
]
|
||||
],
|
||||
"parentname" => ".+"
|
||||
]);
|
||||
break;
|
||||
default:
|
||||
@ -208,7 +210,8 @@ switch ($VARS['action']) {
|
||||
case "youth":
|
||||
$data = [
|
||||
"position" => $people["position"],
|
||||
"days" => $days
|
||||
"days" => $days,
|
||||
"parentname" => $people["parentname"]
|
||||
];
|
||||
if ($editing) {
|
||||
$database->update("youth", $data, ['youthid' => $person['youthid']]);
|
||||
@ -219,7 +222,6 @@ switch ($VARS['action']) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$data = [
|
||||
"familyid" => $familyid,
|
||||
"camperid" => $camperid,
|
||||
@ -242,6 +244,7 @@ switch ($VARS['action']) {
|
||||
} else {
|
||||
$database->insert("people", $data);
|
||||
}
|
||||
|
||||
} catch (Exception $ex) {
|
||||
errorBack($ex->getMessage());
|
||||
}
|
||||
@ -266,15 +269,15 @@ switch ($VARS['action']) {
|
||||
}
|
||||
break;
|
||||
case "editpayment":
|
||||
if (!(new User($_SESSION['uid']))->hasPermission("HACHEPORTAL_EDIT")) {
|
||||
returnToSender("no_permission");
|
||||
}
|
||||
if (!$database->has("families", ['familyid' => $VARS['familyid']])) {
|
||||
returnToSender("invalid_parameters");
|
||||
}
|
||||
if (!is_numeric($VARS["amount"]) || $VARS["amount"] < 0) {
|
||||
returnToSender("invalid_parameters");
|
||||
}
|
||||
if (!is_numeric($VARS["amountpaid"]) || $VARS["amountpaid"] < 0) {
|
||||
returnToSender("invalid_parameters");
|
||||
}
|
||||
if (empty($VARS['date']) || strtotime($VARS['date']) === false) {
|
||||
returnToSender("invalid_parameters");
|
||||
}
|
||||
@ -282,7 +285,7 @@ switch ($VARS['action']) {
|
||||
$database->update("payments", [
|
||||
"familyid" => $VARS["familyid"],
|
||||
"amount" => $VARS["amount"],
|
||||
"paid" => !empty($VARS["paid"]) && $VARS["paid"] == "1" ? true : false,
|
||||
"amountpaid" => $VARS["amountpaid"],
|
||||
"date" => date("Y-m-d H:i:s", strtotime($VARS['date'])),
|
||||
"type" => $VARS["type"]
|
||||
], [
|
||||
@ -293,19 +296,28 @@ switch ($VARS['action']) {
|
||||
$database->insert("payments", [
|
||||
"familyid" => $VARS["familyid"],
|
||||
"amount" => $VARS["amount"],
|
||||
"paid" => !empty($VARS["paid"]) && $VARS["paid"] == "1" ? true : false,
|
||||
"amountpaid" => $VARS["amountpaid"],
|
||||
"date" => date("Y-m-d H:i:s", strtotime($VARS['date'])),
|
||||
"type" => $VARS["type"]
|
||||
]);
|
||||
$paymentid = $database->id();
|
||||
$family = (new Family())->load($VARS['familyid']);
|
||||
if ($family->getExpires() < time()) {
|
||||
$family->setExpires(strtotime("+1 year"));
|
||||
} else {
|
||||
$family->setExpires(strtotime("+1 year", $family->getExpires()));
|
||||
}
|
||||
$family->save();
|
||||
}
|
||||
returnToSender("payment_saved", "&id=$paymentid");
|
||||
break;
|
||||
case "familysearch":
|
||||
$people = $database->select('people', ['familyid (id)', 'firstname', 'lastname'], ['OR' => ['familyid' => $VARS['q'], 'lastname[~]' => $VARS['q'], 'firstname[~]' => $VARS['q']]]);
|
||||
$data = [];
|
||||
foreach ($people as $p) {
|
||||
$data[$p['id']]['names'][] = $p['firstname'] . " " . $p['lastname'];
|
||||
$data[$p['id']]['id'] = $p['id'];
|
||||
}
|
||||
$out = [];
|
||||
foreach ($data as $i) {
|
||||
$out[] = [
|
||||
'id' => $i['id'],
|
||||
'name' => implode(", ", $i['names'])
|
||||
];
|
||||
}
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($out);
|
||||
}
|
BIN
database.mwb
BIN
database.mwb
Binary file not shown.
@ -21,20 +21,16 @@ define("MESSAGES", [
|
||||
"string" => "You do not have permission to do that.",
|
||||
"type" => "danger"
|
||||
],
|
||||
"family_doesnt_exist" => [
|
||||
"string" => "That family ID does not exist.",
|
||||
"person_doesnt_exist" => [
|
||||
"string" => "That person does not exist.",
|
||||
"type" => "warning"
|
||||
],
|
||||
"family_saved" => [
|
||||
"string" => "Family saved.",
|
||||
"person_saved" => [
|
||||
"string" => "Person saved.",
|
||||
"type" => "success"
|
||||
],
|
||||
"family_deleted" => [
|
||||
"string" => "Family deleted.",
|
||||
"type" => "success"
|
||||
],
|
||||
"events_updated" => [
|
||||
"string" => "Events updated.",
|
||||
"person_deleted" => [
|
||||
"string" => "Person deleted.",
|
||||
"type" => "success"
|
||||
],
|
||||
"payment_saved" => [
|
||||
|
@ -27,7 +27,8 @@ define("PAGES", [
|
||||
"editperson" => [
|
||||
"title" => "Edit Person",
|
||||
"scripts" => [
|
||||
"static/js/editperson.js"
|
||||
"static/js/editperson.js",
|
||||
"static/js/familysearch.js"
|
||||
],
|
||||
],
|
||||
"confirmdelete" => [
|
||||
@ -49,7 +50,8 @@ define("PAGES", [
|
||||
"editpayment" => [
|
||||
"title" => "Edit Payment",
|
||||
"scripts" => [
|
||||
"static/js/editpayment.js"
|
||||
"static/js/editpayment.js",
|
||||
"static/js/familysearch.js"
|
||||
]
|
||||
],
|
||||
"reports" => [
|
||||
|
@ -16,10 +16,10 @@ $editing = false;
|
||||
$data = [
|
||||
"id" => "",
|
||||
"family" => "",
|
||||
"amount" => 1.0,
|
||||
"amount" => 0.0,
|
||||
"amountpaid" => 0.0,
|
||||
"date" => date("Y-m-d"),
|
||||
"type" => "",
|
||||
"paid" => true
|
||||
"type" => ""
|
||||
];
|
||||
|
||||
if (!empty($_GET['id']) && $database->has('payments', ['paymentid' => $_GET['id']])) {
|
||||
@ -30,6 +30,24 @@ if (!empty($_GET['id']) && $database->has('payments', ['paymentid' => $_GET['id'
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="modal fade" id="familysearchmodal">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Find Family</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input type="text" id="familysearchbox" class="form-control" placeholder="Type to Search" />
|
||||
<div class="list-group" id="familysearchresults">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form action="action.php" method="post" id="editform">
|
||||
|
||||
<div class="card">
|
||||
@ -52,6 +70,29 @@ if (!empty($_GET['id']) && $database->has('payments', ['paymentid' => $_GET['id'
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
|
||||
<div class="col-12 col-md-2">
|
||||
<div class="form-group mb-3">
|
||||
<label class="mb-0">Family ID:</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="btn btn-default" id="familysearchbtn"><i class="fas fa-search"></i></span>
|
||||
</div>
|
||||
<input type="number"
|
||||
name="familyid"
|
||||
value="<?php echo $data['family']; ?>"
|
||||
class="form-control"
|
||||
placeholder=""
|
||||
aria-label="Family ID"
|
||||
maxlength="5"
|
||||
required />
|
||||
<div class="invalid-feedback">
|
||||
Enter a family ID.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<?php
|
||||
$textboxes = [
|
||||
[
|
||||
@ -94,7 +135,9 @@ if (!empty($_GET['id']) && $database->has('payments', ['paymentid' => $_GET['id'
|
||||
"Online" => "Online",
|
||||
"Cash" => "Cash",
|
||||
"Check" => "Check",
|
||||
"Camp Coupon/Scout Bucks" => "Camp Coupon/Scout Bucks",
|
||||
"Free" => "Free",
|
||||
"Multiple" => "Multiple",
|
||||
"Other" => "Other"
|
||||
],
|
||||
"width" => 3,
|
||||
|
@ -10,6 +10,7 @@ redirectIfNotLoggedIn();
|
||||
$editing = false;
|
||||
$data = [
|
||||
"id" => null,
|
||||
"familyid" => "",
|
||||
"camperid" => null,
|
||||
"adultid" => null,
|
||||
"youthid" => null,
|
||||
@ -34,6 +35,7 @@ if (!empty($VARS['type']) && preg_match("/(camper|adult|youth)/", $VARS['type'])
|
||||
if (!empty($VARS['id']) && $database->has('people', ['personid' => $VARS['id']])) {
|
||||
$personid = $VARS['id'];
|
||||
$data = $database->get('people', ['personid (id)',
|
||||
'familyid',
|
||||
'camperid',
|
||||
'adultid',
|
||||
'youthid',
|
||||
@ -55,12 +57,30 @@ if (!empty($VARS['id']) && $database->has('people', ['personid' => $VARS['id']])
|
||||
$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"]]));
|
||||
$data = array_merge($data, $database->get('youth', ['days', 'position', 'parentname'], ['youthid' => $data["youthid"]]));
|
||||
}
|
||||
$editing = true;
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="modal fade" id="familysearchmodal">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Find Family</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input type="text" id="familysearchbox" class="form-control" placeholder="Type to Search" />
|
||||
<div class="list-group" id="familysearchresults">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form action="action.php" method="post" id="editform">
|
||||
|
||||
<div class="card">
|
||||
@ -88,20 +108,41 @@ if (!empty($VARS['id']) && $database->has('people', ['personid' => $VARS['id']])
|
||||
|
||||
<div class="row">
|
||||
|
||||
<div class="col-12 col-md-2">
|
||||
<div class="form-group mb-3">
|
||||
<label class="mb-0">Family ID:</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="btn btn-default" id="familysearchbtn"><i class="fas fa-search"></i></span>
|
||||
</div>
|
||||
<input type="number"
|
||||
name="familyid"
|
||||
value="<?php echo $data['familyid']; ?>"
|
||||
class="form-control"
|
||||
placeholder=""
|
||||
aria-label="Family ID"
|
||||
maxlength="5" />
|
||||
<div class="invalid-feedback">
|
||||
Enter a family ID.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$textboxes = [
|
||||
[
|
||||
"label" => "First Name",
|
||||
"name" => "firstname",
|
||||
"maxlength" => 255,
|
||||
"width" => 6,
|
||||
"width" => 5,
|
||||
"value" => $data["firstname"],
|
||||
"error" => "Enter the person's first name."
|
||||
],
|
||||
[
|
||||
"label" => "Last Name",
|
||||
"name" => "lastname",
|
||||
"width" => 6,
|
||||
"width" => 5,
|
||||
"maxlength" => 255,
|
||||
"value" => $data["lastname"],
|
||||
"error" => "Enter the person's last name."
|
||||
|
@ -1,34 +0,0 @@
|
||||
/* 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/. */
|
||||
|
||||
$('#famtable').DataTable({
|
||||
responsive: {
|
||||
details: {
|
||||
display: $.fn.dataTable.Responsive.display.modal({
|
||||
header: function (row) {
|
||||
var data = row.data();
|
||||
return "<i class=\"fas fa-users fa-fw\"></i> " + data[2];
|
||||
}
|
||||
}),
|
||||
renderer: $.fn.dataTable.Responsive.renderer.tableAll({
|
||||
tableClass: 'table'
|
||||
}),
|
||||
type: "column"
|
||||
}
|
||||
},
|
||||
columnDefs: [
|
||||
{
|
||||
targets: 0,
|
||||
className: 'control',
|
||||
orderable: false
|
||||
},
|
||||
{
|
||||
targets: 1,
|
||||
orderable: false
|
||||
}
|
||||
],
|
||||
order: [
|
||||
[2, 'asc']
|
||||
]
|
||||
});
|
24
static/js/familysearch.js
Normal file
24
static/js/familysearch.js
Normal file
@ -0,0 +1,24 @@
|
||||
/* 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/. */
|
||||
|
||||
$("#familysearchbtn").click(function () {
|
||||
$("#familysearchmodal").modal("show");
|
||||
});
|
||||
|
||||
$("#familysearchmodal #familysearchbox").on("input propertychange paste", function () {
|
||||
$.getJSON("action.php", {
|
||||
action: "familysearch",
|
||||
q: $("#familysearchbox").val()
|
||||
}, function (resp) {
|
||||
$("#familysearchresults").html("");
|
||||
for (var i = 0; i < resp.length; i++) {
|
||||
$("#familysearchresults").append('<div class="list-group-item familysearchresult" data-familyid="' + resp[i]['id'] + '">' + resp[i]['name'] + '</div>');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("#familysearchmodal").on("click", ".familysearchresult", function () {
|
||||
$("input[name=familyid]").val($(this).data("familyid"));
|
||||
$("#familysearchmodal").modal("hide");
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user