Reworked use of times arrays to work with showing times even with non-time-specific...
authorChuck Scott <cscott@gaslightmedia.com>
Thu, 30 Nov 2017 19:43:17 +0000 (14:43 -0500)
committerChuck Scott <cscott@gaslightmedia.com>
Thu, 30 Nov 2017 19:43:17 +0000 (14:43 -0500)
Updated checkEventTimes() and getEventForRegistration() in dataRegEvent.php
Updated admin reg event dashboard to show event dates/times in calendar for non-time-specific events.
Reworked registrations.php to use the proper times data now.
Fixed how ademin events.php sets up first time data in template calendar and how it checks for missing reg_time entries.

classes/data/dataRegEvent.php
models/admin/ajax/updateAvailability.php
models/admin/registrations/events.php
models/front/registrations/registration.php
views/admin/registrations/eventDashboard.html

index c14eee2..34cf6d3 100644 (file)
@@ -659,9 +659,6 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract
     public function getEventConfig($id = false, $extended = false, $forEdit = false, $withRecurData = false, $counts = false)
     {
 
-        $regEventFirstTime = false;
-        $regEventLastTime = false;
-
         // Save status of extended data flag
         $saveExtended = $this->postProcAddedEventData;
 
@@ -688,14 +685,8 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract
         require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegTime.php';
         $RegTime = new GlmDataRegistrationsRegTime($this->wpdb, $this->config);
 
-        // If this is a time specific event, then get all times except any default entry that might be there from the event having been a non-time_specific event
-        if ($this->regEventData['time_specific']['value']) {
-            $this->regEventData['reg_time'] = $RegTime->getList('T.reg_event = '.$this->regEventData['id'], 'start_datetime', true);     // removed    .' AND T.event_time > 0'
-
-        // Otherwise if this is a non-time_specific event, we only want the default entry
-        } else {
-            $this->regEventData['reg_time'] = $RegTime->getList('T.reg_event = '.$this->regEventData['id'].' AND T.event_time = 0', 'start_datetime', true);
-        }
+        // 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);
 
         // Get all reg_class records for this event
         require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegClass.php';
@@ -722,51 +713,44 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract
             return false;
         }
 
-        // For each recurrence
-        foreach ($this->regEventData['recurrences'] as $recurKey=>$recurVal) {
+        // Get the first and last times in the reg_times entries
+        $firstTime = false;
+        $lastTime = false;
+        foreach ($this->regEventData['reg_time'] as $time) {
 
-            $this->regEventData['recurrences'][$recurKey]['haveTimes'] = false;
+            // If the time is not for non-time-specific inventory
+            if (!$time['non_time_specific']['value']) {
 
-            // If we have times for this recurrence
-            if ($recurVal['times'] && count($recurVal['times']) > 0) {
-
-                // Get the first and last event date/time
-                $first = current($recurVal['times']);
-                $last = end($recurVal['times']);
-
-                $this->regEventData['recurrences'][$recurKey]['first_time'] = $first;
-                $this->regEventData['recurrences'][$recurKey]['lastTime'] = $last;
-
-                // Set event first and last times
-                if (!$regEventFirstTime || $regEventFirstTime['start_time']['timestamp'] > $first['start_time']['timestamp'] ) {
-                    $regEventFirstTime = $first;
+                if (!$firstTime || $time['start_datetime']['timestamp'] < $firstTime) {
+                    $firstTime = $time['start_datetime']['timestamp'];
                 }
-                if (!$regEventLastTime || $regEventLastTime['end_time']['timestamp'] < $last['end_time']['timestamp'] ) {
-                    $regEventLastTime = $last;
+                if (!$lastTime || $time['start_datetime']['timestamp'] > $lastTime) {
+                    $lastTime = $time['start_datetime']['timestamp'];
                 }
 
-            } // have times for recurrence
-
-            $recurrenceSummary[] = array(
-                'firstTime'  => $first,
-                'lastTime'   => $last
-            );
+            }
 
-        } // each recurrence
+        }
 
-        // Save First and Last times for the entire event
-        $this->regEventData['firstTime'] = $regEventFirstTime;
-        $this->regEventData['lastTime'] = $regEventLastTime;
+        // Generate date as used in results
+        $firstDateTime = date('Y-m-d H:i:s', $firstTime);
+        $lastDateTime = date('Y-m-d H:i:s', $lastTime);
 
         // Check if we need to update first and/or last event times in database - if so, do that
-        if ($this->regEventData['first_datetime']['timestamp'] != $regEventFirstTime['start_time']['timestamp'] ||
-            $this->regEventData['last_datetime']['timestamp'] != $regEventLastTime['start_time']['timestamp']
+        if ($this->regEventData['first_datetime']['timestamp'] != $firstTime ||
+            $this->regEventData['last_datetime']['timestamp'] != $lastTime
             ) {
+
+            // Update the regEventData first and last times
+            $this->regEventData['first_dateTime'] = array('datetime' => $firstDateTime, 'timestamp' => $firstTime);
+            $this->regEventData['last_dateTime'] = array('datetime' => $lastDateTime, 'timestamp' => $lastTime);
+
+            // Update the database
             $this->wpdb->update(
                 GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX.'reg_event',
                 array(
-                    'first_datetime' => date('Y-m-d H:i:s', $regEventFirstTime['start_time']['timestamp']),
-                    'last_datetime' => date('Y-m-d H:i:s', $regEventLastTime['start_time']['timestamp']),
+                    'first_datetime' => date('Y-m-d H:i:s', $firstTime),
+                    'last_datetime' => date('Y-m-d H:i:s', $lastTime),
                 ),
                 array( 'id' => $this->regEventData['id'] ),
                 array(
@@ -776,8 +760,49 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract
             );
         }
 
+        // If this is a non-time-specific event
+        if ($time['non_time_specific']) {
+
+            // Find the non-time-specific time entry
+            foreach ($this->regEventData['reg_time'] as $regTimeKey=>$regTime) {
+
+                // If this is the non-time-specific entry
+                if ($regTime['non_time_specific']['value']) {
+
+                    // If the start and/or end times changed
+                    if ($regTime['start_datetime']['timestamp'] != $firstTime ||
+                        $regTime['end_datetime']['timestamp'] !=- $lastTime
+                        ) {
+
+                        // Update this reg_time entry - NOTE: for non-time-specific entries the end_datetime is the start of the last occurance of the event
+                        $this->regEventData['reg_time'][$regTimeKey]['start_datetime'] = array('datetime' => $firstDateTime, 'timestamp' => $firstTime);
+                        $this->regEventData['reg_time'][$regTimeKey]['end_datetime'] = array('datetime' => $lastDateTime, 'timestamp' => $lastTime);
+
+                        // Update the database
+                        $this->wpdb->update(
+                            GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX.'reg_time',
+                            array(
+                                'start_datetime' => date('Y-m-d H:i:s', $firstTime),
+                                'end_datetime' => date('Y-m-d H:i:s', $lastTime),
+                            ),
+                            array( 'id' => $regTimeKey ),
+                            array(
+                                '%s',
+                                '%s'
+                            )
+                        );
+
+                    } // If times changed
+
+                } // is non_time_specific
+
+            } // each reg_time
+
+        } // non_time_specific
+
+
         // Add Recurrence summary to event data
-        $this->regEventData['recurrenceSummary'] = $recurrenceSummary;
+//        $this->regEventData['recurrenceSummary'] = $recurrenceSummary;
 
         // If recurrences is not requested - dump them now
         if (!$withRecurData) {
@@ -807,7 +832,6 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract
 
         // Get the event data
         $this->getEventConfig($regEventId);
-//echo "<pre>".print_r($this->regEventData,1)."</pre>";
 
         // Make sure we have an event
         if (!$this->regEventData) {
@@ -827,7 +851,7 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract
         if (!is_array($this->regEventData['reg_time']) || count($this->regEventData['reg_time']) == 0) {
             return false;
         }
-
+/*
         // Check reg_time array
         $timeSpecific = $this->regEventData['time_specific']['value'];
         foreach ($this->regEventData['reg_time'] as $timeKey=>$timeVal) {
@@ -851,6 +875,7 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract
             }
 
         }
+*/
 
         // If now we don't have any time entries
         if (count($this->regEventData['reg_time']) == 0) {
@@ -858,7 +883,7 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract
         }
 
         // If it's too late to register for this event
-        if ($this->regEventData['lastTime']['start_time']['timestamp'] - time() < ($this->regEventData['reg_hours_before'] & 3600)) {
+        if ($this->regEventData['last_datetime']['timestamp'] - time() < ($this->regEventData['reg_hours_before'] & 3600)) {
             return false;
         }
 
@@ -868,80 +893,68 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract
         }
 
         // For each class
-        foreach ($this->regEventData['reg_class'] as $ck=>$cv) {
+        foreach ($this->regEventData['reg_class'] as $regClassKey=>$regClass) {
 
             // If we don't have any rates for this class, remove the class
-            if (!is_array($cv['reg_rate']) || count($cv['reg_rate']) == 0) {
-                unset($this->regEventData['reg_class'][$ck]);
+            if (!is_array($regClass['reg_rate']) || count($regClass['reg_rate']) == 0) {
+                unset($this->regEventData['reg_class'][$regCLassKey]);
             } else {
 
-                $this->regEventData['reg_class'][$ck]['times'] = array();
-                $this->regEventData['reg_class'][$ck]['hasTimes'] = false;
-
-                // For each event time
-                foreach ($this->regEventData['reg_time'] as $tk=>$tv) {
-
-                    // If event is time specific - rates days are per the selected time
-                    if ($this->regEventData['time_specific']['value']) {
-
-                        // If event time is for time-specific event (might be either mixed in)
-// Not checking time specific/non-time specific reg_time records at this time due to adding reg_times manually that don't have event_time(s) that match
-//                        if ($tv['event_time']) {
-
-                            // Try to find a current rate for this time - within the start and end days before this time
-                            foreach ($cv['reg_rate'] as $rk=>$rv) {
+                $this->regEventData['reg_class'][$regCLassKey]['times'] = array();
+                $this->regEventData['reg_class'][$regCLassKey]['non_time_specific_time'] = array();
+                $this->regEventData['reg_class'][$regCLassKey]['hasTimes'] = false;
 
-                                // Calculate earliest and latest days for this rate calculated from the start of this event time
-                                $earliestTime   = strtotime(date('m/d/Y', $tv['start_datetime']['timestamp']).' -'.$rv['start_days'].' days');
-                                $latestTime     = strtotime(date('m/d/Y', $tv['start_datetime']['timestamp']).' -'.($rv['end_days']-1).' days');
+                // For each event time except non-time-specific entry
+                foreach ($this->regEventData['reg_time'] as $regTimeKey=>$regTime) {
 
-                                // If it's time to register with this time/rate - Add it to the class data
-                                if (time() > $earliestTime && time() < $latestTime) {
+                    // Try to find a current rate for this time - within the start and end days before this time
+                    foreach ($regClass['reg_rate'] as $regRateKey=>$regRate) {
 
-                                    // Preserve rate ID and don't let it trash the time ID
-                                    $rv['rate_id'] = $rv['id'];
-                                    unset($rv['id']);
+                        // Calculate earliest and latest days for this rate calculated from the start of this event time
+                        $earliestTime   = strtotime(date('m/d/Y', $regTime['start_datetime']['timestamp']).' -'.$regRate['start_days'].' days');
+                        $latestTime     = strtotime(date('m/d/Y', $regTime['start_datetime']['timestamp']).' -'.($regRate['end_days']-1).' days');
 
-                                    $this->regEventData['reg_class'][$ck]['times'][$tv['event_time']] = array_merge($tv, $rv);
-                                    $this->regEventData['reg_class'][$ck]['hasTimes'] = true;
-                                }
+                        // If it's time to register with this time/rate - Add it to the class data
+                        if (time() > $earliestTime && time() < $latestTime) {
 
-                            }
+                            // Preserve rate ID and don't let it trash the time ID
+                            $regRate['rate_id'] = $regRate['id'];
+                            unset($regRate['id']);
 
-//                        }
+                            $this->regEventData['reg_class'][$regCLassKey]['times'][$regTime['event_time']] = array_merge($regTime, $regRate);
+                            $this->regEventData['reg_class'][$regCLassKey]['hasTimes'] = true;
+                        }
 
-                    // Otherwise for non time specific eventes - rate days are per the first event date
-                    } else {
+                    }
 
-                        // If event time is for non time specific event (might be either mixed in)
-                        if (!$tv['event_time']) {
+                }
 
-                            // Try to find a current rate for this time - within the start and end days before this time
-                            foreach ($cv['reg_rate'] as $rk=>$rv) {
 
-                                // Calculate earliest and latest days for this rate calculated from the start of the first date/time for this event
-                                // ** We may want to make it optional to use the last day of the event ???
-                                $earliestTime   = strtotime(date('m/d/Y', $this->regEventData['firstTime']['start_time']['timestamp']).' -'.$rv['start_days'].' days');
-                                $latestTime     = strtotime(date('m/d/Y', $this->regEventData['firstTime']['start_time']['timestamp']).' -'.($rv['end_days']-1).' days');
+                // If event time is for time-specific event (might be either mixed in)
+                if ($regTime['non_time_specific']) {
 
-                                // If it's time to register with this time/rate - Add it to the class data
-                                if (time() > $earliestTime && time() < $latestTime) {
+                    // Try to find a current rate for this time - within the start and end days before this time
+                    foreach ($regClass['reg_rate'] as $regRateKey=>$regRate) {
 
-                                    // Preserve rate ID and don't let it trash the time ID
-                                    $rv['rate_id'] = $rv['id'];
-                                    unset($rv['id'], $rv['reg_event']);
+                        // Calculate earliest and latest days for this rate calculated from the start of the first date/time for this event
+                        // ** We may want to make it optional to use the last day of the event ???
+                        $earliestTime   = strtotime(date('m/d/Y', $this->regEventData['firstTime']['start_time']['timestamp']).' -'.$regRate['start_days'].' days');
+                        $latestTime     = strtotime(date('m/d/Y', $this->regEventData['firstTime']['start_time']['timestamp']).' -'.($regRate['end_days']-1).' days');
 
-                                    $this->regEventData['reg_class'][$ck]['times'][$tv['event_time']] = array_merge($tv, $rv);
-                                    $this->regEventData['reg_class'][$ck]['hasTimes'] = true;
-                                }
+                        // If it's time to register with this time/rate - Add it to the class data
+                        if (time() > $earliestTime && time() < $latestTime) {
 
-                            }
+                            // Preserve rate ID and don't let it trash the time ID
+                            $regRate['rate_id'] = $regRate['id'];
+                            unset($regRate['id'], $regRate['reg_event']);
 
+                            $this->regEventData['reg_class'][$regCLassKey]['times'][$regTime['event_time']] = array_merge($regTime, $regRate);
+                            $this->regEventData['reg_class'][$regCLassKey]['hasTimes'] = true;
                         }
 
                     }
 
-                } // each event time
+                }
 
             } // Have rates for this class
 
@@ -956,7 +969,7 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract
         // Get rid of the provided reg_time entries - No longer needed
         unset($this->regEventData['reg_time']);
 
-        // echo "<pre>".print_r($this->regEventData,1)."<pre>";
+        // echo "<pre>".print_r($this->regEventData,1)."</pre>";
 
         return $this->regEventData;
     }
@@ -970,10 +983,11 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract
      * @param integer $regEventId Optional ID of a reg event record. If provided, load all registration data using getEventConfig() above
      *                            This is not required if the event data has already been loaded using getEVentConfig() by the calling code
      * @param boolean $deleteRemovedTimes Optional flag to ask that times removed from the event are removed from registration
+     * @param boolean $nonDateSpecificOnly Optional flag to check only for the default non-date-specific time entry.
      *
      * @return array updated reg_times data or false if not regEventData has been provided or no recurrence data
      */
-    public function checkEventTimes($regEventId = false, $deleteTimes = false)
+    public function checkEventTimes($regEventId = false, $deleteTimes = false, $nonDateSpecificOnly = false)
     {
 
         $needTimesReloaded = false;
@@ -989,155 +1003,158 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract
             return false;
         }
 
-        // If we don't have recurrences for the event
-        if (!is_array($this->regEventData['recurrences']) || count($this->regEventData['recurrences']) == 0) {
-            return false;
-        }
+        // Only do this if we haven't requested only non-date-specific time entry check
+        if (!$nonDateSpecificOnly) {
+
+            // If we don't have recurrences for the event
+            if (!is_array($this->regEventData['recurrences']) || count($this->regEventData['recurrences']) == 0) {
+                return false;
+            }
 
-        // For each recurrence
-        foreach ($this->regEventData['recurrences'] as $recurKey=>$recurVal) {
+            // For each recurrence
+            foreach ($this->regEventData['recurrences'] as $recurKey=>$recurVal) {
 
-            // If we have times for this recurrence
-            if ($recurVal['times'] && count($recurVal['times']) > 0) {
+                // If we have times for this recurrence
+                if ($recurVal['times'] && count($recurVal['times']) > 0) {
 
-                // If this is a time specific event
-                if ($this->regEventData['time_specific']['value']) {
+                    // If this is a time specific event
+                    if ($this->regEventData['time_specific']['value']) {
 
-                    // Check all event times for matching reg event times
-                    foreach ($recurVal['times'] as $eventTimeKey=>$eventTimeVal) {
+                        // Check all event times for matching reg event times
+                        foreach ($recurVal['times'] as $eventTimeKey=>$eventTimeVal) {
 
-                        $id = false;
+                            $id = false;
 
-                        // If we have any times entries in this event
-                        if (is_array($this->regEventData['reg_time']) && count($this->regEventData['reg_time']) > 0) {
+                            // If we have any times entries in this event
+                            if (is_array($this->regEventData['reg_time']) && count($this->regEventData['reg_time']) > 0) {
 
-                            // Check if this time from the event already exists in reg_times array
-                            reset($this->regEventData['reg_time']);
-                            foreach($this->regEventData['reg_time'] as $regTimeKey=>$regTimeVal) {
-                                if ($regTimeVal['event_time'] == $eventTimeKey) {
+                                // Check if this time from the event already exists in reg_times array
+                                reset($this->regEventData['reg_time']);
+                                foreach($this->regEventData['reg_time'] as $regTimeKey=>$regTimeVal) {
+                                    if ($regTimeVal['event_time'] == $eventTimeKey) {
 
-                                    // Set ID to say we found this one.
-                                    $id = $regTimeKey;
+                                        // Set ID to say we found this one.
+                                        $id = $regTimeKey;
 
-                                    // Also add OK to the reg_time to say that it matches a recur time - see below
-                                    $this->regEventData['reg_time'][$regTimeKey]['OK'] = true;
+                                        // Also add OK to the reg_time to say that it matches a recur time - see below
+                                        $this->regEventData['reg_time'][$regTimeKey]['OK'] = true;
+                                    }
                                 }
-                            }
 
-                        }
-                        // If it wasn't found, then add it
-                        if (!$id) {
-
-                            $needTimesReloaded = true;
-                            $message .= "<br>&nbsp;&nbsp;&nbsp;&nbsp;New dates and/or times have been added";
-
-                            $sTime = date('Y-m-d H:i:s',strtotime($eventTimeVal['start_time']['datetime']));
-                            $eTime = date('Y-m-d H:i:s',strtotime($eventTimeVal['end_time']['datetime']));
-
-                            // Add reg event time
-                            $this->wpdb->insert(
-                                GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time",
-                                array(
-                                    'reg_event'             => $this->regEventData['id'],
-                                    'event_time'            => $eventTimeKey,
-                                    'start_datetime'        => $sTime,
-                                    'end_datetime'          => $eTime,
-                                    'all_day'               => $eventTimeVal['all_day']['value'],
-                                    'attendees'             => $this->regEventData['attendees']['value'],
-                                    'attendee_max'          => $this->regEventData['attendee_max'],
-                                    'attendee_count'        => 0,
-                                    'attendees_pending'     => 0,
-                                    'attendees_available'   => $this->regEventData['attendee_max'],
-                                    'total_base_charge'     => 0,
-
-                                    'total_per_attendee'    => 0,
-                                    'total_other'           => 0,
-                                    'total_taxes'           => 0,
-                                    'total_charges'         => 0,
-                                    'total_discounts'       => 0,
-                                    'total_payments'        => 0
-                                ),
-                                array(
-                                    '%d',   // reg_event
-                                    '%d',   // event_time record ID
-                                    '%s',   // start_datetime
-                                    '%s',   // end_datetime
-                                    '%d',   // all_day flag
-                                    '%d',   // attendees flag
-                                    '%d',   // attendee_max
-                                    '%d',   // attendee_count
-                                    '%d',   // attendees_pending
-                                    '%d',   // attendees_available
-                                    '%f',   // total_base__charge
-                                    '%f',   // total_per_attendee
-                                    '%f',   // total_other
-                                    '%f',   // total_taxes
-                                    '%f',   // total_charges
-                                    '%f',   // total_discounts
-                                    '%f'    // total_payments
-                                )
-                                );
-
-                        } // If time isn't in reg_times
-                    } // each recurrence times
-                } // time specific
-            } // have times for recurrence
-
-        } // each recurrence
-
-        // If this is a time specific event
-        $deleteList = '';
-        $deleteSep = '';
-        if ($this->regEventData['time_specific']['value']) {
-
-            // Check all reg_times we had from before to make sure they were matched with a recur time
-            foreach($this->regEventData['reg_time'] as $regTimeKey=>$regTimeVal) {
-                if (!isset($regTimeVal['OK'])) {
-
-                    // If this time didn't match a recur time, then it must have been removed in the event so add to list
-                    $deleteList .= $deleteSep.$regTimeKey;
-                    $deleteSep = ',';
+                            }
+                            // If it wasn't found, then add it
+                            if (!$id) {
+
+                                $needTimesReloaded = true;
+                                $message .= "<br>&nbsp;&nbsp;&nbsp;&nbsp;New dates and/or times have been added";
+
+                                $sTime = date('Y-m-d H:i:s',strtotime($eventTimeVal['start_time']['datetime']));
+                                $eTime = date('Y-m-d H:i:s',strtotime($eventTimeVal['end_time']['datetime']));
+
+                                // Add reg event time
+                                $this->wpdb->insert(
+                                    GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time",
+                                    array(
+                                        'reg_event'             => $this->regEventData['id'],
+                                        'active'                => false,
+                                        'event_time'            => $eventTimeKey,
+                                        'start_datetime'        => $sTime,
+                                        'end_datetime'          => $eTime,
+                                        'all_day'               => $eventTimeVal['all_day']['value'],
+                                        'non_time_specific'     => false,
+                                        'attendees'             => $this->regEventData['attendees']['value'],
+                                        'attendee_max'          => $this->regEventData['attendee_max'],
+                                        'attendee_count'        => 0,
+                                        'attendees_pending'     => 0,
+                                        'attendees_available'   => $this->regEventData['attendee_max'],
+                                        'total_base_charge'     => 0,
+
+                                        'total_per_attendee'    => 0,
+                                        'total_other'           => 0,
+                                        'total_taxes'           => 0,
+                                        'total_charges'         => 0,
+                                        'total_discounts'       => 0,
+                                        'total_payments'        => 0
+                                    ),
+                                    array(
+                                        '%d',   // reg_event
+                                        '%d',   // event_time record ID
+                                        '%s',   // start_datetime
+                                        '%s',   // end_datetime
+                                        '%d',   // all_day flag
+                                        '%d',   // attendees flag
+                                        '%d',   // attendee_max
+                                        '%d',   // attendee_count
+                                        '%d',   // attendees_pending
+                                        '%d',   // attendees_available
+                                        '%f',   // total_base__charge
+                                        '%f',   // total_per_attendee
+                                        '%f',   // total_other
+                                        '%f',   // total_taxes
+                                        '%f',   // total_charges
+                                        '%f',   // total_discounts
+                                        '%f'    // total_payments
+                                    )
+                                    );
+
+                            } // If time isn't in reg_times
+                        } // each recurrence times
+                    } // time specific
+                } // have times for recurrence
+
+            } // each recurrence
+
+            // If this is a time specific event
+            $deleteList = '';
+            $deleteSep = '';
+            if ($this->regEventData['time_specific']['value']) {
+
+                // Check all reg_times we had from before to make sure they were matched with a recur time
+                foreach($this->regEventData['reg_time'] as $regTimeKey=>$regTimeVal) {
+                    if (!isset($regTimeVal['OK'])) {
+
+                        // If this time didn't match a recur time, then it must have been removed in the event so add to list
+                        $deleteList .= $deleteSep.$regTimeKey;
+                        $deleteSep = ',';
 
+                    }
                 }
+
             }
 
-        }
+            // If requested and there's anything in the delete list, purge them now and say we need a reload
+            if ($deleteTimes && $deleteList != '') {
+                $this->wpdb->query("
+                    DELETE FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time
+                     WHERE id IN ($deleteList)
+                ");
+                $needTimesReloaded = true;
+                $message .= '<br>&nbsp;&nbsp;&nbsp;&nbsp;Old dates and/or times have been removed';
+            }
 
-        // If requested and there's anything in the delete list, purge them now and say we need a reload
-        if ($deleteTimes && $deleteList != '') {
-            $this->wpdb->query("
-                DELETE FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time
-                 WHERE id IN ($deleteList)
-            ");
-            $needTimesReloaded = true;
-            $message .= '<br>&nbsp;&nbsp;&nbsp;&nbsp;Old dates and/or times have been removed';
-        }
+            // Get rid of all of the recurrence data - No longer needed
+            unset($this->regEventData['recurrences']);
 
-        // Get rid of all of the recurrence data - No longer needed
-        unset($this->regEventData['recurrences']);
 
-        // If not time specific
+        } // if time specific check
+
+        // If this event is not time specific
         if (!$this->regEventData['time_specific']['value']) {
 
             // Do we have default reg_time entry? (event_time is 0)
             $defTime = false;
             if (is_array($this->regEventData['reg_time'])) {
 
-                // Is there's a default entry for not time specific event? (might be others if time_specific had been selected before - they might switch back)
+                // Is there's a default entry for not time specific event?
                 $defTime = false;
                 foreach($this->regEventData['reg_time'] as $r) {
 
-                    if ($r['event_time'] == 0) {
+                    if ($r['non_time_specific']['value']) {
                         $defTime = $r;
                         break;
                     }
                 }
 
-                // Get rid of other time entries and just use this one
-                if ($defTime !== false) {
-                    $this->regEventData['reg_time'] = array();
-                    $this->regEventData['reg_time'][0] = $defTime;
-                }
 
             }
 
@@ -1148,10 +1165,12 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract
                     GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time",
                     array(
                         'reg_event'             => $this->regEventData['id'],
+                        'active'                => true,
                         'event_time'            => 0,
                         'start_datetime'        => NULL,
                         'end_datetime'          => NULL,
                         'all_day'               => false,
+                        'non_time_specific'     => true,
                         'attendees'             => $this->regEventData['attendees']['value'],
                         'attendee_max'          => $this->regEventData['attendee_max'],
                         'attendee_count'        => 0,
index 21098c2..c71f4e2 100644 (file)
@@ -85,7 +85,7 @@
             wp_die();
         }
         $max = ($_REQUEST['max'] - 0);
-        if ($max <= 0) {
+        if ($max < 0) {
             wp_die();
         }
 
index bb10932..50dcd58 100644 (file)
@@ -105,7 +105,6 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent
         $haveRegEvent              = false;
         $haveRegEventRecurrences   = false;
         $haveRegEventTimes         = false;
-        $earliestDate              = false;
         $regEventFirstTime         = false;
         $regEventLastTime          = false;
         $regEventUpdated           = false;
@@ -276,7 +275,7 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent
                                 $regEventUpdated = true;
 
                                 // Create all needed reg_time entries
-                                // $this->checkEventTimes($regEventID);
+                                $this->checkEventTimes($regEventID);
 
                             }
 
@@ -381,9 +380,6 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent
                     // Check that the user entered the correct confirmation string
                     if (isset($_REQUEST['addConfirmation']) && $_REQUEST['addConfirmation'] == 'ADD') {
 
-                        // Check for new event times
-                        $regEvent = $this->checkEventTimes();
-
                         // Get the event data again along with any new times
                         $regEvent = $this->getEventConfig($regEventID, true, false, true);
 
@@ -395,11 +391,16 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent
 
                 }
 
+                // If this isn't a time specific event - check for new event non-date-specific only time entry
+                if (!$regEvent['time_specific']['value']) {
+                    $regEvent = $this->checkEventTimes(false, false, true);
+                }
+
                 if ($regEvent !== false) {
 
                     $haveRegEvent       = true;
-                    $regEventFirstTime  = $regEvent['firstTime'];
-                    $regEventLastTime  = $regEvent['lastTime'];
+                    $regEventFirstTime  = $regEvent['first_datetime'];
+                    $regEventLastTime  = $regEvent['last_datetime'];
 
                     // if there's a user notice, add it to messages
                     if (isset($regEvent['message']) && $regEvent['message']) {
@@ -501,8 +502,6 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent
             update_option('glmMembersDatabaseRegistrationsRegEventID', $regEventID);
         }
 
-        // echo "<pre>".print_r($regEvent,1)."</pre>";
-
         // Compile template data
         $templateData = array(
             'haveMessages'            => count($messages) > 0,
@@ -526,8 +525,8 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent
             'regEvent'                => $regEvent,
             'haveRegEvent'            => $haveRegEvent,
             'haveRegEventRecurrences' => $haveRegEventRecurrences,
-            'earliestDate'            => $earliestDate,
             'haveRegEventTimes'       => $haveRegEventTimes,
+            'defaultCalDate'          => date('Y-m-d H:i:s', $regEventFirstTime['timestamp']),
             'regEventFirstTime'       => $regEventFirstTime,
             'regEventLastTime'        => $regEventLastTime,
             'regEventUpdated'         => $regEventUpdated,
@@ -540,6 +539,8 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent
             'regTimesJSON'            => $regTimesJSON
         );
 
+        // echo "<pre>".print_r($templateData,1)."</pre>";
+
         // Return status, any suggested view, and any data to controller
         return array(
             'status'        => true,
index e4deab2..0e35a53 100644 (file)
         $regClasses  = array();
 
         $regTimes = array();
+
         if ( isset( $regEvent['reg_class'] ) && is_array( $regEvent['reg_class'] ) ) {
 
             // Loop through the $regEvent['reg_class'] array to build $rClass array
             // times array. If it doesn't then there's no current registration
             // allowed for that event.
             foreach ( $regEvent['reg_class'] as $key => $rClass ) {
+
                 $classStartingTime = '';
                 // echo '<pre>$rClass: ' . print_r( $rClass, true ) . '</pre>';
+
                 // Pull the rate data
                 if ( isset( $rClass['times'] ) && is_array( $rClass['times'] ) && count( $rClass['times'] ) > 0 ) {
+
                     // echo '<pre>$rClass[times]: ' . print_r( $rClass['times'], true ) . '</pre>';
-                    foreach ( $rClass['times'] as &$time ) {
+                    foreach ( $rClass['times'] as $time ) {
                         if ( $classStartingTime == '' || $time['start_datetime']['timestamp'] < $classStartingTime['start_datetime']['timestamp'] ) {
                             $classStartingTime = $time;
                         }
             } // - End loop through events.
         }
 
-        // echo '<pre>$registrants: ' . print_r( $regEvent, true ) . '</pre>';
-
         // Compile template data
         $templateData = array(
             'page'              => 'registration',
             'reg_bulletin'      => $misc['reg_bulletin']
         );
 
+        // echo '<pre>$registrants: ' . print_r( $templateData, true ) . '</pre>';
+
         // Return status, any suggested view, and any data to controller
         return array(
             'status'        => true,
index 984d2b2..1dc5717 100644 (file)
@@ -31,7 +31,7 @@
                         <h3>First Event Time:</h3>
                     </div>
                     <div class="glm-small-12 glm-column time-input">
-                        {$regEventFirstTime.start_time.datetime}
+                        {$regEventFirstTime.datetime}
                     </div>
                 </div>
                 <div class="glm-row">
@@ -39,7 +39,7 @@
                         <h3>Last Event Time:</h3>
                     </div>
                     <div class="glm-small-12 glm-column">
-                        {$regEventLastTime.end_time.datetime}
+                        {$regEventLastTime.datetime}
                     </div>
                 </div>
             </div>
 <div class="glm-admin-table-inner glm-admin-table">
   {if $haveRegEvent}
     <p><h3>Dates and Availability</h3></p>
-
-   {if $regEvent.time_specific.value}
-
-    <p>Availability guide: (limit)-(registered)-(pending)-(available)</p>
-    <table id="glm-table-calendar" class="glm-admin-table glm-event-table">
-        <tr>
-            <td>
-                <div id="eventCalendar" style="width: 95%;"></div>
-            </td>
-        </tr>
-    </table>
-   {else}
     <p>Event occurs every day from first day to last day at the times shown.</p>
     <table>
       {foreach $regEvent.recurrenceSummary as $rs}
         <tr><th>Last Day of Event: </th><td>{$rs.lastTime.start_time.datetime} - {$rs.lastTime.end_time.datetime}</td></tr>
       {/foreach}
       {foreach $regEvent.reg_time as $rt}
+       {if $rt.non_time_specific.value}
         {if $rt.attendee_max == 0}
-        <tr><th colspan="2">Unlimited registration - Not maintaining available inventory.</th></tr>
-        {else}
+        <tr><th colspan="2">Unlimited registration - Set maximum attendees quantity below to limit registrations.</th></tr>
+        {/if}
         <tr><td colspan="2">&nbsp;</td></tr>
         <tr><td colspan="2">Limited availability for this event - the below numbers are for all days.</td></tr>
         <tr><th style="text-align: left">Maximum Attendees:</th><td>
         <tr><th style="text-align: left">Registered Attendees:</th><td id="regAtt">{$rt.attendee_count}</td></tr>
         <tr><th style="text-align: left">Pending in Carts:</th><td id="pendAtt">{$rt.attendees_pending}</td></tr>
         <tr><th style="text-align: left">Available for Registration:</th><td id="availAtt">{$rt.attendees_available}</td></tr>
-        {/if}
+       {/if}
       {/foreach}
     </table>
-   {/if}
+    <p>Availability guide: (limit)-(registered)-(pending)-(available)</p>
+    <table id="glm-table-calendar" class="glm-admin-table glm-event-table">
+        <tr>
+            <td>
+                <div id="eventCalendar" style="width: 95%;"></div>
+            </td>
+        </tr>
+    </table>
+
+
   {else}
         <h3>Did not find selected event.</h3>
   {/if}
 
             var fullCalendarLoaded = false;
 
-            // If this is a time specific event, then display the calendar
-            if ({$regEvent.time_specific.value} +0) {
 
-                /*
-                 * Initialize the Full Calendar
-                 */
-                
-                function initFullCalendar(){
-                    $('#eventCalendar').fullCalendar({
-        {if $regEvent}
-                        // Add existing registration dates/times
-                        events: [
-                            {$sep = ''}
-          {if $haveRegEventTimes}
-               {foreach $regEvent.reg_time as $t}
-                            {$sep}{
-                              {if $t.attendee_max == 0}
-                                title:              'unlimited',
-                              {else}
-                                title:              '{$t.attendee_max}-{$t.attendee_count}-{$t.attendees_pending}-{$t.attendees_available}',
-                              {/if}
-                                start:              '{$t.start_datetime.datetime}',
-                                end:                '{$t.end_datetime.datetime}',
-                                active:             {if $t.active.value}true{else}false{/if},
-                              {if $t.active.value}
-                                backgroundColor:    'light-blue',
-                              {else}
+            /*
+             * Initialize the Full Calendar
+             */
+           
+            function initFullCalendar(){
+                $('#eventCalendar').fullCalendar({
+    {if $regEvent}
+                    // Add existing registration dates/times
+                    events: [
+                        {$sep = ''}
+      {if $haveRegEventTimes}
+       {foreach $regEvent.reg_time as $t}
+          {if $t.non_time_specific.value == false}
+                        {$sep}{
+                          {if $t.attendee_max == 0}
+                            title:              'unlimited',
+                          {else}
+                            title:              '{$t.attendee_max}-{$t.attendee_count}-{$t.attendees_pending}-{$t.attendees_available}',
+                          {/if}
+                            start:              '{$t.start_datetime.datetime}',
+                            end:                '{$t.end_datetime.datetime}',
+                            active:             {if $t.active.value}true{else}false{/if},
+                          {if $t.active.value}
+                            backgroundColor:    'light-blue',
+                          {else}
+                            backgroundColor:    '#aaa',
+                          {/if}
+                            allday:             {$t.all_day.value},
+                            attendees:          {if $t.attendees.value}true{else}false{/if},
+                            max:                {$t.attendee_max},
+                            count:              {$t.attendee_count},
+                            pending:            {$t.attendees_pending},
+                            available:          {$t.attendees_available},
+                            datetime:           '{$t.start_datetime.datetime}',
+                            timeid:             {$t.id}
+                        }
+                        {$sep = ','}
+          {/if}
+        {/foreach}
+      {/if}
+                    ],
+                    // Clicking on a date cell (not a reg event) Brings up the new reg event dialog
+                    dayClick: function(date, allDay, jsEvent, view) {
+
+                        $('#dialogAvailSubmit').off('click');           
+                        
+                        $('#availabilityTitle').html('Create New: '+date.format());
+                        $('#availabilityEditDialog').dialog('open');
+                        $('#dialogRegActive').prop('checked', true);
+                        $('#dialogTimeAllDay').prop('checked', false);
+                        $('#dialogAttendees').prop('checked', true);
+                        $('#dialogStartTime').val('');
+                        $('#dialogEndTime').val('');
+                        $('#dialogMaxAtt').val(0);
+                        $('#dialogRegLine').hide();
+                        $('#dialogPendLine').hide();
+                        $('#dialogAvailLine').hide();
+                        $('#dialogAvailSubmit').on('click', function() {
+
+                            // Submit clicked 
+                            var max = $('#dialogMaxAtt').val();
+                            var startDate = new Date($('#dialogStartTime').val());
+                            var startTime = $('#dialogStartTime').val();
+
+                            // Initialize the event data object with submitted data 
+                            var newEvent = {
+                                title:              startTime + ' unlimited',
+                                start:              date.format() + ' ' + startTime,
+                                end:                date.format() + ' ' + $('#dialogEndTime').val(),
+                                active:             $('#dialogRegActive').is(":checked"),
                                 backgroundColor:    '#aaa',
-                              {/if}
-                                allday:             {$t.all_day.value},
-                                attendees:          {if $t.attendees.value}true{else}false{/if},
-                                max:                {$t.attendee_max},
-                                count:              {$t.attendee_count},
-                                pending:            {$t.attendees_pending},
-                                available:          {$t.attendees_available},
-                                datetime:           '{$t.start_datetime.datetime}',
-                                timeid:             {$t.id}
+                                allDay:             $('#dialogTimeAllDay').is(':checked'),
+                                attendees:          $('#dialogAttendees').is(':checked'),          
+                                max:                max,
+                                count:              0,
+                                pending:            0,
+                                available:          max,
+                                timeId:             false                                
+                            };
+
+                            // If max or active is set, override the defaults
+                            if (newEvent.max > 0 ) {
+                                newEvent.title = startTime + ' ' + newEvent.max + '-0-0-' + newEvent.max
+                            }
+                            if (newEvent.active) {
+                                newEvent.backgroundColor = 'light-blue';
                             }
-                            {$sep = ','}
-            {/foreach}
-          {/if}
-                        ],
-                        // Clicking on a date cell (not a reg event) Brings up the new reg event dialog
-                        dayClick: function(date, allDay, jsEvent, view) {
-
-                            $('#dialogAvailSubmit').off('click');           
-                            
-                            $('#availabilityTitle').html('Create New: '+date.format());
-                            $('#availabilityEditDialog').dialog('open');
-                            $('#dialogRegActive').prop('checked', true);
-                            $('#dialogTimeAllDay').prop('checked', false);
-                            $('#dialogAttendees').prop('checked', true);
-                            $('#dialogStartTime').val('');
-                            $('#dialogEndTime').val('');
-                            $('#dialogMaxAtt').val(0);
-                            $('#dialogRegLine').hide();
-                            $('#dialogPendLine').hide();
-                            $('#dialogAvailLine').hide();
-                            $('#dialogAvailSubmit').on('click', function() {
-
-                                // Submit clicked 
-                                var max = $('#dialogMaxAtt').val();
-                                var startDate = new Date($('#dialogStartTime').val());
-                                var startTime = $('#dialogStartTime').val();
-
-                                // Initialize the event data object with submitted data 
-                                var newEvent = {
-                                    title:              startTime + ' unlimited',
-                                    start:              date.format() + ' ' + startTime,
-                                    end:                date.format() + ' ' + $('#dialogEndTime').val(),
-                                    active:             $('#dialogRegActive').is(":checked"),
-                                    backgroundColor:    '#aaa',
-                                    allDay:             $('#dialogTimeAllDay').is(':checked'),
-                                    attendees:          $('#dialogAttendees').is(':checked'),          
-                                    max:                max,
-                                    count:              0,
-                                    pending:            0,
-                                    available:          max,
-                                    timeId:             false                                
-                                };
-
-                                // If max or active is set, override the defaults
-                                if (newEvent.max > 0 ) {
-                                    newEvent.title = startTime + ' ' + newEvent.max + '-0-0-' + newEvent.max
-                                }
-                                if (newEvent.active) {
-                                    newEvent.backgroundColor = 'light-blue';
-                                }
-
-                                // Try to send the data via AJAX
-                                var newTime = $.ajax({
-                                    
-                                    url: "{$ajaxUrl}",
-                                    method: "POST",
-                                    data: {
-                                        action:         "glm_members_admin_ajax",
-                                        glm_action:     "updateAvailability",
-                                        event:          {$regEvent.id},
-                                        newTime:        "true",
-                                        active:         newEvent.active,
-                                        allDay:         newEvent.allDay,
-                                        attendees:      newEvent.attendees,
-                                        start:          newEvent.start,
-                                        end:            newEvent.end,
-                                        max:            newEvent.max
-                                    },
-                                    dataType: "text"
-                                        
-                                }).done( function(newTimeId) {
-
-                                    // If response was not a possible time ID
-                                    newEvent.timeId = parseInt(newTimeId);
 
-                                    if (newEvent.timeId == '0') {
-                                        alert('New event date/time may not have been stored properly. Reload page to check.');
-                                    } else {
-                                        // Should have good time ID, so add it to the calendar
-                                        $('#eventCalendar').fullCalendar('renderEvent', newEvent, true);
-                                    }
-                                    
-                                    $('#availabilityEditDialog').dialog('close');           
-                                    $('#dialogAvailSubmit').off('click');           
+                            // Try to send the data via AJAX
+                            var newTime = $.ajax({
+                                
+                                url: "{$ajaxUrl}",
+                                method: "POST",
+                                data: {
+                                    action:         "glm_members_admin_ajax",
+                                    glm_action:     "updateAvailability",
+                                    event:          {$regEvent.id},
+                                    newTime:        "true",
+                                    active:         newEvent.active,
+                                    allDay:         newEvent.allDay,
+                                    attendees:      newEvent.attendees,
+                                    start:          newEvent.start,
+                                    end:            newEvent.end,
+                                    max:            newEvent.max
+                                },
+                                dataType: "text"
                                     
-                                });
+                            }).done( function(newTimeId) {
 
-                            });
-
-                        },
-                        eventMouseover : function(event, jsEvent, view) {
-                            $('.fc-event').css( 'cursor', 'pointer' );
-                        },
-                        defaultDate : '{$regEventFirstTime.start_time.datetime}',
-                        timeFormat  : 'h:mma',
-                        fixedWeekCount : false,
-                        eventClick: function(calEvent, jsEvent, view) {
-
-                            $('#dialogAvailSubmit').off('click');  
-                            
-                            $("#occurrences").dialog();
-                            $(this).css('border-color', 'red');
+                                // If response was not a possible time ID
+                                newEvent.timeId = parseInt(newTimeId);
 
-                            $('#availabilityEditDialog').dialog('open');
-
-                            $('#dialogAllDayLine').hide();
-                            $('#dialogTrackLine').hide();
-                            $('#dialogStartTimeLine').hide();
-                            $('#dialogEndTimeLine').hide();
-                            
-                            $('#availabilityTitle').html(calEvent.datetime);
-                            $('#dialogRegActive').prop('checked', calEvent.active);
-                            $('#dialogTimeAllDay').prop('checked', calEvent.allDay);
-                            $('#dialogStartTime').val(calEvent.start);
-                            $('#dialogEndTime').val(calEvent.end);
-                            $('#dialogMaxAtt').val(calEvent.max);
-                            $('#dialogRegLine').show();
-                            $('#dialogRegAtt').html(calEvent.count);
-                            $('#dialogPendLine').show();
-                            $('#dialogPendAtt').html(calEvent.pending);
-                            $('#dialogAvailLine').show();
-                            $('#dialogAvailAtt').html(calEvent.available);
-                            $('#dialogAvailSubmit').attr('data-timeid', calEvent.timeid);
-                            // Re-calculate total available when entering
-
-                            $('#dialogMaxAtt').on('change', function() {
-                                var max = $('#dialogMaxAtt').val();
-                                max = max -0;
-                                var available = max - calEvent.count - calEvent.pending;
-                                if (available < 0) {
-                                    max = max - available;
-                                    $('#dialogMaxAtt').val(max);
-                                    available = 0;
-                                }
-                                calEvent.available = available;
-                                $('#dialogAvailAtt').html(available);
-                                $('#dialogMaxAtt').off('change');
-                            });
-                            
-                            $('#dialogAvailSubmit').on('click', function() {
-
-                                var checked = $('#dialogRegActive').is(":checked");
-                                calEvent.active = checked;
-                                if (checked) {
-                                    calEvent.backgroundColor = 'light-blue';
+                                if (newEvent.timeId == '0') {
+                                    alert('New event date/time may not have been stored properly. Reload page to check.');
                                 } else {
-                                    calEvent.backgroundColor = '#aaa';
+                                    // Should have good time ID, so add it to the calendar
+                                    $('#eventCalendar').fullCalendar('renderEvent', newEvent, true);
                                 }
-                                var max = $('#dialogMaxAtt').val();
-                                var timeid = $('#dialogAvailSubmit').attr('data-timeid');
-                                $.ajax({
-                                    url: "{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=updateAvailability&newTime=false&active=" + checked + "&max=" + max + "&reg_time=" + timeid
-                                });
+                                
                                 $('#availabilityEditDialog').dialog('close');           
                                 $('#dialogAvailSubmit').off('click');           
                                 
-                                calEvent.title = max + '-' + calEvent.count + '-' + calEvent.pending + '-' + calEvent.available;
-                                $('#eventCalendar').fullCalendar('updateEvent', calEvent);      
                             });
 
-                                            
-                        }
-        {/if}
-                    });
-                }
+                        });
 
-                       initFullCalendar();
+                    },
+                    eventMouseover : function(event, jsEvent, view) {
+                        $('.fc-event').css( 'cursor', 'pointer' );
+                    },
+                    defaultDate : '{$defaultCalDate}',
+                    timeFormat  : 'h:mma',
+                    fixedWeekCount : false,
+                    eventClick: function(calEvent, jsEvent, view) {
+
+                        $('#dialogAvailSubmit').off('click');  
+                        
+                        $("#occurrences").dialog();
+                        $(this).css('border-color', 'red');
+
+                        $('#availabilityEditDialog').dialog('open');
+
+                        $('#dialogAllDayLine').hide();
+                        $('#dialogTrackLine').hide();
+                        $('#dialogStartTimeLine').hide();
+                        $('#dialogEndTimeLine').hide();
+                        
+                        $('#availabilityTitle').html(calEvent.datetime);
+                        $('#dialogRegActive').prop('checked', calEvent.active);
+                        $('#dialogTimeAllDay').prop('checked', calEvent.allDay);
+                        $('#dialogStartTime').val(calEvent.start);
+                        $('#dialogEndTime').val(calEvent.end);
+                        $('#dialogMaxAtt').val(calEvent.max);
+                        $('#dialogRegLine').show();
+                        $('#dialogRegAtt').html(calEvent.count);
+                        $('#dialogPendLine').show();
+                        $('#dialogPendAtt').html(calEvent.pending);
+                        $('#dialogAvailLine').show();
+                        $('#dialogAvailAtt').html(calEvent.available);
+                        $('#dialogAvailSubmit').attr('data-timeid', calEvent.timeid);
+                        // Re-calculate total available when entering
+
+                        $('#dialogMaxAtt').on('change', function() {
+                            var max = $('#dialogMaxAtt').val();
+                            max = max -0;
+                            var available = max - calEvent.count - calEvent.pending;
+                            if (available < 0) {
+                                max = max - available;
+                                $('#dialogMaxAtt').val(max);
+                                available = 0;
+                            }
+                            calEvent.available = available;
+                            $('#dialogAvailAtt').html(available);
+                            $('#dialogMaxAtt').off('change');
+                        });
+                        
+                        $('#dialogAvailSubmit').on('click', function() {
+
+                            var checked = $('#dialogRegActive').is(":checked");
+                            calEvent.active = checked;
+                            if (checked) {
+                                calEvent.backgroundColor = 'light-blue';
+                            } else {
+                                calEvent.backgroundColor = '#aaa';
+                            }
+                            var max = $('#dialogMaxAtt').val();
+                            var timeid = $('#dialogAvailSubmit').attr('data-timeid');
+                            $.ajax({
+                                url: "{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=updateAvailability&newTime=false&active=" + checked + "&max=" + max + "&reg_time=" + timeid
+                            });
+                            $('#availabilityEditDialog').dialog('close');           
+                            $('#dialogAvailSubmit').off('click');           
+                            
+                            calEvent.title = max + '-' + calEvent.count + '-' + calEvent.pending + '-' + calEvent.available;
+                            $('#eventCalendar').fullCalendar('updateEvent', calEvent);      
+                        });
 
-            } else {
+                                        
+                    }
+    {/if}
+                });
+            }
+            initFullCalendar();
 
+            // If not date/time specific then we need to add the data for the non-date-specific time entry.
+            if (!{$regEvent.time_specific.value}) {
+                    
                 // Not date specific so do one counts update form
                 $('#maxAtt').on('change', function() {
                     var max = $('#maxAtt').val();
                     var time = $('#availSubmit').attr('data-timeid');
                     
                     $.ajax({
-                        url: "{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=updateAvailability&max=" + max + "&reg_time=" + time
+                        url: "{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=updateAvailability&newTime=false&active=true&max=" + max + "&reg_time=" + time
                     });
                     $("#submit-flash").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);
                 });