Classify families and children
This commit is contained in:
parent
c82baef506
commit
d3b7289b22
@ -35,4 +35,10 @@ switch ($VARS['action']) {
|
|||||||
session_destroy();
|
session_destroy();
|
||||||
header('Location: index.php');
|
header('Location: index.php');
|
||||||
die("Logged out.");
|
die("Logged out.");
|
||||||
|
case "editfamily":
|
||||||
|
if (!(new User($_SESSION['uid']))->hasPermission("HACHEPORTAL_EDIT")) {
|
||||||
|
returnToSender("no_permission");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
114
lib/Child.lib.php
Normal file
114
lib/Child.lib.php
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Child {
|
||||||
|
|
||||||
|
private $id;
|
||||||
|
private $familyid;
|
||||||
|
private $name;
|
||||||
|
private $birthday;
|
||||||
|
private $graduated;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function load(int $id): Child {
|
||||||
|
global $database;
|
||||||
|
$info = $database->get('people', ["familyid", "name", "birthday", "graduated"], ['personid' => $id]);
|
||||||
|
|
||||||
|
$this->id = $id;
|
||||||
|
$this->familyid = $info['familyid'];
|
||||||
|
$this->name = $info['name'];
|
||||||
|
$this->birthday = strtotime($info['birthday']);
|
||||||
|
$this->graduated = $info['graduated'] == 1;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save() {
|
||||||
|
global $database;
|
||||||
|
if (is_int($this->id) && $database->has("people", ['personid' => $this->id])) {
|
||||||
|
$database->update("people", ["name" => $this->name, "birthday" => date("Y-m-d", $this->birthday), "graduated" => $this->graduated], ['personid' => $this->id]);
|
||||||
|
} else {
|
||||||
|
$database->insert("people", ["familyid" => $this->familyid, "name" => $this->name, "birthday" => date("Y-m-d", $this->birthday), "graduated" => $this->graduated]);
|
||||||
|
$this->id = $database->id();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function exists(int $cid, int $fid = null) {
|
||||||
|
global $database;
|
||||||
|
if (is_null($fid)) {
|
||||||
|
return $database->has("people", [
|
||||||
|
'personid' => $cid
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
return $database->has("people", ["AND" => [
|
||||||
|
'familyid' => $fid,
|
||||||
|
'personid' => $cid
|
||||||
|
]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getID(): int {
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFamilyID(): int {
|
||||||
|
return $this->familyid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFamily(): Family {
|
||||||
|
return (new Family())->load($this->familyid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName(): string {
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the person's birth date as a UNIX timestamp.
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getBirthday(): int {
|
||||||
|
return $this->birthday;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isGraduated(): bool {
|
||||||
|
return $this->graduated == true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName(string $name) {
|
||||||
|
$this->name = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the person's birth date to either a UNIX timestamp or a date string.
|
||||||
|
* @param int $timestamp
|
||||||
|
* @param string $date A string parseable by strtotime().
|
||||||
|
*/
|
||||||
|
public function setBirthday(int $timestamp = null, string $date = null) {
|
||||||
|
if (is_null($timestamp) && !is_null($date)) {
|
||||||
|
$this->birthday = strtotime($date);
|
||||||
|
} else if (!is_null($timestamp) && is_null($date)) {
|
||||||
|
$this->birthday = $timestamp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setGraduated(bool $graduated) {
|
||||||
|
$this->graduated = $graduated;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFamilyID(int $id) {
|
||||||
|
$this->familyid = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFamily(Family $f) {
|
||||||
|
$this->familyid = $f->getID();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
255
lib/Family.lib.php
Normal file
255
lib/Family.lib.php
Normal file
@ -0,0 +1,255 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Family {
|
||||||
|
|
||||||
|
private $id;
|
||||||
|
private $name;
|
||||||
|
private $father;
|
||||||
|
private $mother;
|
||||||
|
private $phone;
|
||||||
|
private $email;
|
||||||
|
private $address;
|
||||||
|
private $city;
|
||||||
|
private $state;
|
||||||
|
private $zip;
|
||||||
|
private $photo;
|
||||||
|
private $newsletter;
|
||||||
|
private $children = [];
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a family from the database into this object
|
||||||
|
* @global type $database
|
||||||
|
* @param int $familyid
|
||||||
|
* @return \Family
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function load(int $familyid): Family {
|
||||||
|
global $database;
|
||||||
|
if ($database->has("families", ['familyid' => $familyid])) {
|
||||||
|
$this->id = $familyid;
|
||||||
|
} else {
|
||||||
|
throw new Exception("No such family exists.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$f = $database->get("families", [
|
||||||
|
'familyid (id)',
|
||||||
|
'familyname (name)',
|
||||||
|
'phone',
|
||||||
|
'email',
|
||||||
|
'newsletter_method (newsletter)',
|
||||||
|
'address',
|
||||||
|
'city',
|
||||||
|
'state',
|
||||||
|
'zip',
|
||||||
|
'father_name (father)',
|
||||||
|
'mother_name (mother)',
|
||||||
|
'photo_permission (photo)'
|
||||||
|
], [
|
||||||
|
"familyid" => $this->id
|
||||||
|
]);
|
||||||
|
|
||||||
|
$children = $database->select("people", 'personid', ["familyid" => $this->id]);
|
||||||
|
|
||||||
|
$this->name = $f['name'];
|
||||||
|
$this->father = $f['father'];
|
||||||
|
$this->mother = $f['mother'];
|
||||||
|
$this->phone = $f['phone'];
|
||||||
|
$this->email = $f['email'];
|
||||||
|
$this->address = $f['address'];
|
||||||
|
$this->city = $f['city'];
|
||||||
|
$this->state = $f['state'];
|
||||||
|
$this->zip = $f['zip'];
|
||||||
|
$this->photo = $f['photo'] == 1;
|
||||||
|
$this->newsletter = $f['newsletter'];
|
||||||
|
|
||||||
|
foreach ($children as $c) {
|
||||||
|
$this->children[] = (new Child())->load($c);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save() {
|
||||||
|
global $database;
|
||||||
|
if (is_int($this->id) && $database->has("families", ['familyid' => $this->id])) {
|
||||||
|
$database->update("families", [
|
||||||
|
"familyname" => $this->getName(),
|
||||||
|
"father_name" => $this->getFather(),
|
||||||
|
"mother_name" => $this->getMother(),
|
||||||
|
"phone" => $this->getPhone(),
|
||||||
|
"email" => $this->getEmail(),
|
||||||
|
"address" => $this->getAddress(),
|
||||||
|
"city" => $this->getCity(),
|
||||||
|
"state" => $this->getState(),
|
||||||
|
"zip" => $this->getZip(),
|
||||||
|
"photo_permission" => $this->getPhotoPermission(),
|
||||||
|
"newsletter_method" => $this->getNewsletter()
|
||||||
|
], [
|
||||||
|
"familyid" => $this->id
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$database->insert("families", [
|
||||||
|
"familyname" => $this->getName(),
|
||||||
|
"father_name" => $this->getFather(),
|
||||||
|
"mother_name" => $this->getMother(),
|
||||||
|
"phone" => $this->getPhone(),
|
||||||
|
"email" => $this->getEmail(),
|
||||||
|
"address" => $this->getAddress(),
|
||||||
|
"city" => $this->getCity(),
|
||||||
|
"state" => $this->getState(),
|
||||||
|
"zip" => $this->getZip(),
|
||||||
|
"photo_permission" => $this->getPhotoPermission(),
|
||||||
|
"newsletter_method" => $this->getNewsletter()
|
||||||
|
]);
|
||||||
|
$this->id = $database->id();
|
||||||
|
}
|
||||||
|
|
||||||
|
for ($i = 0; $i < count($this->children); $i++) {
|
||||||
|
$this->children[$i]->setFamilyID($this->id);
|
||||||
|
$this->children[$i]->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getID() {
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName(): string {
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFather(): string {
|
||||||
|
return $this->father;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMother(): string {
|
||||||
|
return $this->mother;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPhone(): string {
|
||||||
|
return $this->phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEmail(): string {
|
||||||
|
return $this->email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAddress(): string {
|
||||||
|
return $this->address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCity(): string {
|
||||||
|
return $this->city;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getState(): string {
|
||||||
|
return $this->state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getZip(): string {
|
||||||
|
return $this->zip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPhotoPermission(): bool {
|
||||||
|
return $this->photo == true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNewsletter(): int {
|
||||||
|
return $this->newsletter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getChildren(): array {
|
||||||
|
return $this->children;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function setName(string $name) {
|
||||||
|
$this->name = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFather(string $name) {
|
||||||
|
$this->father = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMother(string $name) {
|
||||||
|
$this->mother = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPhone(string $phone) {
|
||||||
|
$phone = preg_replace("/[^0-9]/", "", $phone);
|
||||||
|
if (strlen($phone) == 11) {
|
||||||
|
$phone = preg_replace("/^1/", "", $phone);
|
||||||
|
}
|
||||||
|
if (strlen($phone) != 10) {
|
||||||
|
throw new Exception("Enter a valid 10-digit phone number.");
|
||||||
|
}
|
||||||
|
$this->phone = $phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setEmail(string $email) {
|
||||||
|
$email = strtolower($email);
|
||||||
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||||
|
throw new Exception("The email address looks wrong.");
|
||||||
|
}
|
||||||
|
$this->email = $email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAddress(string $address) {
|
||||||
|
$this->address = $address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCity(string $city) {
|
||||||
|
$this->city = $city;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the state, in two-character form.
|
||||||
|
* @param string $state
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function setState(string $state) {
|
||||||
|
$state = strtoupper($state);
|
||||||
|
if (!preg_match("/^[A-Z]{2}$/", $state)) {
|
||||||
|
throw new Exception("Select a valid state.");
|
||||||
|
}
|
||||||
|
$this->state = strtoupper($state);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setZip(string $zip) {
|
||||||
|
if (!preg_match("/^[0-9]{5}(-?[0-9]{4})?$/", $zip)) {
|
||||||
|
throw new Exception("Enter a valid five or nine digit US ZIP code.");
|
||||||
|
}
|
||||||
|
$this->zip = $zip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPhotoPermission(bool $perm) {
|
||||||
|
$this->photo = $perm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setNewsletter(int $newsletter) {
|
||||||
|
if (!is_int($newsletter) || !($newsletter == 1 || $newsletter == 2 || $newsletter == 3)) {
|
||||||
|
throw new Exception("Invalid newsletter preference.");
|
||||||
|
}
|
||||||
|
$this->newsletter = $newsletter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setChildren(array $children) {
|
||||||
|
$this->children = $children;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addChild(Child $child) {
|
||||||
|
$this->children[] = $child;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -20,24 +20,7 @@ if (empty($VARS['id']) || !$database->has('families', ['familyid' => $VARS['id']
|
|||||||
|
|
||||||
$famid = $VARS['id'];
|
$famid = $VARS['id'];
|
||||||
|
|
||||||
$family = $database->get("families", [
|
$family = (new Family())->load($famid);
|
||||||
'familyid (id)',
|
|
||||||
'familyname (name)',
|
|
||||||
'phone',
|
|
||||||
'email',
|
|
||||||
'newsletter_method (newsletter)',
|
|
||||||
'address',
|
|
||||||
'city',
|
|
||||||
'state',
|
|
||||||
'zip',
|
|
||||||
'father_name (father)',
|
|
||||||
'mother_name (mother)',
|
|
||||||
'photo_permission (photo)'
|
|
||||||
], [
|
|
||||||
"familyid" => $famid
|
|
||||||
]);
|
|
||||||
|
|
||||||
$children = $database->select("people", ["name", "birthday", "graduated"], ["familyid" => $famid]);
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
@ -47,13 +30,13 @@ $children = $database->select("people", ["name", "birthday", "graduated"], ["fam
|
|||||||
<a href="app.php?page=families" class="text-body">
|
<a href="app.php?page=families" class="text-body">
|
||||||
<i class="fas fa-arrow-left"></i>
|
<i class="fas fa-arrow-left"></i>
|
||||||
</a>
|
</a>
|
||||||
<?php echo $family['name']; ?> <?php $Strings->get("Family"); ?>
|
<?php echo $family->getName(); ?> <?php $Strings->get("Family"); ?>
|
||||||
</h3>
|
</h3>
|
||||||
<div>
|
<div>
|
||||||
<?php
|
<?php
|
||||||
if ($writeaccess) {
|
if ($writeaccess) {
|
||||||
?>
|
?>
|
||||||
<a href="app.php?page=editfamily&id=<?php echo $family['id']; ?>&source=viewfamily" class="btn btn-primary"><i class="fas fa-edit"></i> <?php $Strings->get('Edit Family'); ?></a>
|
<a href="app.php?page=editfamily&id=<?php echo $family->getID(); ?>&source=viewfamily" class="btn btn-primary"><i class="fas fa-edit"></i> <?php $Strings->get('Edit Family'); ?></a>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
@ -63,7 +46,7 @@ $children = $database->select("people", ["name", "birthday", "graduated"], ["fam
|
|||||||
<div class="d-flex justify-content-around flex-wrap">
|
<div class="d-flex justify-content-around flex-wrap">
|
||||||
<?php
|
<?php
|
||||||
$newsletter = "Email";
|
$newsletter = "Email";
|
||||||
switch ($family['newsletter']) {
|
switch ($family->getNewsletter()) {
|
||||||
case 1:
|
case 1:
|
||||||
$newsletter = $Strings->get("Email", false);
|
$newsletter = $Strings->get("Email", false);
|
||||||
break;
|
break;
|
||||||
@ -76,47 +59,47 @@ $children = $database->select("people", ["name", "birthday", "graduated"], ["fam
|
|||||||
}
|
}
|
||||||
$items = [
|
$items = [
|
||||||
[
|
[
|
||||||
"db" => "father",
|
"value" => $family->getFather(),
|
||||||
"icon" => "fas fa-male",
|
"icon" => "fas fa-male",
|
||||||
"label" => "Father"
|
"label" => "Father"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"db" => "mother",
|
"value" => $family->getMother(),
|
||||||
"icon" => "fas fa-female",
|
"icon" => "fas fa-female",
|
||||||
"label" => "Mother"
|
"label" => "Mother"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"db" => "phone",
|
"value" => $family->getPhone(),
|
||||||
"icon" => "fas fa-phone",
|
"icon" => "fas fa-phone",
|
||||||
"label" => "Phone"
|
"label" => "Phone"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"db" => "email",
|
"value" => $family->getEmail(),
|
||||||
"icon" => "fas fa-at",
|
"icon" => "fas fa-at",
|
||||||
"label" => "Email"
|
"label" => "Email"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"db" => "address",
|
"value" => $family->getAddress(),
|
||||||
"icon" => "fas fa-map-marker",
|
"icon" => "fas fa-home",
|
||||||
"label" => "Address"
|
"label" => "Address"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"db" => "city",
|
"value" => $family->getCity(),
|
||||||
"icon" => "fas fa-city",
|
"icon" => "fas fa-city",
|
||||||
"label" => "City"
|
"label" => "City"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"db" => "state",
|
"value" => $family->getState(),
|
||||||
"icon" => "fas fa-flag",
|
"icon" => "fas fa-flag",
|
||||||
"label" => "State"
|
"label" => "State"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"db" => "zip",
|
"value" => $family->getZip(),
|
||||||
"icon" => "fas fa-mail-bulk",
|
"icon" => "fas fa-mail-bulk",
|
||||||
"label" => "ZIP Code"
|
"label" => "ZIP Code"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"value" => $family['photo'] ? $Strings->get("Yes", false) : $Strings->get("No", false),
|
"value" => $family->getPhotoPermission() ? $Strings->get("Yes", false) : $Strings->get("No", false),
|
||||||
"icon" => "fas fa-camera",
|
"icon" => "fas fa-camera",
|
||||||
"label" => "Photo Permission"
|
"label" => "Photo Permission"
|
||||||
],
|
],
|
||||||
@ -132,11 +115,7 @@ $children = $database->select("people", ["name", "birthday", "graduated"], ["fam
|
|||||||
<i class="<?php echo $i['icon']; ?>"></i> <?php
|
<i class="<?php echo $i['icon']; ?>"></i> <?php
|
||||||
$Strings->get($i['label']);
|
$Strings->get($i['label']);
|
||||||
echo ": ";
|
echo ": ";
|
||||||
if (empty($i['db'])) {
|
|
||||||
echo $i['value'];
|
echo $i['value'];
|
||||||
} else {
|
|
||||||
echo $family[$i['db']];
|
|
||||||
}
|
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
@ -156,12 +135,12 @@ $children = $database->select("people", ["name", "birthday", "graduated"], ["fam
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php
|
<?php
|
||||||
foreach ($children as $c) {
|
foreach ($family->getChildren() as $c) {
|
||||||
?>
|
?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?php echo $c['name']; ?></td>
|
<td><?php echo $c->getName(); ?></td>
|
||||||
<td><?php echo date("F Y", strtotime($c['birthday'])); ?></td>
|
<td><?php echo date("F Y", $c->getBirthday()); ?></td>
|
||||||
<td><?php $c['graduated'] == 1 ? $Strings->get("Yes") : $Strings->get("No"); ?></td>
|
<td><?php $c->isGraduated() ? $Strings->get("Yes") : $Strings->get("No"); ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,9 @@
|
|||||||
|
|
||||||
require_once __DIR__ . "/../../lib/requiredpublic.php";
|
require_once __DIR__ . "/../../lib/requiredpublic.php";
|
||||||
|
|
||||||
|
require_once __DIR__ . "/../../lib/Family.lib.php";
|
||||||
|
require_once __DIR__ . "/../../lib/Child.lib.php";
|
||||||
|
|
||||||
function errorBack(string $errormsg) {
|
function errorBack(string $errormsg) {
|
||||||
header("Location: ../?page=signup&error=" . htmlentities($errormsg));
|
header("Location: ../?page=signup&error=" . htmlentities($errormsg));
|
||||||
die($errormsg);
|
die($errormsg);
|
||||||
@ -17,8 +20,10 @@ if (empty($_POST['agree_terms'])) {
|
|||||||
errorBack("You must agree to HACHE's policy.");
|
errorBack("You must agree to HACHE's policy.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$family = new Family();
|
||||||
|
|
||||||
if (!empty($_SESSION['familyid']) && $database->has("families", ['familyid' => $_SESSION['familyid']])) {
|
if (!empty($_SESSION['familyid']) && $database->has("families", ['familyid' => $_SESSION['familyid']])) {
|
||||||
$familyid = $_SESSION['familyid'];
|
$family = (new Family())->load($familyid);
|
||||||
} else if (!empty($_POST['renewing'])) {
|
} else if (!empty($_POST['renewing'])) {
|
||||||
// Session expired, but we're renewing, so kick them back to verification
|
// Session expired, but we're renewing, so kick them back to verification
|
||||||
header("Location: ../?page=renew&msg=sessionexpired");
|
header("Location: ../?page=renew&msg=sessionexpired");
|
||||||
@ -26,7 +31,9 @@ if (!empty($_SESSION['familyid']) && $database->has("families", ['familyid' => $
|
|||||||
}
|
}
|
||||||
|
|
||||||
$database->action(function($database) {
|
$database->action(function($database) {
|
||||||
global $familyid;
|
global $family;
|
||||||
|
|
||||||
|
try {
|
||||||
$lastname = $_POST['familyname'];
|
$lastname = $_POST['familyname'];
|
||||||
$father = $_POST['fathername'];
|
$father = $_POST['fathername'];
|
||||||
$mother = $_POST['mothername'];
|
$mother = $_POST['mothername'];
|
||||||
@ -41,19 +48,12 @@ $database->action(function($database) {
|
|||||||
errorBack("Enter a mother name.");
|
errorBack("Enter a mother name.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$phone = $_POST['phone'];
|
$family->setName($lastname);
|
||||||
$phone = preg_replace("/[^0-9]/", "", $phone);
|
$family->setFather($father);
|
||||||
if (strlen($phone) == 11) {
|
$family->setMother($mother);
|
||||||
$phone = preg_replace("/^1/", "", $phone);
|
|
||||||
}
|
|
||||||
if (strlen($phone) != 10) {
|
|
||||||
errorBack("Enter a valid 10-digit phone number.");
|
|
||||||
}
|
|
||||||
|
|
||||||
$email = strtolower($_POST['email']);
|
$family->setPhone($_POST['phone']);
|
||||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
$family->setEmail($_POST['email']);
|
||||||
errorBack("The email address looks wrong.");
|
|
||||||
}
|
|
||||||
|
|
||||||
$address = $_POST['streetaddress'];
|
$address = $_POST['streetaddress'];
|
||||||
$city = $_POST['city'];
|
$city = $_POST['city'];
|
||||||
@ -65,18 +65,18 @@ $database->action(function($database) {
|
|||||||
if (empty($city)) {
|
if (empty($city)) {
|
||||||
errorBack("Enter a city.");
|
errorBack("Enter a city.");
|
||||||
}
|
}
|
||||||
if (!preg_match("/^[A-Z]{2}$/", $state)) {
|
$family->setAddress($address);
|
||||||
errorBack("Select a state.");
|
$family->setCity($city);
|
||||||
}
|
$family->setState($state);
|
||||||
if (!preg_match("/^[0-9]{5}(-?[0-9]{4})?$/", $zip)) {
|
$family->setZip($zip);
|
||||||
errorBack("Enter a valid five or nine digit US ZIP code.");
|
|
||||||
}
|
|
||||||
|
|
||||||
$newsletter = $_POST['newsletter_method'];
|
$newsletter = $_POST['newsletter_method'];
|
||||||
$membership_cost = 2500;
|
$membership_cost = 2500;
|
||||||
if (empty($newsletter)) {
|
if (empty($newsletter)) {
|
||||||
errorBack("Select a newsletter preference.");
|
errorBack("Select a newsletter preference.");
|
||||||
}
|
}
|
||||||
|
$family->setNewsletter($newsletter);
|
||||||
switch ($newsletter) {
|
switch ($newsletter) {
|
||||||
case 1: // Email only
|
case 1: // Email only
|
||||||
$membership_cost = 2500;
|
$membership_cost = 2500;
|
||||||
@ -97,43 +97,17 @@ $database->action(function($database) {
|
|||||||
} else {
|
} else {
|
||||||
$photopermission = false;
|
$photopermission = false;
|
||||||
}
|
}
|
||||||
|
$family->setPhotoPermission($photopermission);
|
||||||
|
|
||||||
if (isset($familyid)) {
|
$family->save();
|
||||||
$database->update("families", [
|
|
||||||
"familyname" => $lastname,
|
|
||||||
"father_name" => $father,
|
|
||||||
"mother_name" => $mother,
|
|
||||||
"phone" => $phone,
|
|
||||||
"email" => $email,
|
|
||||||
"newsletter_method" => $newsletter,
|
|
||||||
"address" => $address,
|
|
||||||
"city" => $city,
|
|
||||||
"state" => $state,
|
|
||||||
"zip" => $zip,
|
|
||||||
"photo_permission" => $photopermission
|
|
||||||
], [
|
|
||||||
'familyid' => $familyid
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
$database->insert("families", [
|
|
||||||
"familyname" => $lastname,
|
|
||||||
"father_name" => $father,
|
|
||||||
"mother_name" => $mother,
|
|
||||||
"phone" => $phone,
|
|
||||||
"email" => $email,
|
|
||||||
"newsletter_method" => $newsletter,
|
|
||||||
"address" => $address,
|
|
||||||
"city" => $city,
|
|
||||||
"state" => $state,
|
|
||||||
"zip" => $zip,
|
|
||||||
"photo_permission" => $photopermission
|
|
||||||
]);
|
|
||||||
|
|
||||||
$familyid = $database->id();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Children
|
||||||
|
//
|
||||||
$children = $_POST['child'];
|
$children = $_POST['child'];
|
||||||
|
|
||||||
|
$childObjects = $family->getChildren();
|
||||||
|
|
||||||
foreach ($children['ids'] as $cid) {
|
foreach ($children['ids'] as $cid) {
|
||||||
if (empty($children['name'][$cid])) {
|
if (empty($children['name'][$cid])) {
|
||||||
continue;
|
continue;
|
||||||
@ -151,25 +125,37 @@ $database->action(function($database) {
|
|||||||
errorBack("Invalid birth year chosen for " . htmlentities($children['name'][$cid]) . ".");
|
errorBack("Invalid birth year chosen for " . htmlentities($children['name'][$cid]) . ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($database->has('people', ["AND" => [
|
if (Child::exists($cid, $family->getID())) {
|
||||||
'familyid' => $familyid,
|
// iterate over existing children to find the correct one
|
||||||
'personid' => $cid
|
for ($i = 0; $i < count($childObjects); $i++) {
|
||||||
]])) {
|
if ($childObjects[$i]->getID() == $cid) {
|
||||||
$database->update('people', [
|
$childObjects[$i]->setName($children['name'][$cid]);
|
||||||
"name" => $children['name'][$cid],
|
$childObjects[$i]->setBirthday(null, $children['year'][$cid] . "-" . $children['month'][$cid] . "-00");
|
||||||
"birthday" => $children['year'][$cid] . "-" . $children['month'][$cid] . "-00",
|
$childObjects[$i]->setGraduated(empty($children['graduate'][$cid]) ? false : true);
|
||||||
"graduated" => empty($children['graduate'][$cid]) ? 0 : 1
|
}
|
||||||
], ['personid' => $cid]);
|
}
|
||||||
} else {
|
} else {
|
||||||
$database->insert("people", [
|
$child = new Child();
|
||||||
"familyid" => $familyid,
|
$child->setName($children['name'][$cid]);
|
||||||
"name" => $children['name'][$cid],
|
$child->setBirthday(null, $children['year'][$cid] . "-" . $children['month'][$cid] . "-00");
|
||||||
"birthday" => $children['year'][$cid] . "-" . $children['month'][$cid] . "-00",
|
$child->setGraduated(empty($children['graduate'][$cid]) ? false : true);
|
||||||
"graduated" => empty($children['graduate'][$cid]) ? 0 : 1
|
$child->setFamilyID($family->getID());
|
||||||
]);
|
$childObjects[] = $child;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($childObjects as $child) {
|
||||||
|
$child->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
errorBack($ex->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Interests
|
||||||
|
//
|
||||||
$database->delete('interests', ['familyid' => $familyid]);
|
$database->delete('interests', ['familyid' => $familyid]);
|
||||||
$interests = [];
|
$interests = [];
|
||||||
foreach ($_POST['events'] as $evt) {
|
foreach ($_POST['events'] as $evt) {
|
||||||
@ -180,6 +166,10 @@ $database->action(function($database) {
|
|||||||
$database->insert("interests", $interests);
|
$database->insert("interests", $interests);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Payment
|
||||||
|
//
|
||||||
try {
|
try {
|
||||||
\Stripe\Stripe::setApiKey(STRIPE_SECKEY);
|
\Stripe\Stripe::setApiKey(STRIPE_SECKEY);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user