diff --git a/database.mwb b/database.mwb index a54c587..d585347 100644 Binary files a/database.mwb and b/database.mwb differ diff --git a/lib/requiredpublic.php b/lib/requiredpublic.php index e0b8db6..9817887 100644 --- a/lib/requiredpublic.php +++ b/lib/requiredpublic.php @@ -18,6 +18,8 @@ if (!DEBUG) { ini_set('display_errors', 'On'); } +session_start(); + // Unicode, solves almost all stupid encoding problems header('Content-Type: text/html; charset=utf-8'); diff --git a/public/actions/submitmembership.php b/public/actions/submitmembership.php index c37e5ce..fffa2c4 100644 --- a/public/actions/submitmembership.php +++ b/public/actions/submitmembership.php @@ -17,7 +17,12 @@ if (empty($_POST['agree_terms'])) { errorBack("You must agree to HACHE's policy."); } +if (!empty($_SESSION['familyid']) && $database->has("families", ['familyid' => $_SESSION['familyid']])) { + $familyid = $_SESSION['familyid']; +} + $database->action(function($database) { + global $familyid; $lastname = $_POST['familyname']; $father = $_POST['fathername']; $mother = $_POST['mothername']; @@ -89,21 +94,39 @@ $database->action(function($database) { $photopermission = false; } - $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 - ]); + if (isset($familyid)) { + $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(); + $familyid = $database->id(); + } $children = $_POST['child']; @@ -124,14 +147,26 @@ $database->action(function($database) { errorBack("Invalid birth year chosen for " . htmlentities($children['name'][$cid]) . "."); } - $database->insert("people", [ - "familyid" => $familyid, - "name" => $children['name'][$cid], - "birthday" => $children['year'][$cid] . "-" . $children['month'][$cid] . "-00", - "graduated" => empty($children['graduate'][$cid]) ? 0 : 1 - ]); + if ($database->has('people', ["AND" => [ + 'familyid' => $familyid, + 'personid' => $cid + ]])) { + $database->update('people', [ + "name" => $children['name'][$cid], + "birthday" => $children['year'][$cid] . "-" . $children['month'][$cid] . "-00", + "graduated" => empty($children['graduate'][$cid]) ? 0 : 1 + ], ['personid' => $cid]); + } else { + $database->insert("people", [ + "familyid" => $familyid, + "name" => $children['name'][$cid], + "birthday" => $children['year'][$cid] . "-" . $children['month'][$cid] . "-00", + "graduated" => empty($children['graduate'][$cid]) ? 0 : 1 + ]); + } } + $database->delete('interests', ['familyid' => $familyid]); $interests = []; foreach ($_POST['events'] as $evt) { if ($database->has("events", ['eventid' => $evt])) { @@ -143,7 +178,7 @@ $database->action(function($database) { try { \Stripe\Stripe::setApiKey(STRIPE_SECKEY); - + $charge = \Stripe\Charge::create([ 'amount' => $membership_cost, 'currency' => 'usd', @@ -151,7 +186,6 @@ $database->action(function($database) { 'source' => $_POST['stripeToken'], 'statement_descriptor' => 'HACHE Membership 1yr', ]); - } catch (\Stripe\Error\Card $e) { $body = $e->getJsonBody(); $err = $body['error']; diff --git a/public/parts/signup.php b/public/parts/signup.php index 4b02c96..903167d 100644 --- a/public/parts/signup.php +++ b/public/parts/signup.php @@ -4,6 +4,34 @@ * 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/. */ + +$familyname = ""; +$fathername = ""; +$mothername = ""; +$streetaddress = ""; +$city = ""; +$state = ""; +$zip = ""; +$phone = ""; +$email = ""; +$newsletter_method = ""; + +$children = []; + +if (isset($_SESSION['familyid']) && $database->has('families', ['familyid' => $_SESSION['familyid']])) { + $familyinfo = $database->get("families", ['familyname', 'phone', 'email', 'address', 'city', 'state', 'zip', 'father_name (fathername)', 'mother_name (mothername)', 'newsletter_method'], ['familyid' => $_SESSION['familyid']]); + $children = $database->select("people", 'personid', ['familyid' => $_SESSION['familyid']]); + $familyname = $familyinfo['familyname']; + $fathername = $familyinfo['fathername']; + $mothername = $familyinfo['mothername']; + $streetaddress = $familyinfo['address']; + $city = $familyinfo['city']; + $state = $familyinfo['state']; + $zip = $familyinfo['zip']; + $phone = $familyinfo['phone']; + $email = $familyinfo['email']; + $newsletter_method = $familyinfo['newsletter_method']; +} ?>