function cache_events_day($month, $day, $year) { global $eventcache, $vbulletin; $eventarray = array(); if (!empty($eventcache['holiday1'])) { if (!empty($eventcache['holiday1']["{$month}|{$day}"])) { foreach ($eventcache['holiday1']["{$month}|{$day}"] as $index => $event) { $eventarray[] =& $eventcache['holiday1']["{$month}|{$day}"]["{$index}"]; } } } if (!empty($eventcache['holiday2'])) { $dayofweek = gmdate('w', gmmktime(0, 0, 0, $month, $day, $year)) + 1; if (!empty($eventcache['holiday2']["{$dayofweek}|{$month}"])) { foreach ($eventcache['holiday2']["{$dayofweek}|{$month}"] as $index => $event) { if (cache_event_info($event, $month, $day, $year)) { $eventarray[] =& $eventcache['holiday2']["{$dayofweek}|{$month}"]["{$index}"]; } } } } if (!empty($eventcache['singleday'])) { // Check for single day events occuring on this date $dateline_from = gmmktime(0, 0, 0, $month, $day, $year); if (!empty($eventcache['singleday']["{$dateline_from}"])) { foreach ($eventcache['singleday']["{$dateline_from}"] as $index => $event) { $eventarray[] =& $eventcache['singleday']["{$dateline_from}"]["{$index}"]; } } } if (!empty($eventcache['ranged'])) { // Check for ranged events ocurring on this date $todaystart = gmmktime(0, 0, 0, $month, $day, $year); if (!empty($eventcache['ranged']["{$todaystart}"])) { foreach ($eventcache['ranged']["{$todaystart}"] as $index => $event) { $eventarray[] =& $eventcache['ranged']["{$todaystart}"]["{$index}"]; } } } if (!empty($eventcache['recurring'])) { foreach ($eventcache['recurring'] as $index => $event) { if (cache_event_info($event, $month, $day, $year)) { $eventarray[] =& $eventcache['recurring']["{$index}"]; } } } $sortarray = array(); $finalarray = array(); foreach ($eventarray as $key => $event) { if (!$event['singleday'] and !$event['recurring'] and $event['dateline_from_user'] < gmmktime(0, 0, 0, $month, $day, $year)) { $sortarray["{$key}"] = -3; } else { if ($event['holidayid']) { $sortarray["{$key}"] = -2; } else { if ($event['singleday']) { $sortarray["{$key}"] = -1; } else { $sortarray["{$key}"] = $event['dateline_from_user'] - 86400 * intval($event['dateline_from_user'] / 86400); } } } } asort($sortarray); foreach ($sortarray as $key => $time) { $finalarray[] =& $eventarray["{$key}"]; } return $finalarray; }
} else { while ($iterations < $vbulletin->options['showevents']) { $addcache = false; $todaydate = getdate($gettime); if (isset($eventinfo['holidayid']) AND $eventinfo['holidayid'] AND $eventinfo['recurring'] == 6) { if ($eventinfo['recuroption'] == "$todaydate[mon]|$todaydate[mday]") { $addcache = true; } } else if (cache_event_info($eventinfo, $todaydate['mon'], $todaydate['mday'], $todaydate['year'])) { $addcache = true; } if ($addcache) { if (!$vbulletin->options['showeventtype']) { $events["$eventid"][] = $gettime . "_$sub"; } else { $events["$gettime"][] = $eventid; } $eventcount++;
} } else { // Recurring Event # Advance start date up to the first occurence after now. if ($dateline_from <= $timenow) { $dateline_from = ceil(($timenow - $dateline_from) / 86400) * 86400 + $dateline_from; } $time_until_event = $dateline_from - $timenow; while ($time_until_event <= $event['reminder'] and $time_until_event >= 0 and !$foundevent) { if ($vbulletin->debug and VB_AREA == 'AdminCP') { echo "<br />Time until next event: " . $time_until_event / 60 / 60 . " hours"; echo "<br />Reminder Time: " . ($event['reminder'] / 60 / 60 - 0.25) . " hours"; } # Between 0 and x hours until event starts $temp = explode('-', gmdate('n-j-Y', $dateline_from)); if (cache_event_info($event, $temp[0], $temp[1], $temp[2], true, false)) { if ($vbulletin->debug and VB_AREA == 'AdminCP') { echo "<br />EVENT FOUND " . gmdate('Y-m-d h:i:s a', $dateline_from); } $foundevent = true; if ($event['lastreminder'] != $dateline_from) { #we've never sent a reminder for this event occurence $update = true; } } else { $time_until_event += 86400; $dateline_from += 86400; } if ($vbulletin->debug and VB_AREA == 'AdminCP') { echo "<hr />"; }
/** * Any checks to run immediately before saving. If returning false, the save will not take place. * * @param boolean Do the query? * * @return boolean True on success; false if an error occurred */ function pre_save($doquery = true) { if ($this->presave_called !== null) { return $this->presave_called; } if (!$this->verify_image_count('event', 'allowsmilies', 'calendar')) { return false; } if ($this->verify_datetime) { if (!checkdate($this->info['fromdate']['month'], $this->info['fromdate']['day'], $this->info['fromdate']['year']) or $this->info['type'] != 'single' and !checkdate($this->info['todate']['month'], $this->info['todate']['day'], $this->info['todate']['year'])) { $this->error('calendarbaddate'); return false; } if ($this->info['type'] != 'single') { // extract the relevant info from from_time and to_time $time_re = '#^(0?[0-9]|1[012])\\s*[:.]\\s*([0-5]\\d)(\\s*[AP]M)?|([01]\\d|2[0-3])\\s*[:.]\\s*([0-5]\\d)$#i'; // match text in field for a valid time if (preg_match($time_re, $this->info['fromtime'], $matches)) { if (count($matches) == 3) { $from_hour = intval($matches[1]); $from_minute = intval($matches[2]); $from_ampm = $matches[1] == '12' ? 'PM' : 'AM'; } else { if (count($matches) == 4) { $from_hour = intval($matches[1]); $from_minute = intval($matches[2]); $from_ampm = strtoupper(trim($matches[3])); } else { $from_hour = intval($matches[4]); $from_minute = intval($matches[5]); $from_ampm = $from_hour <= 11 ? 'AM' : 'PM'; } } } else { $this->error('calendarbadtime'); return false; } // preg match text in field for a valid time if (preg_match($time_re, $this->info['totime'], $matches)) { if (count($matches) == 3) { $to_hour = intval($matches[1]); $to_minute = intval($matches[2]); $to_ampm = $matches[1] == '12' ? 'PM' : 'AM'; } else { if (count($matches) == 4) { $to_hour = intval($matches[1]); $to_minute = intval($matches[2]); $to_ampm = strtoupper(trim($matches[3])); } else { $to_hour = intval($matches[4]); $to_minute = intval($matches[5]); $to_ampm = $to_hour <= 11 ? 'AM' : 'PM'; } } } else { $this->error('calendarbadtime'); return false; } if (($pos = strpos($this->registry->options['timeformat'], 'H')) === false) { if ($to_ampm == 'PM') { if ($to_hour >= 1 and $to_hour <= 11) { $to_hour += 12; } } else { if ($to_hour == 12) { $to_hour = 0; } } if ($from_ampm == 'PM') { if ($from_hour >= 1 and $from_hour <= 11) { $from_hour += 12; } } else { if ($from_hour == 12) { $from_hour = 0; } } } $min_offset = $this->fetch_field('utc') - intval($this->fetch_field('utc')); $from_hour -= intval($this->fetch_field('utc')); $from_minute -= intval($min_offset * 60); $to_hour -= intval($this->fetch_field('utc')); $to_minute -= intval($min_offset * 60); $dateline_to = gmmktime($to_hour, $to_minute, 0, $this->info['todate']['month'], $this->info['todate']['day'], $this->info['todate']['year']); $dateline_from = gmmktime($from_hour, $from_minute, 0, $this->info['fromdate']['month'], $this->info['fromdate']['day'], $this->info['fromdate']['year']); if ($dateline_to < $dateline_from) { $this->error('calendartodate'); return false; } require_once DIR . '/includes/functions_misc.php'; $this->set_info('occurdate', vbgmdate('Y-n-j', $dateline_from + $this->registry->userinfo['timezoneoffset'] * 3600, false, false)); } else { $dateline_to = 0; $dateline_from = gmmktime(0, 0, 0, $this->info['fromdate']['month'], $this->info['fromdate']['day'], $this->info['fromdate']['year']); require_once DIR . '/includes/functions_misc.php'; $this->set_info('occurdate', $occurdate = vbgmdate('Y-n-j', $dateline_from, false, false)); } $this->set('dateline_to', $dateline_to); $this->set('dateline_from', $dateline_from); $recuroption = ''; if ($this->info['type'] == 'recur') { $checkevent = array('eventid' => 1, 'dateline_from' => $dateline_from, 'dateline_to' => $dateline_to, 'dateline_from_user' => $dateline_from + $this->registry->userinfo['timezoneoffset'] * 3600, 'dateline_to_user' => $dateline_to + $this->registry->userinfo['timezoneoffset'] * 3600, 'recurring' => $this->fetch_field('recurring'), 'utc' => $this->fetch_field('utc')); $startday = gmmktime(0, 0, 0, gmdate('n', $checkevent['dateline_from_user']), gmdate('j', $checkevent['dateline_from_user']), gmdate('Y', $checkevent['dateline_from_user'])); $endday = gmmktime(0, 0, 0, gmdate('n', $checkevent['dateline_to_user']), gmdate('j', $checkevent['dateline_to_user']), gmdate('Y', $checkevent['dateline_to_user'])); if ($this->info['recur']['pattern'] == 1) { $recuroption = $this->info['recur']['dailybox']; } else { if ($this->info['recur']['pattern'] == 3) { if ($this->info['recur']['weeklysun']) { $daybit = 1; } if ($this->info['recur']['weeklymon']) { $daybit += 2; } if ($this->info['recur']['weeklytue']) { $daybit += 4; } if ($this->info['recur']['weeklywed']) { $daybit += 8; } if ($this->info['recur']['weeklythu']) { $daybit += 16; } if ($this->info['recur']['weeklyfri']) { $daybit += 32; } if ($this->info['recur']['weeklysat']) { $daybit += 64; } $recuroption = $this->info['recur']['weeklybox'] . '|' . $daybit; } else { if ($this->info['recur']['pattern'] == 4) { $recuroption = $this->info['recur']['monthly1'] . '|' . $this->info['recur']['monthlybox1']; } else { if ($this->info['recur']['pattern'] == 5) { $recuroption = $this->info['recur']['monthly2'] . '|' . $this->info['recur']['monthly3'] . '|' . $this->info['recur']['monthlybox2']; } else { if ($this->info['recur']['pattern'] == 6) { $recuroption = $this->info['recur']['yearly1'] . '|' . $this->info['recur']['yearly2']; } else { if ($this->info['recur']['pattern'] == 7) { $recuroption = $this->info['recur']['yearly3'] . '|' . $this->info['recur']['yearly4'] . '|' . $this->info['recur']['yearly5']; } } } } } } $checkevent['recuroption'] = $recuroption; $foundevent = false; while ($startday <= $endday) { $temp = explode('-', gmdate('n-j-Y', $startday)); if (cache_event_info($checkevent, $temp[0], $temp[1], $temp[2], 0)) { $foundevent = true; break; } $startday += 86400; } if (!$foundevent) { $this->error('calendarnorecur'); return false; } } $this->set('recuroption', $recuroption); if ($this->condition === null) { if ($query = $this->dbobject->query_first("\n\t\t\t\t\tSELECT eventid\n\t\t\t\t\tFROM " . TABLE_PREFIX . "event\n\t\t\t\t\tWHERE userid = " . intval($this->fetch_field('userid')) . "\n\t\t\t\t\t\tAND dateline_from = " . intval($this->fetch_field('dateline_from')) . "\n\t\t\t\t\t\tAND dateline_to = " . intval($this->fetch_field('dateline_to')) . "\n\t\t\t\t\t\tAND event = '" . $this->dbobject->escape_string($this->fetch_field('event')) . "'\n\t\t\t\t\t\tAND title = '" . $this->dbobject->escape_string($this->fetch_field('title')) . "'\n\t\t\t\t\t\tAND calendarid = " . intval($this->fetch_field('calendarid')) . "\n\t\t\t\t")) { $this->error('calendareventexists'); return false; } if (!$this->fetch_field('dateline')) { $this->set('dateline', TIMENOW); } } } $return_value = true; ($hook = vBulletinHook::fetch_hook('eventdata_presave')) ? eval($hook) : false; $this->presave_called = $return_value; return $return_value; }