diff --git a/action.php b/action.php index 1fffd9a..9636c47 100644 --- a/action.php +++ b/action.php @@ -58,6 +58,7 @@ switch ($VARS['action']) { "den" => "", "health" => "", "notes" => "", + "child_care" => null, "position" => "" ]; if (!empty($VARS['personid']) && $database->has("people", ['personid' => $VARS['personid']])) { @@ -204,9 +205,18 @@ switch ($VARS['action']) { } break; case "adult": + if (!empty($people["child_care"])) { + $items = preg_split("/[^\d]+/", $people["child_care"]); + $ages = []; + foreach ($items as $it) { + $ages[] = $it; + } + $people["child_care"] = implode(",", $ages); + } $data = [ "position" => $people["position"], - "days" => $days + "days" => $days, + "child_care" => empty($people["child_care"]) ? null : $people["child_care"] ]; if ($editing) { $database->update("adults", $data, ['adultid' => $person['adultid']]); @@ -255,7 +265,6 @@ switch ($VARS['action']) { } else { $database->insert("people", $data); } - } catch (Exception $ex) { errorBack($ex->getMessage()); } diff --git a/database.mwb b/database.mwb index 4ede813..c374162 100644 Binary files a/database.mwb and b/database.mwb differ diff --git a/langs/en/labels.json b/langs/en/labels.json index 133c2c2..a8e3369 100644 --- a/langs/en/labels.json +++ b/langs/en/labels.json @@ -33,6 +33,9 @@ "Den": "Den", "Health": "Health", "Notes": "Notes", + "Child Care Ages": "Child Care Ages", + "Age": "Age", + "Count": "Count", "Total": "Total", "Yes": "Yes", "No": "No", diff --git a/lib/reports.php b/lib/reports.php index 94c6d38..e17d64d 100644 --- a/lib/reports.php +++ b/lib/reports.php @@ -29,7 +29,7 @@ if (LOADED) { /** * Get a 2d array of the families in the database. * @global type $database - * @param array $filter Medoo WHERE clause. + * @param string $filter * @return string */ function getPeopleReport($filter = ""): Report { @@ -80,6 +80,7 @@ function getPeopleReport($filter = ""): Report { $Strings->get("Position", false), $Strings->get("Shirt", false), $Strings->get("Sex", false), + $Strings->get("Child Care Ages", false), $Strings->get("Notes", false) ]; break; @@ -168,6 +169,7 @@ function getPeopleReport($filter = ""): Report { $p['position'], $p['shirt'], $p['sex'], + $p['child_care'], $p['notes'] ]; break; @@ -208,6 +210,62 @@ function getPeopleReport($filter = ""): Report { return $report; } +/** + * Get a report of the children who need child care. + * @global type $database + * @return string + */ +function getChildCareReport(): Report { + global $database, $Strings; + + if (empty($filter)) { + $report = new Report($Strings->get("Child Care Ages", false)); + $filter = ["ORDER" => ["familyname" => "ASC"]]; + } else { + $report = new Report($Strings->get("$filter", false)); + } + + $join = []; + $where = []; + + $header = [ + $Strings->get("Age", false), + $Strings->get("Count", false) + ]; + + + $results = $database->select("adults", 'child_care', ["child_care[!]" => null]); + + + $report->setHeader($header); + + $ages = []; + + $totalcount = 0; + + foreach ($results as $r) { + $items = preg_split("/[^\d]+/", $r); + foreach ($items as $it) { + if (!isset($ages[$it])) { + $ages[$it] = 1; + } else { + $ages[$it]++; + } + $totalcount++; + } + } + + ksort($ages); + + foreach ($ages as $age => $count) { + $report->addDataRow(["$age", "$count"]); + } + + $report->addDataRow([$Strings->get("Total", false), "$totalcount"]); + + return $report; +} + function getReport($type): Report { switch ($type) { case "campers": @@ -222,6 +280,9 @@ function getReport($type): Report { case "people": return getPeopleReport(""); break; + case "childcare": + return getChildCareReport(); + break; default: return new Report("error", ["ERROR"], ["Invalid report type."]); } diff --git a/pages/editperson.php b/pages/editperson.php index 7ce04ca..f22b185 100644 --- a/pages/editperson.php +++ b/pages/editperson.php @@ -29,7 +29,8 @@ $data = [ "days" => "", "den" => "", "health" => "", - "notes" => "" + "notes" => "", + "child_care" => "" ]; $type = "camper"; if (!empty($VARS['type']) && preg_match("/(camper|adult|youth)/", $VARS['type'])) { @@ -58,7 +59,7 @@ if (!empty($VARS['id']) && $database->has('people', ['personid' => $VARS['id']]) $data = array_merge($data, $database->get('campers', ['parentname', 'rank', 'den', 'health'], ['camperid' => $data["camperid"]])); } else if (!empty($data["adultid"])) { $type = "adult"; - $data = array_merge($data, $database->get('adults', ['days', 'position'], ['adultid' => $data["adultid"]])); + $data = array_merge($data, $database->get('adults', ['days', 'position', 'child_care'], ['adultid' => $data["adultid"]])); } else if (!empty($data["youthid"])) { $type = "youth"; $data = array_merge($data, $database->get('youth', ['days', 'position', 'parentname'], ['youthid' => $data["youthid"]])); @@ -382,6 +383,17 @@ if (!empty($VARS['id']) && $database->has('people', ['personid' => $VARS['id']]) ] ]); } + if ($type == "adult") { + $textboxes = array_merge($textboxes, [ + [ + "label" => "Child care ages", + "name" => "child_care", + "optional" => true, + "width" => 6, + "value" => $data["child_care"] + ], + ]); + } $textboxes = array_merge($textboxes, [ [ "label" => "Notes", diff --git a/pages/reports.php b/pages/reports.php index 93ba6de..c48d228 100644 --- a/pages/reports.php +++ b/pages/reports.php @@ -15,7 +15,7 @@
-
+ - \ No newline at end of file diff --git a/public/actions/submit.php b/public/actions/submit.php index 0fb7515..cc46318 100644 --- a/public/actions/submit.php +++ b/public/actions/submit.php @@ -160,6 +160,14 @@ $database->action(function($database) { $dueusd += 10.0; } } + if (!empty($people["child_care"][$pid])) { + $items = preg_split("/[^\d]+/", $people["child_care"][$pid]); + $ages = []; + foreach ($items as $it) { + $ages[] = $it; + } + $people["child_care"][$pid] = implode(",", $ages); + } $database->insert("adults", [ "position" => $people["position"][$pid], "days" => $days,