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' } ?> +