From 4e06d2fb2e124334b8f32cec32087983a21eef06 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Thu, 14 Dec 2017 15:20:21 -0500 Subject: [PATCH] Fixed problems with time editing in admin reg event dashboard and added testing for registrants with missing times for registation page. --- classes/data/dataRegEvent.php | 9 ++- classes/regCartSupport.php | 4 +- models/admin/ajax/updateAvailability.php | 58 ++++++++++--------- models/admin/registrations/events.php | 2 +- models/front/registrations/registration.php | 4 +- views/admin/registrations/eventDashboard.html | 52 ++++++++++++++--- 6 files changed, 88 insertions(+), 41 deletions(-) diff --git a/classes/data/dataRegEvent.php b/classes/data/dataRegEvent.php index 8ad92ef..35c6039 100644 --- a/classes/data/dataRegEvent.php +++ b/classes/data/dataRegEvent.php @@ -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'; diff --git a/classes/regCartSupport.php b/classes/regCartSupport.php index 56e4af0..be8a4f0 100644 --- a/classes/regCartSupport.php +++ b/classes/regCartSupport.php @@ -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; } diff --git a/models/admin/ajax/updateAvailability.php b/models/admin/ajax/updateAvailability.php index fb0748e..037aae4 100644 --- a/models/admin/ajax/updateAvailability.php +++ b/models/admin/ajax/updateAvailability.php @@ -84,6 +84,18 @@ $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(); @@ -93,19 +105,15 @@ 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') { @@ -117,23 +125,6 @@ $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) { @@ -196,8 +187,11 @@ echo "0"; wp_die(); + + // Otherwise this should be an update } else { + // Get the tiem entry ID if (!isset($_REQUEST['reg_time'])) { wp_die(); } @@ -216,11 +210,18 @@ // 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 ), @@ -228,6 +229,9 @@ array( '%d', '%d', + '%s', + '%s', + '%d', '%d' ), array( '%d' ) diff --git a/models/admin/registrations/events.php b/models/admin/registrations/events.php index 9257895..eec5a41 100644 --- a/models/admin/registrations/events.php +++ b/models/admin/registrations/events.php @@ -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') { diff --git a/models/front/registrations/registration.php b/models/front/registrations/registration.php index fcf1db8..7dd2a36 100644 --- a/models/front/registrations/registration.php +++ b/models/front/registrations/registration.php @@ -116,7 +116,7 @@ // 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; } @@ -134,7 +134,7 @@ 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; diff --git a/views/admin/registrations/eventDashboard.html b/views/admin/registrations/eventDashboard.html index 2f7440e..788331c 100644 --- a/views/admin/registrations/eventDashboard.html +++ b/views/admin/registrations/eventDashboard.html @@ -246,7 +246,7 @@ Start Time: End Time: {if $regEvent.time_specific.value} - Maximum Attendees: 0 = Unlimited + Maximum Attendees: 0 = Unlimited Registered Attendees: Pending in Carts: Available for Registration: @@ -350,7 +350,7 @@ {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}, @@ -473,6 +473,8 @@ defaultDate : '{$defaultCalDate}', timeFormat : 'h:mma', fixedWeekCount : false, + + // Click on an event in the calendar eventClick: function(calEvent, jsEvent, view) { $('#dialogAvailSubmit').off('click'); @@ -490,9 +492,14 @@ $('#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); @@ -527,14 +534,45 @@ } 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 + "®_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} -- 2.17.1