Added function to check if the requesting account has permission to access the cart...
authorChuck Scott <cscott@gaslightmedia.com>
Thu, 19 Oct 2017 18:04:19 +0000 (14:04 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Thu, 19 Oct 2017 18:04:19 +0000 (14:04 -0400)
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.

19 files changed:
classes/data/dataRegRequestClass.php
classes/data/dataRegRequestEvent.php
classes/data/dataRegRequestRate.php
classes/data/dataRegRequestRegistrant.php
classes/regCartSupport.php
models/admin/registrations/events.php
models/front/registrations/cart.php
models/front/registrations/checkout.php
models/front/registrations/checkoutProcess.php
models/front/registrations/list.php
models/front/registrations/register.php
models/front/registrations/registration.php
models/front/registrations/summary.php
setup/databaseScripts/create_database_V0.0.15.sql
views/admin/registrations/eventEditLevels.html
views/admin/registrations/requestsDashboard.html
views/front/registrations/cart.html
views/front/registrations/checkout.html
views/front/registrations/header.html

index 85d1bcf..f93352b 100644 (file)
@@ -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',
index ecca510..d6e1774 100644 (file)
@@ -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'
-            ),
+            )
 
         );
 
index 3a2161d..3d4876e 100644 (file)
@@ -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',
index 1269ecf..0bd087d 100644 (file)
@@ -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',
index 7fe25f7..3546578 100644 (file)
@@ -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 "<pre>".print_r($_SESSION,1).print_r($regRequest,1)."</pre>";
+        // 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',
index aa4736e..ce7fd73 100644 (file)
@@ -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 "<pre>".print_r($re['firstTime']['start_time']['timestamp'],1)."</pre>";
-$earliestDate = date('m/d/y', $re['firstTime']['start_time']['timestamp']);
-echo "EarliestDate = $earliestDate<P>";
 
                 // Make all arrays of arrays non-associative to make Backbone happy
                 if (is_array($regEvent['reg_class'])) {
index 18e2a49..1ba6cd8 100644 (file)
@@ -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,
index 668ff83..6106b1d 100644 (file)
@@ -113,6 +113,7 @@ class GlmMembersFront_registrations_checkout extends GlmRegCartSupport
 
         // Compile template data
         $templateData = array(
+            'page'          => 'checkout',
             'cartId'        => $cartId,
             'haveCart'      => $haveCart,
             'cart'          => $this->cart,
index 2870d58..2e4905f 100644 (file)
@@ -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
index 19de3b2..93614f2 100644 (file)
 
         // Compile template data
         $templateData = array(
+            'page'              => 'register',
             //'events'            => $eventData,
             'regEventsCount'    => $regEventsCount,
             'haveRegEvents'     => $haveRegEvents,
index 909bcbb..f29eb4f 100644 (file)
 
         // Compile template data
         $templateData = array(
+            'page'       => 'register',
             'reg'        => $reg,
             'emailError' => $emailError,
             'regUrl'     => GLM_MEMBERS_REGISTRATIONS_SITE_BASE_URL.$this->config['settings']['canonical_reg_page'].'/',
index 5546a3d..994c2c0 100644 (file)
             $this->postProcAddedEventData = true;
             $regEvent = $this->getEventForRegistration($eventRegID);
 
-            // echo '<pre>$regEvent: ' . print_r( $regEvent, true ) . '</pre>';
+            //echo '<pre>$regEvent: ' . print_r( $regEvent, true ) . '</pre>';
 
             // Create an $event array with the event data.
             $event = array(
 
         // Compile template data
         $templateData = array(
+            'page'              => 'registration',
             'haveCart'          => $haveCart,
             'isNewCart'         => $isNewCart,
             'regEvent'          => $regEvent,
index 006e168..aea9982 100644 (file)
@@ -69,6 +69,7 @@
 
         // Compile template data
         $templateData = array(
+            'page' => 'summary'
 
         );
              // Return status, any suggested view, and any data to controller
index 2781513..867f2eb 100644 (file)
  *
  * 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),
index 1264e03..1dc0e57 100644 (file)
@@ -75,7 +75,7 @@
                     </div>
                     <div class="glm-rate-label" style="margin-bottom: .5em;">
                         <h3><%= name %></h3>
-                        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 %> 
                     </div>
                 </div>
             </div>
                             <tr>
                                 <th style="white-space: nowrap;">Cost:</th>
                                 <td>
-                                    <span class="glm-nowrap">Base <input class="rate-base-rate glm-form-text-input-veryshort" type="text" name="base_rate_<% if (id) { %><%- id %><% } else { %> new <% } %>" value="<% if (base_rate) { %><%- base_rate %><% } %>"></span>
-                                    <span class="glm-nowrap">Per-Registrant <input class="rate-per-registrant glm-form-text-input-veryshort" type="text" name="per_registrant_<% if (id) { %><%- id %><% } else { %> new <% } %>" value="<% if (per_registrant) { %><%- per_registrant %><% } %>"></span>
+                                    <span class="glm-nowrap">Base $<input class="rate-base-rate glm-form-text-input-veryshort" type="text" name="base_rate_<% if (id) { %><%- id %><% } else { %> new <% } %>" value="<% if (base_rate) { %><%- base_rate %><% } %>"></span>
+                                    <span class="glm-nowrap">Per-Registrant $<input class="rate-per-registrant glm-form-text-input-veryshort" type="text" name="per_registrant_<% if (id) { %><%- id %><% } else { %> new <% } %>" value="<% if (per_registrant) { %><%- per_registrant %><% } %>"></span>
                                     <span class="glm-nowrap">Registrant Credits <input class="rate-registrant-credits glm-form-text-input-veryshort" type="text" name="registrant_credits_<% if (id) { %><%- id %><% } else { %> new <% } %>" value="<% if (registrant_credits) { %><%- registrant_credits %><% } %>"></span>
                                     <br>
                                 </td>
index d74eb93..98603c6 100644 (file)
@@ -25,7 +25,7 @@
     {if $haveRequests}
         {foreach $requests as $r}
                 <tr>
-                    <td>{$r.id}</a></td>
+                    <td>{$r.id}<a href="">show</a></td>
                     <td><a href="{$thisUrl}?page=glm-members-admin-menu-registrations-requests&option=requestDashboard&requestID={$r.id}">{$r.bill_fname}</td>
                     <td><a href="{$thisUrl}?page=glm-members-admin-menu-registrations-requests&option=requestDashboard&requestID={$r.id}">{$r.bill_lname}</td>
                     <td><a href="{$thisUrl}?page=glm-members-admin-menu-registrations-requests&option=requestDashboard&requestID={$r.id}">{$r.bill_org}</td>
index 39aca46..65a7ac8 100644 (file)
@@ -1,8 +1,9 @@
 {include file='front/registrations/header.html'}
 
-{if $haveCart}
-    <h2>Selected Registrations</h2>
-    
+    <div>
+        <div class="glm-right" style="padding-top: 1.5em;" title="Please refer to this ID when requesting assistance.">Request ID: {$cartId}</div>
+        <h2 class="glm-left" style="clear: none;">Selected Registrations</h2>
+    </div>
     <table class="glm-admin-table" width="100%">
     
         <thead>
         
         
         </thead>
+
         <tbody>
+{if $haveCart}
+        
   {foreach $cart.events as $event}
             <tr>
-                <th colspan="5">Event: {$event.event_name}</th>
+                <th colspan="5"><a href="{$regUrl}?page=registration&eventRegId={$event.reg_event}"><span class="dashicons dashicons-edit"></span></a>Event: {$event.event_name}</th>
             </tr>        
     {foreach $event.classes as $class}
             <tr>
                 <td style="text-align: right;">${$cart.totalCharges|number_format:2}</td>
             </tfoot>
          
+{else}
+            <tr><td colspan="5" class="glm-reg-warning">There was a problem locating the information for your request!</td></tr> 
+{/if}
         </tbody>
  
     </table>
     
     {if $cart.blockCheckout}
     <div>
-        <div class="glm-reg-warning">You have not yet submitted your registration. See above for issues! <img src="{$assetUrl}/fingerUpRed.svg" width="50";"></div>
+        <div class="glm-reg-warning">You have not yet submitted your registration. See above notes! <img src="{$assetUrl}/fingerUpRed.svg" style="height: 2em;"></div>
     </div>
     {else}
     <div class="glm-right">
-        <div class="glm-reg-warning">You have not yet submitted your registration! <img src="{$assetUrl}/fingerRightRed.svg" width="50";"> <a href="{$regUrl}?page=checkout" class="button tiny">Complete Registration</a></div>
+        <div class="glm-reg-warning">You have not yet submitted your registration! <img src="{$assetUrl}/fingerRightRed.svg" style="height: 2em;"> <a href="{$regUrl}?page=checkout" class="button tiny">Complete Registration</a></div>
     </div>
     {/if}
     
-{else}
-            <tr class="alternate"><td colspan="2">No cart data</td></tr>
-{/if}
+
+
+
index 7ac5867..8a723d9 100644 (file)
     
     {if $cart.blockCheckout}
     <div>
-        <div class="glm-reg-warning">You have not yet submitted your registration. See above for issues! <img src="{$assetUrl}/fingerUpRed.svg" width="50";"></div>
+        <div class="glm-reg-warning">You have not yet submitted your registration. See above for issues! <img src="{$assetUrl}/fingerUpRed.svg" style="height: 2em;"></div>
     </div>
     {else}
-    <div class="glm-right">
-        <div class="glm-reg-warning">You have one more step! <img src="{$assetUrl}/fingerRightRed.svg" width="50";"> <a href="{$regUrl}?page=checkout" class="button tiny">Submit Registration</a></div>
+    <div class="glm-right" style="white-space; nowrap;">
+        <span class="glm-reg-warning">You have one more step to complete your registration!</span> <img src="{$assetUrl}/fingerRightRed.svg" style="height: 2em;"> <a href="{$regUrl}?page=checkout" class="button tiny">Submit Registration</a>
+        or <a href="{$regUrl}?page=cart" class="button tiny">Return to Cart</a>
     </div>
     {/if}
     
index 06383fb..51a6120 100644 (file)
@@ -1,4 +1,5 @@
 <div id="accountHeader">
+    <div class="glm-right">
     {if $loggedIn}
         Logged in as {$loggedIn.fname} {$loggedIn.lname}
         <a class="button tiny" href="{$regUrl}?page=login&option=logout">Logout</a>
@@ -6,7 +7,9 @@
         <a id="appLogin" class="button tiny" href="{$regUrl}?page=login">Login</a>
         <a id="register" class="button tiny" href="{$regUrl}?page=register">Register</a>
     {/if}
-</div>
-<div>
-    <a href="{$regUrl}" class="button tiny">Register for Another Event</a>
+    </div>
+    {if $page != 'register'}
+        <a href="{$regUrl}" class="button tiny">Register for Another Event</a>
+    {/if}
+    &nbsp;
 </div>