Fixed problems with time editing in admin reg event dashboard and added testing for...
authorChuck Scott <cscott@gaslightmedia.com>
Thu, 14 Dec 2017 20:20:21 +0000 (15:20 -0500)
committerChuck Scott <cscott@gaslightmedia.com>
Thu, 14 Dec 2017 20:20:21 +0000 (15:20 -0500)
classes/data/dataRegEvent.php
classes/regCartSupport.php
models/admin/ajax/updateAvailability.php
models/admin/registrations/events.php
models/front/registrations/registration.php
views/admin/registrations/eventDashboard.html

index 8ad92ef..35c6039 100644 (file)
@@ -653,10 +653,11 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract
      * @param boolean $forEdit          Ask for results to include arrays necessary for construction of input fields
      * @param boolean $withRecurData    Ask for all recirrences and recurrence times for event if true
      * @param boolean $counts           Ask for attendee counts
+     * @param boolean $inactiveTimes    Include inactive times
      *
      * @return array All data related to the setup/configuration of a registration event
      */
-    public function getEventConfig($id = false, $extended = false, $forEdit = false, $withRecurData = false, $counts = false)
+    public function getEventConfig($id = false, $extended = false, $forEdit = false, $withRecurData = false, $counts = false, $inactiveTimes = false)
     {
 
         // Save status of extended data flag
@@ -685,8 +686,12 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract
         require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegTime.php';
         $RegTime = new GlmDataRegistrationsRegTime($this->wpdb, $this->config);
 
+        $where = 'T.reg_event = '.$this->regEventData['id'];
+        if (!$inactiveTimes) {
+            $where .= ' AND T.active';
+        }
         // Get all active reg_time entries for this event
-        $this->regEventData['reg_time'] = $RegTime->getList('T.reg_event = '.$this->regEventData['id'].' AND T.active', 'start_datetime', true);
+        $this->regEventData['reg_time'] = $RegTime->getList($where, 'start_datetime', true);
 
         // Get all reg_class records for this event
         require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegClass.php';
index 56e4af0..be8a4f0 100644 (file)
@@ -454,8 +454,8 @@ class GlmRegCartSupport
 
                                                 $this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['registrants'][$registrantKey]['removed'] = false;
 
-                                                // Check if the time selected for this registrant still exists in the event
-                                                if (!isset($regEventTimes[$registrant['reg_time']])) {
+                                                // Check if the time selected for this registrant doesn't exist or is inactive
+                                                if (!isset($regEventTimes[$registrant['reg_time']]) || !$regEventTimes[$registrant['reg_time']]['active']) {
                                                     $this->cart['messages'][] = "The event date and/or time selected for ".$registrant['fname'].' '.$registrant['fname']." has been dropped from the event. Registrant was removed.";
                                                     $removeRegistrant = true;
                                                 }
index fb0748e..037aae4 100644 (file)
             $active = true;
         }
 
+        // This is
+        $allDay = false;
+        if (isset($_REQUEST['allDay']) && $_REQUEST['allDay'] == 'true') {
+            $allDay = true;
+        }
+
+        // Active
+        $active = false;
+        if (isset($_REQUEST['active']) && $_REQUEST['active'] == 'true') {
+            $active = true;
+        }
+
         // Get the max attendees value
         if (!isset($_REQUEST['max'])) {
             wp_die();
             wp_die();
         }
 
+        // Get start and end times if available. If start and no end, use start for end
+        $startTime = filter_input(INPUT_POST, 'start', FILTER_SANITIZE_STRING);
+        $startTime = date('Y-m-d H:i:s', strtotime($startTime));
+        $endTime = filter_input(INPUT_POST, 'end', FILTER_SANITIZE_STRING);
+        $endTime = date('Y-m-d H:i:s', strtotime($endTime));
+
         // Get the reg_time entry id
         if ($newTime) {
 
-            $active = false;
-            if (isset($_REQUEST['active']) && $_REQUEST['active'] == 'true') {
-                $active = true;
-            }
-            // This is a new entry
-            $allDay = false;
-            if (isset($_REQUEST['allDay']) && $_REQUEST['allDay'] == 'true') {
-                $allDay = true;
-            }
-
             // Track Attendees flag
             $attendees = false;
             if (isset($_REQUEST['attendees']) && $_REQUEST['attendees'] == 'true') {
                 $regEventId = ($_REQUEST['event'] - 0);
             }
 
-            // Get start and end times if available. If start and no end, use start for end
-            $startTime = filter_input(INPUT_POST, 'start', FILTER_SANITIZE_STRING);
-            if ($allDay || $startTime === null) {
-                $startTime = false;
-            } else {
-                $startTime = date('Y-m-d H:i:s', strtotime($startTime));
-            }
-            $endTime = filter_input(INPUT_POST, 'end', FILTER_SANITIZE_STRING);
-            if ($allDay || $startTime === false || $endTime === null) {
-                $endTime = false;
-                if ($startTime) {
-                    $endTime = $startTime;
-                }
-            } else {
-                $endTime = date('Y-m-d H:i:s', strtotime($endTime));
-            }
-
             // If we have at least a reg_event ID start time, then try to add the reg_time
             if ($regEventId && $startTime) {
 
             echo "0";
             wp_die();
 
+
+        // Otherwise this should be an update
         } else {
 
+            // Get the tiem entry ID
             if (!isset($_REQUEST['reg_time'])) {
                 wp_die();
             }
 
         // re-calculate the total
         $avail = $max - $regTime['attendee_count'] - $regTime['attendees_pending'];
+trigger_error('start = '.$startTime,E_USER_NOTICE);
+trigger_error('end = '.$endTime,E_USER_NOTICE);
+trigger_error(print_r($_REQUEST,1),E_USER_NOTICE);
+
         // Try to update the reg_time entry
         $this->wpdb->update(
             $this->table,
             array(
                 'active'                => $active,
+                'all_day'               => $allDay,
+                'start_datetime'        => $startTime,
+                'end_datetime'          => $endTime,
                 'attendee_max'          => $max,
                 'attendees_available'   => $avail
             ),
             array(
                 '%d',
                 '%d',
+                '%s',
+                '%s',
+                '%d',
                 '%d'
             ),
             array( '%d' )
index 9257895..eec5a41 100644 (file)
@@ -391,7 +391,7 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent
 
             case 'eventDashboard':
 
-                $regEvent = $this->getEventConfig($regEventID, true, false, true);
+                $regEvent = $this->getEventConfig($regEventID, true, false, true, false, true);
 
                 // Check if there's a request to add event times from the event
                 if (isset($_REQUEST) && isset($_REQUEST['getTimesFromEvent']) && $_REQUEST['getTimesFromEvent'] == 'yes') {
index fcf1db8..7dd2a36 100644 (file)
 
             // If it's a positive integer, try to get the cart
             if ($cartId > 0) {
-                $cart = $RegCart->getRegistrationCart( $cartId );
+                $cart = $RegCart->checkRegistrationRequest( $cartId );
                 if ($cart !== false && is_array($cart)) {
                     $haveCart = true;
                 }
             if ($cartId) {
 
                 // Try to get the new cart
-                $cart = $RegCart->getRegistrationCart( $cartId );
+                $cart = $RegCart->checkRegistrationRequest( $cartId );
                 if ($cart !== false && is_array($cart)) {
                     $haveCart  = true;
                     $isNewCart = true;
index 2f7440e..788331c 100644 (file)
         <tr id="dialogStartTimeLine"><th style="text-align: left" class="glm-required">Start Time:</th><td><input id="dialogStartTime" class="glm-form-text-input-short time-input not-all-day" type="text" value=""></td></tr>
         <tr id="dialogEndTimeLine"><th style="text-align: left" class="glm-required">End Time:</th><td><input id="dialogEndTime" class="glm-form-text-input-short time-input not-all-day" type="text" value=""></td></tr>
   {if $regEvent.time_specific.value}        
-        <tr><th style="text-align: left">Maximum Attendees:</th><td><input class="glm-form-text-input-veryshort availabilityInput" type="text" id="dialogMaxAtt" value=""> 0 = Unlimited</td></tr>
+        <tr><th style="text-align: left" class="glm-required">Maximum Attendees:</th><td><input class="glm-form-text-input-veryshort availabilityInput" type="text" id="dialogMaxAtt" value=""> 0 = Unlimited</td></tr>
         <tr id="dialogRegLine"><th style="text-align: left">Registered Attendees:</th><td id="dialogRegAtt"></td></tr>
         <tr id="dialogPendLine"><th style="text-align: left">Pending in Carts:</th><td id="dialogPendAtt"></td></tr>
         <tr id="dialogAvailLine"><th style="text-align: left">Available for Registration:</th><td id="dialogAvailAtt"></td></tr>
                           {else}
                             backgroundColor:    '#aaa',
                           {/if}
-                            allday:             {$t.all_day.value},
+                            allday:             {if $t.all_day.value}true{else}false{/if},
                             attendees:          {if $t.attendees.value}true{else}false{/if},
                             max:                {$t.attendee_max},
                             count:              {$t.attendee_count},
                     defaultDate : '{$defaultCalDate}',
                     timeFormat  : 'h:mma',
                     fixedWeekCount : false,
+
+                    // Click on an event in the calendar
                     eventClick: function(calEvent, jsEvent, view) {
 
                         $('#dialogAvailSubmit').off('click');  
                         
                         $('#availabilityTitle').html(calEvent.datetime);
                         $('#dialogRegActive').prop('checked', calEvent.active);
-                        $('#dialogStartTime').val(calEvent.start.format('hh:mm A'));
-                        $('#dialogEndTime').val(calEvent.end.format('hh:mm A'));
-                        $('#dialogTimeAllDay').prop('checked', calEvent.allDay);
+                        if(calEvent.start) {
+                            $('#dialogStartTime').val(calEvent.start.format('hh:mm A'));
+                        }
+                        if (calEvent.end) {
+                            $('#dialogEndTime').val(calEvent.end.format('hh:mm A'));
+                        }
+
+                        $('#dialogTimeAllDay').prop('checked', calEvent.allday);
                         $('#dialogMaxAtt').val(calEvent.max);
                         $('#dialogRegLine').show();
                         $('#dialogRegAtt').html(calEvent.count);
                             } else {
                                 calEvent.backgroundColor = '#aaa';
                             }
+                            var allDay = $('#dialogTimeAllDay').is(":checked");
+                            calEvent.allday = allDay;
+                            var start = calEvent.start.format('YYYY/MM/DD') + ' ' + $('#dialogStartTime').val();
+                            var end = calEvent.start.format('YYYY/MM/DD') + ' ' + $('#dialogEndTime').val();
+
+                            
                             var max = $('#dialogMaxAtt').val();
-                            var timeid = $('#dialogAvailSubmit').attr('data-timeid');
+                            var timeId = $('#dialogAvailSubmit').attr('data-timeid');
+
+                            // Make sure we have required data
+                            if (start.length < 8 || end.length < 8 || max.length == 0 || !$.isNumeric(max)) {
+                                alert('Please check required fields!');
+                                return false;
+                            }
+
+                            
                             $.ajax({
-                                url: "{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=updateAvailability&newTime=false&active=" + checked + "&max=" + max + "&reg_time=" + timeid
+                                url: "{$ajaxUrl}",
+                                method: "POST",
+                                data: {
+                                    reg_time:       timeId,
+                                    action:         "glm_members_admin_ajax",
+                                    glm_action:     "updateAvailability",
+                                    newTime:        "false",
+                                    active:         checked,
+                                    allDay:         allDay,
+                                    start:          start,
+                                    end:            end,
+                                    max:            max
+                                },
+                                dataType: "text"
                             });
                             $('#availabilityEditDialog').dialog('close');           
                             $('#dialogAvailSubmit').off('click');           
 
+                            // Update times
+                            calEvent.start = start;
+                            calEvent.end = end;
+                            
                 {if $regEvent.time_specific.value}
                             calEvent.title = max + '-' + calEvent.count + '-' + calEvent.pending + '-' + calEvent.available;
                 {else}