From fce563b4b6d6bc74fac3385cea485c4c087059d7 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Thu, 19 Oct 2017 14:04:19 -0400 Subject: [PATCH] Added function to check if the requesting account has permission to access the cart and if cart should be assigned to the account. Fixed incorrect "ID" (should be "id") in updateTimeEntryCounts() in regCartSupport. Removed some unwanted fields in several data classes and added pointer entries to get frequently used data. Updated cart and checkout links and other layout issues for registrations. --- classes/data/dataRegRequestClass.php | 8 -- classes/data/dataRegRequestEvent.php | 9 +- classes/data/dataRegRequestRate.php | 8 -- classes/data/dataRegRequestRegistrant.php | 8 -- classes/regCartSupport.php | 113 ++++++++++++++++-- models/admin/registrations/events.php | 4 - models/front/registrations/cart.php | 15 ++- models/front/registrations/checkout.php | 1 + .../front/registrations/checkoutProcess.php | 1 + models/front/registrations/list.php | 1 + models/front/registrations/register.php | 1 + models/front/registrations/registration.php | 3 +- models/front/registrations/summary.php | 1 + .../create_database_V0.0.15.sql | 20 +--- .../admin/registrations/eventEditLevels.html | 6 +- .../registrations/requestsDashboard.html | 2 +- views/front/registrations/cart.html | 25 ++-- views/front/registrations/checkout.html | 7 +- views/front/registrations/header.html | 9 +- 19 files changed, 159 insertions(+), 83 deletions(-) diff --git a/classes/data/dataRegRequestClass.php b/classes/data/dataRegRequestClass.php index 85d1bcf..f93352b 100644 --- a/classes/data/dataRegRequestClass.php +++ b/classes/data/dataRegRequestClass.php @@ -160,14 +160,6 @@ class GlmDataRegistrationsRequestClass extends GlmDataAbstract 'use' => 'lgneud' ), - // Any MagicForm data associated with requested event - 'mf_data' => array ( - 'field' => 'mf_data', - 'type' => 'text', - 'required' => false, - 'use' => 'a' - ), - // System operator's notes for this registration request 'notes' => array ( 'field' => 'notes', diff --git a/classes/data/dataRegRequestEvent.php b/classes/data/dataRegRequestEvent.php index ecca510..d6e1774 100644 --- a/classes/data/dataRegRequestEvent.php +++ b/classes/data/dataRegRequestEvent.php @@ -165,14 +165,7 @@ class GlmDataRegistrationsRequestEvent extends GlmDataAbstract 'type' => 'text', 'required' => false, 'use' => 'a' - ), - // Any MagicForm data associated with requested event - 'mf_data' => array ( - 'field' => 'mf_data', - 'type' => 'text', - 'required' => false, - 'use' => 'a' - ), + ) ); diff --git a/classes/data/dataRegRequestRate.php b/classes/data/dataRegRequestRate.php index 3a2161d..3d4876e 100644 --- a/classes/data/dataRegRequestRate.php +++ b/classes/data/dataRegRequestRate.php @@ -210,14 +210,6 @@ class GlmDataRegistrationsRegRequestRate extends GlmDataAbstract 'use' => 'a' ), - // Any MagicForm data associated with registrant - 'mf_data' => array ( - 'field' => 'mf_data', - 'type' => 'text', - 'required' => false, - 'use' => 'a' - ), - // System operator's notes for this registration request 'notes' => array ( 'field' => 'notes', diff --git a/classes/data/dataRegRequestRegistrant.php b/classes/data/dataRegRequestRegistrant.php index 1269ecf..0bd087d 100644 --- a/classes/data/dataRegRequestRegistrant.php +++ b/classes/data/dataRegRequestRegistrant.php @@ -203,14 +203,6 @@ class GlmDataRegistrationsRequestRegistrant extends GlmDataAbstract 'use' => 'lgneud' ), - // Any MagicForm data associated with registrant - 'mf_data' => array ( - 'field' => 'mf_data', - 'type' => 'text', - 'required' => false, - 'use' => 'a' - ), - // System operator's notes for this registration request 'notes' => array ( 'field' => 'notes', diff --git a/classes/regCartSupport.php b/classes/regCartSupport.php index 7fe25f7..3546578 100644 --- a/classes/regCartSupport.php +++ b/classes/regCartSupport.php @@ -172,13 +172,18 @@ class GlmRegCartSupport // Validate request ID if (!$requestId || ($requestId-0) <= 0) { - return false; + return $this->cart; } // Try to get the base registration request data $this->cart['request'] = $RegRequest->getEntry($requestId); if (!$this->cart['request']) { - return false; + return $this->cart; + } + + // Check if the person looking at this cart is permitted to do so + if (!$this->checkRequestingAccount($requestId)) { + return $this->cart; } // Add submitting account if not guest submission (at this point) @@ -276,11 +281,15 @@ class GlmRegCartSupport public function checkRegistrationRequest($requestId = false, $json = false, $noReturn = false) { + $this->cart['blockCheckout'] = false; + // Try to get the cart data $this->getRegistrationCart($requestId, false, true); - if (!$this->cart) { - return false; + // If cart status is false, then we don't have a cart so return now + if (!$this->cart['status']) { + $this->cart['blockCheckout'] = true; + return $this->cart; } // First purge any expired pending registration holds @@ -302,8 +311,6 @@ class GlmRegCartSupport $totalDiscounts = 0; $grandTotal = 0; - $this->cart['blockCheckout'] = false; - // If we have a cart and a good request array if ($this->cart && is_array($this->cart['request'])) { @@ -560,6 +567,98 @@ class GlmRegCartSupport } + /* + * Update request to use another account + * + * @param integer $requestId + * @param integer $accountId + * + * @return boolean True is success otherwise false + * @access public + */ + public function replaceRequestingAccount($requestId = false, $accountId = false) + { + + // **** NEED TO COMPLETE THIS FUNCTION **** + + } + + /* + * Check if logged in user has permission to access cart + * + * Will also check for admin user and permit access even if it's not their cart + * + * If the cart does not have a submitting account (account = 0) then assign it to $accountId unless admin user + * + * @param integer $requestId + * + * @return boolean True if permitted otherwise false + * @access public + */ + public function checkRequestingAccount($requestId = false) + { + + // Do we have a valid request ID + if (!$requestId || ($requestId - 0) == 0) { + return false; + } + + // Try to get the base request information + $RegRequest = new GlmDataRegistrationsRegRequest($this->wpdb, $this->config); + $regRequest = $RegRequest->getEntry($requestId); + if (!$regRequest) { + return false; + } + + // If the user is an WordPress administrator or we have contacts add-on and WordPress user with adequate permissions + if (current_user_can('administrator') && apply_filters('glm_members_menu_members', true)) { + return true; + } + + // If there's no logged in registrations user + if (!isset($_SESSION) || !isset($_SESSION['LoginAccount']) || !is_array($_SESSION['LoginAccount'])) { + + // If it's a guest account and the request ID is in the current session - allow cart + if ($_SESSION['LoginAccount']['id'] == 0 && $_SESSION['glm_reg_cart_id'] == $requestId) { + return true; + } + + } + echo "
".print_r($_SESSION,1).print_r($regRequest,1)."
"; + // If there's a logged in registrations user + if (isset($_SESSION) && isset($_SESSION['LoginAccount']) && is_array($_SESSION['LoginAccount'])) { + + // If the registrations user owns the cart + if ($_SESSION['LoginAccount']['id'] == $regRequest['account']) { + return true; + } + + // If it's a guest cart and the cart ID matches glm_reg_cart_id in session - Was user's cart before logged in + if ($regRequest['id'] == $_SESSION['glm_reg_cart_id']) { + + // Assign this cart to the logged in user + $updated = $this->wpdb->update( + GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX.'reg_request', + array( + 'account' => $_SESSION['LogInAccount']['id'] + ), + array( 'id' => $requestId ), + array( + '%d' + ) + ); + + if ($updated) { + return true; + } + + } + } + + return false; + } + + /* * Add an account to the accounts list in the temoporary cart array if not already there * @@ -732,7 +831,7 @@ class GlmRegCartSupport 'attendees_pending' => $time['attendees_pending'], 'attendess_available' => $time['attendess_available'] ), - array( 'ID' => $timeId ), + array( 'id' => $timeId ), array( '%d', '%d', diff --git a/models/admin/registrations/events.php b/models/admin/registrations/events.php index aa4736e..ce7fd73 100644 --- a/models/admin/registrations/events.php +++ b/models/admin/registrations/events.php @@ -161,10 +161,6 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent // Get all current registration event data $regEvent = $this->getEventConfig($regEventID, false, false, true); -$re = $this->checkEventTimes(); -echo "
".print_r($re['firstTime']['start_time']['timestamp'],1)."
"; -$earliestDate = date('m/d/y', $re['firstTime']['start_time']['timestamp']); -echo "EarliestDate = $earliestDate

"; // Make all arrays of arrays non-associative to make Backbone happy if (is_array($regEvent['reg_class'])) { diff --git a/models/front/registrations/cart.php b/models/front/registrations/cart.php index 18e2a49..1ba6cd8 100644 --- a/models/front/registrations/cart.php +++ b/models/front/registrations/cart.php @@ -108,9 +108,6 @@ class GlmMembersFront_registrations_cart extends GlmRegCartSupport // If bad cart ID, set to false if ($cartId <= 0) { $cartId = false; - } else { - // If good dart ID save that in the session - $_SESSION['glm_reg_cart_id'] = $cartId; } } elseif (isset($_SESSION['glm_reg_cart_id'])) { @@ -120,21 +117,29 @@ class GlmMembersFront_registrations_cart extends GlmRegCartSupport } + // If we have a cart ID now if ($cartId) { - // Try to get a Validate cart with updated totals + // Try to get a Validated cart with updated totals $this->checkRegistrationRequest($cartId); - if ($this->cart) { + // If the cart checks out OK + if ($this->cart && $this->cart['status']) { + + // Mark it as good and stuff the cart ID in the current session $haveCart = true; + $_SESSION['glm_reg_cart_id'] = $cartId; + } } + $view = 'cart'; // Compile template data $templateData = array( + 'page' => 'cart', 'cartId' => $cartId, 'haveCart' => $haveCart, 'cart' => $this->cart, diff --git a/models/front/registrations/checkout.php b/models/front/registrations/checkout.php index 668ff83..6106b1d 100644 --- a/models/front/registrations/checkout.php +++ b/models/front/registrations/checkout.php @@ -113,6 +113,7 @@ class GlmMembersFront_registrations_checkout extends GlmRegCartSupport // Compile template data $templateData = array( + 'page' => 'checkout', 'cartId' => $cartId, 'haveCart' => $haveCart, 'cart' => $this->cart, diff --git a/models/front/registrations/checkoutProcess.php b/models/front/registrations/checkoutProcess.php index 2870d58..2e4905f 100644 --- a/models/front/registrations/checkoutProcess.php +++ b/models/front/registrations/checkoutProcess.php @@ -130,6 +130,7 @@ class GlmMembersAdmin_registrations_event extends GlmRegCartSupport // Compile template data $templateData = array( + 'page' => 'checkoutProcess' ); // Return status, any suggested view, and any data to controller diff --git a/models/front/registrations/list.php b/models/front/registrations/list.php index 19de3b2..93614f2 100644 --- a/models/front/registrations/list.php +++ b/models/front/registrations/list.php @@ -140,6 +140,7 @@ // Compile template data $templateData = array( + 'page' => 'register', //'events' => $eventData, 'regEventsCount' => $regEventsCount, 'haveRegEvents' => $haveRegEvents, diff --git a/models/front/registrations/register.php b/models/front/registrations/register.php index 909bcbb..f29eb4f 100644 --- a/models/front/registrations/register.php +++ b/models/front/registrations/register.php @@ -132,6 +132,7 @@ // Compile template data $templateData = array( + 'page' => 'register', 'reg' => $reg, 'emailError' => $emailError, 'regUrl' => GLM_MEMBERS_REGISTRATIONS_SITE_BASE_URL.$this->config['settings']['canonical_reg_page'].'/', diff --git a/models/front/registrations/registration.php b/models/front/registrations/registration.php index 5546a3d..994c2c0 100644 --- a/models/front/registrations/registration.php +++ b/models/front/registrations/registration.php @@ -154,7 +154,7 @@ $this->postProcAddedEventData = true; $regEvent = $this->getEventForRegistration($eventRegID); - // echo '

$regEvent: ' . print_r( $regEvent, true ) . '
'; + //echo '
$regEvent: ' . print_r( $regEvent, true ) . '
'; // Create an $event array with the event data. $event = array( @@ -314,6 +314,7 @@ // Compile template data $templateData = array( + 'page' => 'registration', 'haveCart' => $haveCart, 'isNewCart' => $isNewCart, 'regEvent' => $regEvent, diff --git a/models/front/registrations/summary.php b/models/front/registrations/summary.php index 006e168..aea9982 100644 --- a/models/front/registrations/summary.php +++ b/models/front/registrations/summary.php @@ -69,6 +69,7 @@ // Compile template data $templateData = array( + 'page' => 'summary' ); // Return status, any suggested view, and any data to controller diff --git a/setup/databaseScripts/create_database_V0.0.15.sql b/setup/databaseScripts/create_database_V0.0.15.sql index 2781513..867f2eb 100644 --- a/setup/databaseScripts/create_database_V0.0.15.sql +++ b/setup/databaseScripts/create_database_V0.0.15.sql @@ -14,17 +14,6 @@ * * misc - Misc settings and text - Site owner may update * - * Magic Forms Tables - * magicforms - Forms - * --> Event, Registration, Rate Class, Account, Registrant - * mf_data - Data submitted to a form - * --> Submission, Event Registration, Rate Class selected, Account, Registrant - * mf_temp_file - Temporary file meta-data - * - * added_info_fields - Additional fields - * added_info_data - Submitted additional field data - * --> added_info_fields - * * payment codes - Promotional payment codes - Used with various things * --> Event, Submission, Event Registration, Event Registrant, Account or global * @@ -43,6 +32,7 @@ * reg_request_rate - Specific registration date/rate (one or more) * reg_request_registrant - Registrant (one or more) * + * NOTE: additional fields and added fields data will be coming from the Custom Fields add-on * * Overall Flow * ------------ @@ -444,7 +434,7 @@ CREATE TABLE {prefix}reg_request_event ( reg_event INT NULL, -- Pointer to reg_event event_name TINYTEXT NULL, -- Name of Event so it will always be in the cart data event_datetime DATETIME NULL, -- Date and time of event time selected so it will always be in the cart - mf_data TEXT NULL, -- Any MagicForm data associated with requested event +-- mf_data TEXT NULL, -- Any MagicForm data associated with requested event notes TEXT NULL, -- System operator's notes for this registration request PRIMARY KEY (id), INDEX (reg_request), @@ -464,7 +454,7 @@ CREATE TABLE {prefix}reg_request_class ( reg_request_event INT NULL, -- Pointer to reg_request_event table entry class INT NULL, -- Pointer to event reg_class table - False (0) if registration class no longer exits class_name TINYTEXT NULL, -- Name of event class at the time selected - mf_data TEXT NULL, -- Any MagicForm data associated with registrant +-- mf_data TEXT NULL, -- Any MagicForm data associated with registrant notes TEXT NULL, -- System operator's notes for this registration request PRIMARY KEY (id), INDEX (reg_event), @@ -488,7 +478,7 @@ CREATE TABLE {prefix}reg_request_rate ( base_rate FLOAT, -- Base rate at time of registration per_registrant FLOAT, -- Per Registrant Rate at time of registration registrant_credits TINYINT NULL, -- Number of registrants included in base rate at time of registration - mf_data TEXT NULL, -- Any MagicForm data associated with registrant +-- mf_data TEXT NULL, -- Any MagicForm data associated with registrant notes TEXT NULL, -- System operator's notes for this registration request PRIMARY KEY (id), INDEX (reg_event), @@ -512,7 +502,7 @@ CREATE TABLE {prefix}reg_request_registrant ( reg_request_rate INT NULL, -- Pointer to reg_request_rate table entry fname TINYTEXT NULL, -- First name of registrant at the time of selection lname TINYTEXT NULL, -- Last name of registrant at the time of selection - mf_data TEXT NULL, -- Any MagicForm data associated with registrant +-- mf_data TEXT NULL, -- Any MagicForm data associated with registrant notes TEXT NULL, -- System operator's notes for this registration request PRIMARY KEY (id), INDEX (account), diff --git a/views/admin/registrations/eventEditLevels.html b/views/admin/registrations/eventEditLevels.html index 1264e03..1dc0e57 100644 --- a/views/admin/registrations/eventEditLevels.html +++ b/views/admin/registrations/eventEditLevels.html @@ -75,7 +75,7 @@

<%= name %>

- Start Days: <%= start_days %>, End Days: <%= end_days %>, Base: <%= base_rate %>. Per-Registrant: <%= per_registrant %>. Registrant Credits: <%= registrant_credits %> + Start Days: <%= start_days %>, End Days: <%= end_days %>, Base: $<%= base_rate %>. Per-Registrant: $<%= per_registrant %>. Registrant Credits: <%= registrant_credits %>
@@ -123,8 +123,8 @@ Cost: - Base - Per-Registrant + Base $ + Per-Registrant $ Registrant Credits
diff --git a/views/admin/registrations/requestsDashboard.html b/views/admin/registrations/requestsDashboard.html index d74eb93..98603c6 100644 --- a/views/admin/registrations/requestsDashboard.html +++ b/views/admin/registrations/requestsDashboard.html @@ -25,7 +25,7 @@ {if $haveRequests} {foreach $requests as $r} - {$r.id} + {$r.id}show {$r.bill_fname} {$r.bill_lname} {$r.bill_org} diff --git a/views/front/registrations/cart.html b/views/front/registrations/cart.html index 39aca46..65a7ac8 100644 --- a/views/front/registrations/cart.html +++ b/views/front/registrations/cart.html @@ -1,8 +1,9 @@ {include file='front/registrations/header.html'} -{if $haveCart} -

Selected Registrations

- +
+
Request ID: {$cartId}
+

Selected Registrations

+
@@ -17,10 +18,13 @@ + +{if $haveCart} + {foreach $cart.events as $event} - + {foreach $event.classes as $class} @@ -71,20 +75,23 @@ +{else} + +{/if}
Event: {$event.event_name}Event: {$event.event_name}
${$cart.totalCharges|number_format:2}
There was a problem locating the information for your request!
{if $cart.blockCheckout}
-
You have not yet submitted your registration. See above for issues!
+
You have not yet submitted your registration. See above notes!
{else}
- +
You have not yet submitted your registration! Complete Registration
{/if} -{else} - No cart data -{/if} + + + diff --git a/views/front/registrations/checkout.html b/views/front/registrations/checkout.html index 7ac5867..8a723d9 100644 --- a/views/front/registrations/checkout.html +++ b/views/front/registrations/checkout.html @@ -13,11 +13,12 @@ {if $cart.blockCheckout}
-
You have not yet submitted your registration. See above for issues!
+
You have not yet submitted your registration. See above for issues!
{else} -
-
You have one more step! Submit Registration
+
+ You have one more step to complete your registration! Submit Registration + or Return to Cart
{/if} diff --git a/views/front/registrations/header.html b/views/front/registrations/header.html index 06383fb..51a6120 100644 --- a/views/front/registrations/header.html +++ b/views/front/registrations/header.html @@ -1,4 +1,5 @@
+
{if $loggedIn} Logged in as {$loggedIn.fname} {$loggedIn.lname} Logout @@ -6,7 +7,9 @@ Login Register {/if} -
-
- Register for Another Event +
+ {if $page != 'register'} + Register for Another Event + {/if} +  
-- 2.17.1