}
// For each recurrence
- foreach ($this->regEventData['recurrences'] as $k=>$v) {
+ foreach ($this->regEventData['recurrences'] as $recurKey=>$recurVal) {
- $this->regEventData['recurrences'][$k]['haveTimes'] = false;
+ $this->regEventData['recurrences'][$recurKey]['haveTimes'] = false;
// If we have times for this recurrence
- if ($v['times'] && count($v['times']) > 0) {
+ if ($recurVal['times'] && count($recurVal['times']) > 0) {
// Get the first and last event date/time
- $first = current($v['times']);
- $last = end($v['times']);
+ $first = current($recurVal['times']);
+ $last = end($recurVal['times']);
- $this->regEventData['recurrences'][$k]['first_time'] = $first;
- $this->regEventData['recurrences'][$k]['lastTime'] = $last;
+ $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'] ) {
// Check reg_time array
$timeSpecific = $this->regEventData['time_specific']['value'];
- foreach ($this->regEventData['reg_time'] as $k=>$v) {
+ foreach ($this->regEventData['reg_time'] as $timeKey=>$timeVal) {
// if event is time specific
if ($timeSpecific) {
// Remove entry if it's not time specific or is in the past
- if ($v['event_time'] == 0 || $v['start_datetime']['timestamp'] < time()) {
- unset($this->regEventData['reg_time'][$k]);
+ if ($timeVal['event_time'] == 0 || $timeVal['start_datetime']['timestamp'] < time()) {
+ unset($this->regEventData['reg_time'][$timeKey]);
}
// Otherwise event is non time specific
} else {
// Remove any time specific entries
- if ($v['event_time'] > 0) {
- unset($this->regEventData['reg_time'][$k]);
+ if ($timeVal['event_time'] > 0) {
+ unset($this->regEventData['reg_time'][$timeKey]);
}
}
{
$needTimesReloaded = false;
+ $message = '';
// If we've been passed a reg event id, get the configuration (with recurrence data)
if ($regEventId && $regEventId > 0) {
}
// For each recurrence
- foreach ($this->regEventData['recurrences'] as $k=>$v) {
+ foreach ($this->regEventData['recurrences'] as $recurKey=>$recurVal) {
// If we have times for this recurrence
- if ($v['times'] && count($v['times']) > 0) {
+ if ($recurVal['times'] && count($recurVal['times']) > 0) {
// If this is a time specific event
if ($this->regEventData['time_specific']['value']) {
// Check all event times for matching reg event times
- foreach ($v['times'] as $tk=>$tv) {
+ foreach ($recurVal['times'] as $eventTimeKey=>$eventTimeVal) {
$id = false;
// Check if this time from the event already exists in reg_times array
reset($this->regEventData['reg_time']);
- foreach($this->regEventData['reg_time'] as $rk=>$rv) {
- if ($rv['event_time'] == $tk) {
- $id = $rk;
- break;
+ foreach($this->regEventData['reg_time'] as $regTimeKey=>$regTimeVal) {
+ if ($regTimeVal['event_time'] == $eventTimeKey) {
+
+ // 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;
}
}
}
- // If it doesn't now, then add it
+ // If it wasn't found, then add it
if (!$id) {
$needTimesReloaded = true;
+ $message .= "<br> New dates and/or times have been added";
- $sTime = date('Y-m-d H:i:s',strtotime($tv['start_time']['datetime']));
- $eTime = date('Y-m-d H:i:s',strtotime($tv['end_time']['datetime']));
+ $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' => $tk,
+ 'event_time' => $eventTimeKey,
'start_datetime' => $sTime,
'end_datetime' => $eTime,
- 'all_day' => $tv['all_day']['value'],
+ 'all_day' => $eventTimeVal['all_day']['value'],
'attendees' => $this->regEventData['attendees']['value'],
'attendee_max' => $this->regEventData['attendee_max'],
'attendee_count' => 0,
} // each recurrence
+ // Check all reg_times we had from before to make sure they were matched with a recur time
+ $deleteList = '';
+ $deleteSep = '';
+ 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 there's anything in the delete list, purge them now and say we need a reload
+ if ($deleteList != '') {
+ $this->wpdb->query("
+ DELETE FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time
+ WHERE id IN ($deleteList)
+ ");
+ $needTimesReloaded = true;
+ $message .= '<br> Old dates and/or times have been removed';
+ }
+
// Get rid of all of the recurrence data - No longer needed
unset($this->regEventData['recurrences']);
} // not times specific
// Check if we need the times entries reloaded
+ $this->regEventData['message'] = false;
if ($needTimesReloaded) {
// Get all reg_time records for this event
$RegTime = new GlmDataRegistrationsRegTime($this->wpdb, $this->config);
$this->regEventData['reg_time'] = $RegTime->getList('T.reg_event = '.$this->regEventData['id'], 'start_datetime', true);
+ $this->regEventData['message'] = 'Dates and Times have been updated due to changes in the "Dates Schedules" for this event.'.$message;
+
+
}
// echo "<pre>".print_r($this->regEventData,1)."</pre>";
public function modelAction($actionData = false)
{
+ $messages = array();
$option = 'dashboard';
$view = false;
$numbDisplayed = false;
$regEventUpdated = false;
$regEventUpdateError = false;
$regEventAdded = false;
- $reason = false;
$regEventSample = false;
$regEventJSON = false;
$regClassesJSON = false;
case 'add':
case 'edit':
+ $problem = false;
+
// If we're adding a new reg event
if ($option == 'add') {
} else {
- $reason = "Trying to add an event that is already listed in Registrations.";
+ $messages[] = "Trying to add an event that is already listed in Registrations.";
+ $problem = true;
}
}
// If there's no problem yet, try to get the regEvent data for edit
- if ($reason == '') {
+ if (!$problem) {
if ($regEventID) {
$regEvent = $this->editEntry($regEventID);
if ($regEvent) {
$regEventFirstTime = $regEvent['firstTime'];
$regEventLastTime = $regEvent['lastTime'];
+ // if there's a user notice, add it to messages
+ if ($regEvent['message']) {
+ $messages[] = $regEvent['message'];
+ }
+
}
$view = 'eventDashboard';
// Compile template data
$templateData = array(
+ 'haveMessages' => count($messages) > 0,
+ 'messages' => $messages,
'option' => $option,
'regEventsCount' => $regEventsCount,
'haveRegEvents' => $haveRegEvents,
'regEventUpdated' => $regEventUpdated,
'regEventUpdateError' => $regEventUpdateError,
'regEventAdded' => $regEventAdded,
- 'reason' => $reason,
-
'entry' => $regEventSample,
'thisJsUrl' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_URL . '/js',
'regEventJSON' => $regEventJSON,