// 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 {
$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(
public function modelAction($actionData = false)
{
-trigger_error(123123123,E_USER_NOTICE);
+
$haveRequest = false;
// Get new time flag
$newTime = false;
if ($_REQUEST['newTime'] == 'true') {
$newTime = true;
-echo "123456";
-exit;
}
-
-
// Get the active value
if (!isset($_REQUEST['active'])) {
wp_die();
}
// 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
<tr><th id="availabilityTitle" colspan="2"><!-- item date / time goes here --></th></tr>
<tr><th style="text-align: left">Active:</th><td><input id="dialogRegActive" type="checkbox" value=""></td></tr>
<tr><th style="text-align: left">All Day:</th><td><input id="dialogTimeAllDay" type="checkbox" value=""></td></tr>
+ <tr><th style="text-align: left">Track Attendees:</th><td><input id="dialogAttendees" type="checkbox" value=""></td></tr>
<tr><th style="text-align: left">Start Time:</th><td><input id="dialogStartTime" class="glm-form-text-input-short time-input not-all-day" type="text" value=""></td></tr>
<tr><th style="text-align: left">End Time:</th><td><input id="dialogEndTime" class="glm-form-text-input-short time-input not-all-day" type="text" value=""></td></tr>
<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>
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
}
},
function initFullCalendar(){
$('#eventCalendar').fullCalendar({
{if $regEvent}
+ // Add existing registration dates/times
events: [
{$sep = ''}
{if $haveRegEventTimes}
backgroundColor: '#aaa',
{/if}
allday: {$t.all_day.value},
+ attendees: {$t.attendees.value},
max: {$t.attendee_max},
count: {$t.attendee_count},
pending: {$t.attendees_pending},
{/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);
$('#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,
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}",
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');
timeFormat : 'h:mma',
fixedWeekCount : false,
eventClick: function(calEvent, jsEvent, view) {
+
+ $('#dialogAvailSubmit').off('click');
+
$("#occurrences").dialog();
$(this).css('border-color', 'red');
$('#availabilityTitle').html(calEvent.datetime);
$('#dialogRegActive').prop('checked', calEvent.active)
+ $('#dialogTimeAllDay').prop('checked', calEvent.allDay)
+
$('#dialogMaxAtt').val(calEvent.max);
$('#dialogRegLine').show();
$('#dialogRegAtt').html(calEvent.count);