Added Custom Fields support for admin events.
authorChuck Scott <cscott@gaslightmedia.com>
Mon, 11 Dec 2017 14:27:10 +0000 (09:27 -0500)
committerChuck Scott <cscott@gaslightmedia.com>
Mon, 11 Dec 2017 14:27:10 +0000 (09:27 -0500)
models/admin/registrations/events.php
models/front/registrations/checkout.php
models/front/registrations/checkoutProcess.php
views/admin/registrations/eventDashboard.html
views/admin/registrations/eventEdit.html
views/admin/registrations/eventEditCustomFields.html [new file with mode: 0644]
views/admin/registrations/eventEditLevels.html
views/front/registrations/checkout.html

index d9f3909..bb571aa 100644 (file)
@@ -156,6 +156,18 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent
 
         switch ($option) {
 
+            case 'eventCustomFields':
+
+                require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegClass.php';
+                $RegClasses = new GlmDataRegistrationsRegClass($this->wpdb, $this->config);
+                $classes = $RegClasses->getList("T.reg_event = $regEventID");
+
+                $regEvent = $this->getEntry($regEventID);
+
+                $view = 'eventEditCustomFields';
+
+                break;
+
             case 'configureEvent':
 
                 $scripts = array(
@@ -543,7 +555,7 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent
             'regEventJSON'            => $regEventJSON,
             'regClassesJSON'          => $regClassesJSON,
             'regTimesJSON'            => $regTimesJSON,
-            'eventCustomFieldsUid'    => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG.'-customfields-reg-event-edit-'.$regEventID
+            'classes'                 => $classes
         );
 
         // echo "<pre>".print_r($templateData,1)."</pre>";
index 5fc0e37..d3049c2 100644 (file)
@@ -292,7 +292,7 @@ class GlmMembersFront_registrations_checkout extends GlmRegCartSupport
             'misc'          => $misc,
             'checkoutPageText'  => $misc['checkout_page_text'],
             'globalTerms'   => $misc['reg_terms'],
-            'eventCustomFieldsUid'    => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG.'-customfields-reg-event-edit-'
+            'eventCustomFieldsFidPrefix'    => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG.'-customfields-reg-event-'
         );
 
         // echo "<pre>".print_r($templateData,1)."</pre>";
index 84e7b5f..17ecfda 100644 (file)
@@ -217,6 +217,43 @@ class GlmMembersFront_registrations_checkoutProcess extends GlmRegCartSupport
 
         }
 
+        /*
+         * Custom Fields
+         */
+
+        // Process and store any custom fields for events
+        if (apply_filters('glm-members-customfields-active', false)) {
+
+            // For each event, see if there's any custom fields
+            foreach ($this->cart['events'] as $eventKey=>$eventData) {
+
+                $formResult = false;
+
+                // Build form ID for the custom form that's requested once at checkout for this event
+                $fid = 'glm_reg_customfields_reg_event_'.$eventData['reg_event'];
+
+                // If there's any form fields (if not - assume no form)
+                if (apply_filters('glm-members-customfields-have-fields', false, $fid)) {
+
+                    // Attempt to process the custom form fields and ask for the data to be stored - use reg_request_event id for record #
+                    $formResult = apply_filters('glm-members-customfields-form-submit', false, $fid, $eventData['id'], true );
+
+                }
+
+echo "Form Result: <pre>".print_r($formResult,1)."</pre>";
+
+                // Save the results in the cart event data
+                $this->cart['events'][$eventKey]['customForm'] = $formResult;
+
+            }
+        }
+
+echo "<pre>".print_r($this->cart['events'],1)."</pre>";
+
+
+wp_die("KILLING WORDPRESS FOR TESTING IN checkoutProcess.php");
+
+
         /*
          * Policies accepted?
          */
@@ -578,6 +615,8 @@ class GlmMembersFront_registrations_checkoutProcess extends GlmRegCartSupport
         $request = $Request->getEntry($this->cart['request']['id']);
         $account = $Account->getEntry($request['account']);
 
+
+
         if (count($messages) == 0) {
 
             // Produce HTML for storage and checkout page and add to request
index 4eb4518..c871cec 100644 (file)
@@ -6,6 +6,9 @@
         <a onClick="return false;" class="nav-tab nav-tab-active">Event Dashboard</a>
         <a href="{$thisUrl}?page=glm-members-admin-menu-registrations-events&option=edit&regEventID={$regEventID}" class="nav-tab">Edit Registration Settings</a>
         <a href="{$thisUrl}?page=glm-members-admin-menu-registrations-events&option=configureEvent&regEventID={$regEventID}" class="nav-tab">Registration Levels & Charges</a> 
+{if apply_filters('glm-members-customfields-active', false)}        
+        <a href="{$thisUrl}?page=glm-members-admin-menu-registrations-events&option=eventCustomFields&regEventID={$regEventID}" class="nav-tab">Additional Fields</a>
+{/if}
     </h2>
 
 {if $haveMessages}
index 1fd83cc..542f25e 100644 (file)
@@ -1,7 +1,7 @@
 {include file='admin/registrations/eventHeader.html'}
     
        <h1>
-               Registrations Event Edit
+               {$regEvent.fieldData.event_name}
                &nbsp;&nbsp;&nbsp;
         {if $regEventUpdated}<span class="glm-notice glm-flash-updated">Registration Event Updated</span>{/if}
         {if $regEventUpdateError}<span class="glm-error glm-flash-updated">Registration Event Update Error</span>{/if}
@@ -25,6 +25,9 @@
         <a href="{$thisUrl}?page=glm-members-admin-menu-registrations-events&option=eventDashboard" class="nav-tab">Event Dashboard</a>
         <a onClick="return false;" class="nav-tab nav-tab-active">Edit Registration Settings</a>
         <a href="{$thisUrl}?page=glm-members-admin-menu-registrations-events&option=configureEvent&regEventID={$regEventID}" class="nav-tab">Registration Levels & Charges</a>
+{if apply_filters('glm-members-customfields-active', false)}        
+        <a href="{$thisUrl}?page=glm-members-admin-menu-registrations-events&option=eventCustomFields&regEventID={$regEventID}" class="nav-tab">Additional Fields</a>
+{/if}
     </h2>
 
 
                 {/if}<br>
                 </td>
             </tr>
-    {if apply_filters('glm-members-customfields-active', false)}
-            <tr>
-                <th>Custom Fields</th>
-                <td>
-                    <p>These are additional fields of information that will be requested for each registrant.</p> 
-                    {apply_filters('glm-members-customfields-edit', '', $eventCustomFieldsUid)}
-                </td>
-            </tr>
-    {/if}
         </table>
         
         
diff --git a/views/admin/registrations/eventEditCustomFields.html b/views/admin/registrations/eventEditCustomFields.html
new file mode 100644 (file)
index 0000000..f5e343a
--- /dev/null
@@ -0,0 +1,74 @@
+{include file='admin/registrations/eventHeader.html'}
+
+    <h1>
+        {$regEvent.event_name}
+
+        &nbsp;&nbsp;&nbsp;
+        {if $regEventUpdated}<span class="glm-notice glm-flash-updated">Registration Event Updated</span>{/if}
+        {if $regEventUpdateError}<span class="glm-error glm-flash-updated">Registration Event Update Error</span>{/if}
+        {if $regEventAdded}<span class="glm-notice glm-flash-updated">Registration Event Added</span>{/if}
+
+    </h1>
+
+<div class="glm-admin-table-inner glm-admin-table">
+
+{if $haveMessages}
+    <div class="glm-error" style="font-size: 1rem; line-height: 1rem; margin-top: 1rem;">
+        <i>Please Note:</i>
+        <UL>
+  {foreach $messages as $m}
+            <li>{$m}</li>
+  {/foreach}          
+        </UL>
+    </div>
+{/if}
+
+    <h2 class="nav-tab-wrapper" style="margin-bottom: 1em;">
+        <a href="{$thisUrl}?page=glm-members-admin-menu-registrations-events&option=eventDashboard" class="nav-tab">Event Dashboard</a>
+        <a href="{$thisUrl}?page=glm-members-admin-menu-registrations-events&option=edit&regEventID={$regEventID}" class="nav-tab">Edit Registration Settings</a>
+        <a href="{$thisUrl}?page=glm-members-admin-menu-registrations-events&option=configureEvent&regEventID={$regEventID}" class="nav-tab">Registration Levels & Charges</a> 
+        <a onClick="return false;" class="nav-tab nav-tab-active">Additional Fields</a> 
+         
+    </h2>
+    
+    
+{if apply_filters('glm-members-customfields-active', false)}
+    <p><hr></p>
+
+    {* Per Event Form for this event *}
+    <h3>Per submission including this event</h3>
+    <p>These are additional fields of information that will be requested for this event in each submission.</p>
+    <p>
+        {assign var="eventFid" value="glm_reg_customfields_reg_event_`$regEventID`"}
+        {apply_filters('glm-members-customfields-edit', '', $eventFid)}
+    </p>
+
+    {* Per Attendee Form for this event *}
+    <p><hr></p>
+    <h3>Each attendee for this event</h3>
+    <p>These are additional fields of information that will be requested for each registrant for this event.</p>
+    <p> 
+        {assign var="attendeeFid" value="glm_reg_customfields_reg_attendee_`$regEventID`"}
+        {apply_filters('glm-members-customfields-edit', '', $attendeeFid)}
+    </p>
+
+    {* Per Attendee form for each class (level) for this event *}
+    <p><hr></p>
+  {foreach $classes as $class}
+    <h3>Each attendee for level: {$class.name}</h3>
+    <p>These are additional fields of information that will be requested for each registrant for this event.</p>
+    <p> 
+        {assign var="levelFid" value="glm_reg_customfields_reg_event_`$regEventID`_level_`$class.id`"}
+        {apply_filters('glm-members-customfields-edit', '', $levelFid)}
+    </p>
+    <p><hr></p>
+  {/foreach}
+
+{/if}
+   
+    
+    
+</div>
+
+{include file='admin/footer.html'}
+
index 124009d..de6f2e1 100644 (file)
@@ -1,7 +1,7 @@
 {include file='admin/registrations/eventHeader.html'}
 
     <h1>
-        Registrations Event Edit
+        {$regEvent.event_name}
 
         &nbsp;&nbsp;&nbsp;
         {if $regEventUpdated}<span class="glm-notice glm-flash-updated">Registration Event Updated</span>{/if}
@@ -27,6 +27,9 @@
         <a href="{$thisUrl}?page=glm-members-admin-menu-registrations-events&option=eventDashboard" class="nav-tab">Event Dashboard</a>
         <a href="{$thisUrl}?page=glm-members-admin-menu-registrations-events&option=edit&regEventID={$regEventID}" class="nav-tab">Edit Registration Settings</a>
         <a onClick="return false;" class="nav-tab nav-tab-active">Registration Levels & Charges</a> 
+{if apply_filters('glm-members-customfields-active', false)}        
+        <a href="{$thisUrl}?page=glm-members-admin-menu-registrations-events&option=eventCustomFields&regEventID={$regEventID}" class="nav-tab">Additional Fields</a>
+{/if}
     </h2>
     
     {* Event Registration App - Backbone.js *}
index 25a7727..6236262 100644 (file)
@@ -1,9 +1,9 @@
 {include file='front/registrations/header.html'}
 
 {if $checkoutPageText}
-<div>
-    {$checkoutPageText}
-</div>
+    <div>
+        {$checkoutPageText}
+    </div>
 {/if}
 
 {if $haveMessages}
   {/if} {* / total charges > 0 *}
             </div>
     {if apply_filters('glm-members-customfields-active', false)}
-            <div class="glm-reg-row">
-                <div class="glm-small-12 glm-columns">
-                    <h4>Additional information we need to collect</h4>
       {foreach $cart.events as $event}
+        {assign var="fid" value="glm_reg_customfields_reg_event_`$event.reg_event`"} {* assemble the uid with the current event ID *}      
+        {if apply_filters('glm-members-customfields-have-fields', false, $fid)}
+            <div class="glm-reg-row">
+                <div class="glm-large-6 glm-small-12 glm-columns">
+                    <h4>Additional information for event: {$event.event_name}</h4>
                     <div class="glm-reg-row">
                         <div class="glm-large-12 glm-columns glm-reg-nowrap">
-                            <h5>{$event.event_name}:</h5>
-                             {apply_filters('glm-members-customfields-form-display', $eventCustomFieldsUid.{$event.id}, {$cart.id}, false)}
-                             
-                             GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG.'-customfields-reg-event-edit-'.$regEventID
-                             
+                {apply_filters('glm-members-customfields-form-display', '', $fid, $cartId, 'checkoutForm', false)}
                         </div>
                     </div>
-      {/foreach}
                 </div>
             </div>
+        {/if}
+      {/foreach}
     {/if}
             <div class="glm-reg-row">
                 <div class="glm-small-12 glm-columns">
                 <span class="glm-reg-warning">You have one more step to complete your registration!</span> <img src="{$assetUrl}/fingerRightRed.svg" style="height: 2em;"> <input id="regSubmitButton" type="submit" value="Submit Registration Request" class="button tiny">
             </div>
 
-
-        </form>
-
-        <div id="regSubmitDialog" title="Please wait...">Please wait while we process your registration request. If you don't see a new page, your registration request may not have been processed.</div>
-        <div id="regSubmitFailDialog" title="Oops!">
-            <h3>Something may have gone wrong.</h3>
-            <p>
-                It may be that your registration request was received and processed and you didn't receive our response yet.
-                If you still don't see a response in a while, try returning to the cart using the button above.
-                If still don't see any response, please check your E-Mail to see if you have been sent a confirmation.
-            </p>
-            <p>
-                In any case, we will never process your request more than once. If you can return to the cart, it should say if
-                your request was recieved and processed. If not, you may try the checkout process again or come back later.
-            </p>
         </div>
 
-        <h4 id="cart-summary">Registration Summary</h4>
-        <table class="glm-admin-table" width="100%">
+    </form>
+
+    <div id="regSubmitDialog" title="Please wait...">Please wait while we process your registration request. If you don't see a new page, your registration request may not have been processed.</div>
+    <div id="regSubmitFailDialog" title="Oops!">
+        <h3>Something may have gone wrong.</h3>
+        <p>
+            It may be that your registration request was received and processed and you didn't receive our response yet.
+            If you still don't see a response in a while, try returning to the cart using the button above.
+            If still don't see any response, please check your E-Mail to see if you have been sent a confirmation.
+        </p>
+        <p>
+            In any case, we will never process your request more than once. If you can return to the cart, it should say if
+            your request was recieved and processed. If not, you may try the checkout process again or come back later.
+        </p>
+    </div>
+
+    <h4 id="cart-summary">Registration Summary</h4>
+    <table class="glm-admin-table" width="100%">
 
-            <thead>
+        <thead>
 
-                <tr>
-                    <th>Registering</th>
-                    <th>Registrant</th>
-                    <th>Date/Time</th>
-                    <th>Discount</th>
-                    <th>Rate</th>
-                </tr>
+            <tr>
+                <th>Registering</th>
+                <th>Registrant</th>
+                <th>Date/Time</th>
+                <th>Discount</th>
+                <th>Rate</th>
+            </tr>
 
 
-            </thead>
+        </thead>
             <tbody>
   {foreach $cart.events as $event}
-                <tr>
-                    <th colspan="5">Event: {$event.event_name}</th>
-                </tr>
+            <tr>
+                <th colspan="5">Event: {$event.event_name}</th>
+            </tr>
     {foreach $event.classes as $class}
-                <tr>
-                    <td colspan="5">&nbsp;&nbsp;&nbsp;&nbsp;{$class.class_name}</td>
-                </tr>
+            <tr>
+                <td colspan="5">&nbsp;&nbsp;&nbsp;&nbsp;{$class.class_name}</td>
+            </tr>
       {foreach $class.rates as $rate}
         {if $rate.rateBaseCharge || $rate.registrant_credits}
-                <tr>
-                    <td colspan="4">
-                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$rate.rate_name}
-                        - Base Rate ({$rate.registrant_credits} registrants included)
-                    </td>
-                    <td style="text-align: right;">
-                        {if $rate.rateBaseCharge}{$rate.rateBaseCharge|number_format:2}{/if}
-                    </td>
-                </tr>
+            <tr>
+                <td colspan="4">
+                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$rate.rate_name}
+                    - Base Rate ({$rate.registrant_credits} registrants included)
+                </td>
+                <td style="text-align: right;">
+                    {if $rate.rateBaseCharge}{$rate.rateBaseCharge|number_format:2}{/if}
+                </td>
+            </tr>
         {/if}
         {foreach $rate.registrants as $registrant}
-                <tr>
-                    <td>&nbsp;</td>
-                    <td>{$registrant.fname} {$registrant.lname}</td>
-                    <td>{$registrant.timeReformatted}</td>
-                    <td style="text-align: right;">
-                        {if $registrant.registrantDiscounts > 0}
-                            {$registrant.registrantDiscounts|number_format:2}
-                        {else}
-                            &nbsp;
-                        {/if}
-                    </td>
-                    <td style="text-align: right;">
-                        {if $registrant.registrantRate > 0}
-                            {$registrant.registrantRate|number_format:2}
-                        {else}
-                            (included)
-                        {/if}
-                    </td>
-                </tr>
+            <tr>
+                <td>&nbsp;</td>
+                <td>{$registrant.fname} {$registrant.lname}</td>
+                <td>{$registrant.timeReformatted}</td>
+                <td style="text-align: right;">
+                    {if $registrant.registrantDiscounts > 0}
+                        {$registrant.registrantDiscounts|number_format:2}
+                    {else}
+                        &nbsp;
+                    {/if}
+                </td>
+                <td style="text-align: right;">
+                    {if $registrant.registrantRate > 0}
+                        {$registrant.registrantRate|number_format:2}
+                    {else}
+                        (included)
+                    {/if}
+                </td>
+            </tr>
           {assign var="acct" value=$cart.accounts.{$registrant.account}}
           {if $acct.validated.value}
-                <tr>
-                    <td colspan="2">&nbsp;</td>
-                    <td colspan="3">
-                      {if $acct.email != ''}E-Mail: {$acct.email}<br>{/if}
-                      (Account information is restricted)
-                    </td>
-                </tr>
+            <tr>
+                <td colspan="2">&nbsp;</td>
+                <td colspan="3">
+                  {if $acct.email != ''}E-Mail: {$acct.email}<br>{/if}
+                  (Account information is restricted)
+                </td>
+            </tr>
           {else}
             {if $acct.addr1 != '' || $acct.phone != '' || $acct.email != ''}
-                <tr>
-                    <td colspan="2">&nbsp;</td>
-                    <td colspan="3">
-                      {if $acct.org != ''}          {$acct.title}, {$acct.org}<br>                      {/if}
-                      {if $acct.addr1 != ''}        {$acct.addr1}<br>                                   {/if}
-                      {if $acct.addr2 != ''}        {$acct.addr2}<br>                                   {/if}
-                      {if $acct.city != ''}         {$acct.city}, {$acct.state.value} {$acct.zip}<br>   {/if}
-                      {if $acct.country.name != ''} {$acct.country.name}<br>                            {/if}
-                      {if $acct.phone != ''}        Phone: {$acct.phone}<br>                            {/if}
-                      {if $acct.fax != ''}          Fax: {$acct.fax}<br>                                {/if}
-                      {if $acct.email != ''}        E-Mail: {$acct.email}                               {/if}
-                    </td>
-                </tr>
+            <tr>
+                <td colspan="2">&nbsp;</td>
+                <td colspan="3">
+                  {if $acct.org != ''}          {$acct.title}, {$acct.org}<br>                      {/if}
+                  {if $acct.addr1 != ''}        {$acct.addr1}<br>                                   {/if}
+                  {if $acct.addr2 != ''}        {$acct.addr2}<br>                                   {/if}
+                  {if $acct.city != ''}         {$acct.city}, {$acct.state.value} {$acct.zip}<br>   {/if}
+                  {if $acct.country.name != ''} {$acct.country.name}<br>                            {/if}
+                  {if $acct.phone != ''}        Phone: {$acct.phone}<br>                            {/if}
+                  {if $acct.fax != ''}          Fax: {$acct.fax}<br>                                {/if}
+                  {if $acct.email != ''}        E-Mail: {$acct.email}                               {/if}
+                </td>
+            </tr>
             {/if}
           {/if}
         {/foreach}
       {/foreach}
     {/foreach}
   {/foreach}
-            </tbody>
-            <tfoot>
-                <td colspan="2">&nbsp;</td>
-                <td>Total registrants: {$cart.totalRegistrants}</td>
-                <td style="text-align: right;">
-                    {if $cart.totalDiscounts > 0}
-                        ${$cart.totalDiscounts|number_format:2}
-                    {else}
-                        &nbsp;
-                    {/if}
-                </td>
-                <td style="text-align: right;">${$cart.totalCharges|number_format:2}</td>
-            </tfoot>
+        </tbody>
+        <tfoot>
+            <td colspan="2">&nbsp;</td>
+            <td>Total registrants: {$cart.totalRegistrants}</td>
+            <td style="text-align: right;">
+                {if $cart.totalDiscounts > 0}
+                    ${$cart.totalDiscounts|number_format:2}
+                {else}
+                    &nbsp;
+                {/if}
+            </td>
+            <td style="text-align: right;">${$cart.totalCharges|number_format:2}</td>
+        </tfoot>
 {/if} {* / if have cart *}
-        </table>
-
-
-    </div>
-</div>
+    </table>
 
 <script type="text/javascript">
     jQuery(function($){
         });
 
         // Dissable checkout button when first clicked to prevent multiple attempts
-        $("#checkoutForm").submit(function(){
+        $("#checkoutForm").submit(function(e){
 
+            // If something else is preventing submission, stop here. Use this with custom fields when there are required fields.
+            if (e.isDefautPrevented()) {
+                return false;
+            }
+            
             // Show submit dialog box
             $( "#regSubmitDialog" ).dialog( "open" );