diff --git a/action.php b/action.php index da11934..82b702d 100644 --- a/action.php +++ b/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); } \ No newline at end of file diff --git a/database.mwb b/database.mwb index 7b28f0c..416b046 100644 Binary files a/database.mwb and b/database.mwb differ diff --git a/langs/messages.php b/langs/messages.php index 0b3c6f7..feac3c6 100644 --- a/langs/messages.php +++ b/langs/messages.php @@ -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" => [ diff --git a/pages.php b/pages.php index 3cc7a78..de0a66a 100644 --- a/pages.php +++ b/pages.php @@ -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" => [ diff --git a/pages/editpayment.php b/pages/editpayment.php index dbb7f15..f22e4b4 100644 --- a/pages/editpayment.php +++ b/pages/editpayment.php @@ -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' } ?> + +
@@ -52,6 +70,29 @@ if (!empty($_GET['id']) && $database->has('payments', ['paymentid' => $_GET['id'
+
+
+ +
+
+ +
+ +
+ Enter a family ID. +
+
+
+
+ + 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, diff --git a/pages/editperson.php b/pages/editperson.php index 5875e19..eb73f6e 100644 --- a/pages/editperson.php +++ b/pages/editperson.php @@ -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; } ?> + +
@@ -88,20 +108,41 @@ if (!empty($VARS['id']) && $database->has('people', ['personid' => $VARS['id']])
+
+
+ +
+
+ +
+ +
+ Enter a family ID. +
+
+
+
+ "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." diff --git a/static/js/families.js b/static/js/families.js deleted file mode 100644 index 60d92eb..0000000 --- a/static/js/families.js +++ /dev/null @@ -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 " " + 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'] - ] -}); \ No newline at end of file diff --git a/static/js/familysearch.js b/static/js/familysearch.js new file mode 100644 index 0000000..54bd239 --- /dev/null +++ b/static/js/familysearch.js @@ -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('
' + resp[i]['name'] + '
'); + } + }); +}); + +$("#familysearchmodal").on("click", ".familysearchresult", function () { + $("input[name=familyid]").val($(this).data("familyid")); + $("#familysearchmodal").modal("hide"); +}); \ No newline at end of file