From e5ba8e1a68a0471d3111cb7067bb40eff8adf739 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Tue, 28 Nov 2017 13:04:23 -0500 Subject: [PATCH] Completed ability to add new reg event times via reg event dashboard calendar. Fixed bad date/time format where updating first and last times for reg_event. Had to remove check for event_time > 0 in getEventConfig() in dataRegEvent.php. --- classes/data/dataRegEvent.php | 6 +- models/admin/ajax/updateAvailability.php | 128 ++++++++++++++++-- models/admin/registrations/events.php | 4 - views/admin/registrations/eventDashboard.html | 62 ++++++--- 4 files changed, 161 insertions(+), 39 deletions(-) diff --git a/classes/data/dataRegEvent.php b/classes/data/dataRegEvent.php index 82d86ac..2b10096 100644 --- a/classes/data/dataRegEvent.php +++ b/classes/data/dataRegEvent.php @@ -690,7 +690,7 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract // 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'].' AND T.event_time > 0', 'start_datetime', true); + $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 { @@ -765,8 +765,8 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract $this->wpdb->update( GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX.'reg_event', array( - 'first_datetime' => date('Y-m-d H:is', $regEventFirstTime['start_time']['timestamp']), - 'last_datetime' => date('Y-m-d H:is', $regEventLastTime['start_time']['timestamp']), + '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']), ), array( 'id' => $this->regEventData['id'] ), array( diff --git a/models/admin/ajax/updateAvailability.php b/models/admin/ajax/updateAvailability.php index b23abf1..21098c2 100644 --- a/models/admin/ajax/updateAvailability.php +++ b/models/admin/ajax/updateAvailability.php @@ -59,7 +59,7 @@ public function modelAction($actionData = false) { -trigger_error(123123123,E_USER_NOTICE); + $haveRequest = false; // Get new time flag @@ -69,12 +69,8 @@ trigger_error(123123123,E_USER_NOTICE); $newTime = false; if ($_REQUEST['newTime'] == 'true') { $newTime = true; -echo "123456"; -exit; } - - // Get the active value if (!isset($_REQUEST['active'])) { wp_die(); @@ -94,18 +90,120 @@ exit; } // Get the reg_time entry id - if (!isset($_REQUEST['reg_time'])) { - wp_die(); - } - $regTimeId = ($_REQUEST['reg_time'] - 0); - if ($regTimeId <= 0) { - wp_die(); - } + if ($newTime) { + + // 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') { + $attendees = true; + } - // Try to get the reg_time entry - $regTime = $this->getEntry($regTimeId); - if (!$regTime) { + $regEventId = false; + if (isset($_REQUEST['event'])) { + $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) { + + // Add reg event time + $this->wpdb->insert( + GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time", + array( + 'reg_event' => $regEventId, + 'active' => $active, + 'non_time_specific' => false, + 'event_time' => 0, + 'start_datetime' => $startTime, + 'end_datetime' => $endTime, + 'all_day' => $allDay, + 'attendees' => $attendees, + 'attendee_max' => $max, + 'attendee_count' => 0, + 'attendees_pending' => 0, + 'attendees_available' => $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', // active + '%d', // non_time_specific + '%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 + ) + ); + + // Get the new reg_time record ID and return that to the AJAX call + $regTime = $this->wpdb->insert_id; + if ($regTime) { + echo $regTime; + wp_die(); + } + } + + // We failed so return 0 for the ID + echo "0"; wp_die(); + + } else { + + if (!isset($_REQUEST['reg_time'])) { + wp_die(); + } + $regTimeId = ($_REQUEST['reg_time'] - 0); + if ($regTimeId <= 0) { + wp_die(); + } + + // Try to get the reg_time entry + $regTime = $this->getEntry($regTimeId); + if (!$regTime) { + wp_die(); + } + } // re-calculate the total diff --git a/models/admin/registrations/events.php b/models/admin/registrations/events.php index b3a5b33..e16ca6c 100644 --- a/models/admin/registrations/events.php +++ b/models/admin/registrations/events.php @@ -419,10 +419,6 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent break; - - - break; - case 'dashboard': default: diff --git a/views/admin/registrations/eventDashboard.html b/views/admin/registrations/eventDashboard.html index bdf510f..93a3a2c 100644 --- a/views/admin/registrations/eventDashboard.html +++ b/views/admin/registrations/eventDashboard.html @@ -259,6 +259,7 @@ Active: All Day: + Track Attendees: Start Time: End Time: Maximum Attendees: 0 = Unlimited @@ -307,16 +308,18 @@ width: 'auto', resizable: true, open: function(event,ui){ + + // On open set the time input mask if (!timeMaskSet) { - $(".time-input").mask("X0:Y0 ZM", { + $(".time-input").mask("X0:Y0 ZM", { translation: { - 'X': { + 'X': { // Force 1st hour digit to 0 or 1 pattern: /[01]/, optional: false - }, - 'Y': { + }, + 'Y': { // force first minute digit to 0 through 5 pattern: /[012345]/, optional: false }, - 'Z': { + 'Z': { // Force AM or PM only pattern: /[AaPp]/, optional: false } }, @@ -339,6 +342,7 @@ function initFullCalendar(){ $('#eventCalendar').fullCalendar({ {if $regEvent} + // Add existing registration dates/times events: [ {$sep = ''} {if $haveRegEventTimes} @@ -358,6 +362,7 @@ backgroundColor: '#aaa', {/if} allday: {$t.all_day.value}, + attendees: {$t.attendees.value}, max: {$t.attendee_max}, count: {$t.attendee_count}, pending: {$t.attendees_pending}, @@ -369,12 +374,16 @@ {/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); @@ -383,17 +392,20 @@ $('#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: 'unlimited', - start: date.format() + ' ' + $('#dialogStartTime').val(), + 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, @@ -401,13 +413,15 @@ timeId: false }; + // If max or active is set, override the defaults if (newEvent.max > 0 ) { - newEvent.title = newEvent.max + '-0-0-' + newEvent.max + 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}", @@ -415,19 +429,28 @@ data: { action: "glm_members_admin_ajax", glm_action: "updateAvailability", + event: {$regEvent.id}, newTime: "true", active: newEvent.active, - startTime: newEvent.startTime, - endTime: newEvent.endTime, + allDay: newEvent.allDay, + attendees: newEvent.attendees, + start: newEvent.start, + end: newEvent.end, max: newEvent.max }, dataType: "text" }).done( function(newTimeId) { - newEvent.timeId = newTimeId; - - $('#eventCalendar').fullCalendar('renderEvent', newEvent, true); + // 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'); @@ -444,6 +467,9 @@ timeFormat : 'h:mma', fixedWeekCount : false, eventClick: function(calEvent, jsEvent, view) { + + $('#dialogAvailSubmit').off('click'); + $("#occurrences").dialog(); $(this).css('border-color', 'red'); @@ -451,6 +477,8 @@ $('#availabilityTitle').html(calEvent.datetime); $('#dialogRegActive').prop('checked', calEvent.active) + $('#dialogTimeAllDay').prop('checked', calEvent.allDay) + $('#dialogMaxAtt').val(calEvent.max); $('#dialogRegLine').show(); $('#dialogRegAtt').html(calEvent.count); -- 2.17.1