/common/calendar.php
PHP | 170 lines | 147 code | 23 blank | 0 comment | 20 complexity | cd2f6098171e609d9b3165c6b17ab6c7 MD5 | raw file
- <?
- define('CAN_EDIT', $prefs['calendar.edit']);
- $m = idate('n');
- $y = idate('Y');
- if (preg_match(
- '/\/(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\w*-([0-9]{4})\b/i',
- $_SERVER['REQUEST_URI'], $parts
- )) {
- $months = array(
- 'jan' => 1, 'feb' => 2, 'mar' => 3, 'apr' => 4, 'may' => 5, 'jun' => 6,
- 'jul' => 7, 'aug' => 8, 'sep' => 9, 'oct' => 10, 'nov' => 11, 'dec' => 12
- );
- $m = $months[strtolower($parts[1])];
- $y = (int)($parts[2]);
- unset($parts);
- }
- $d = mktime(0, 0, 0, $m, 1, $y);
- $firstShown = mktime(0, 0, 0, idate('m') - 1, 1, idate('Y'));
- $lastShown = mktime(0, 0, 0, idate('m'), 1, idate('Y') + 1);
- if ($d < $firstShown) {
- header('Location: '.CALENDAR_URL);
- exit;
- } elseif ($d > $firstShown) {
- $prev = mktime(0, 0, 0, $m - 1, 1, $y);
- }
- if ($d > $lastShown) {
- header('Location: '.CALENDAR_URL);
- exit;
- } elseif ($d < $lastShown) {
- $next = mktime(0, 0, 0, $m + 1, 1, $y);
- }
- unset($firstShown, $lastShown);
- $start = mktime(0, 0, 0, $m, 1, $y);
- $t_start = idate('t', $start);
- $w_start = idate('w', $start);
- $i_start = mktime(0, 0, 0, idate('m', $start), 1 - $w_start, idate('Y', $start));
- $end = mktime(0, 0, 0, $m + 1, 0, $y);
- $w_end = idate('w', $end);
- $i_end = mktime(0, 0, 0, idate('m', $start), $t_start + 7 - $w_end, idate('Y', $start));
- $pagetitle = date('F Y', $d);
- if ($prev)
- $extraHeadTags[] = '<link rel="prev" href="'.CALENDAR_URL.'/'.date('F-Y', $prev).'" />';
- if ($next)
- $extraHeadTags[] = '<link rel="next" href="'.CALENDAR_URL.'/'.date('F-Y', $next).'" />';
- $extraHeadTags[] = '<link rel="stylesheet" href="/common/tools/darkbox.css" type="text/css" />';
- $extraFootTags[] = '<script src="/common/tools/extend.js" type="text/javascript"></script>';
- $extraFootTags[] = '<script src="/common/tools/xhr.js" type="text/javascript"></script>';
- $extraFootTags[] = '<script src="/common/tools/contentbox.js" type="text/javascript"></script>';
- $extraFootTags[] = '<script src="/common/calendar.js" type="text/javascript"></script>';
- if (CAN_EDIT) {
- $extraFootTags[] = '<script src="/common/tools/date.js" type="text/javascript"></script>';
- $extraFootTags[] = '<script src="/common/tools/dragdrop.js" type="text/javascript"></script>';
- $extraFootTags[] = '<script src="/admin/inline/calendar.js" type="text/javascript"></script>';
- }
- require_once 'header.inc';
- if (CAN_EDIT) {
- echo '<div class="editbuttonsurround">';
- echo '<button type="button" class="editbutton" onclick="newEvent();" style="top: -30px">';
- echo '<span class="icon icon_add">Add Event</span>';
- echo '</button>';
- echo '</div>';
- }
- echo '<div id="calendarheader">';
- if ($prev) {
- echo '<a href="'.CALENDAR_URL.'/'.date('F-Y', $prev).'" rel="prev">'.
- date('F Y', $prev).'</a>';
- }
- if ($next) {
- echo '<a href="'.CALENDAR_URL.'/'.date('F-Y', $next).'" rel="next">'.
- date('F Y', $next).'</a>';
- }
- echo '<h1>'.date('F Y', $d).'</h1>';
- echo '</div>';
- $events = array();
- foreach (Events::SelectEventsByDate($i_start, $i_end) as $event) {
- $eventStart = strtotime($event['start']);
- $eventEnd = strtotime($event['end']);
- $eventDate = mktime(0, 0, 0, idate('m', $eventStart), idate('d', $eventStart), idate('Y', $eventStart));
- do {
- if (!isset($events[$eventDate])) {
- $events[$eventDate] = array();
- }
- $events[$eventDate][] = $event;
- $eventDate = mktime(0, 0, 0, idate('m', $eventDate), idate('d', $eventDate) + 1, idate('Y', $eventDate));
- } while ($eventDate < $eventEnd);
- }
- unset($event, $eventStart, $eventEnd, $eventDate);
- echo '<table cellspacing="0" cellpadding="0" id="calendar" data-first="'.
- date('Y-m-d', mktime(0, 0, 0, $m, 1 - $w_start, $y)).'">';
- echo '<thead>'.
- '<tr>'.
- '<th>Sunday</th>'.
- '<th>Monday</th>'.
- '<th>Tuesday</th>'.
- '<th>Wednesday</th>'.
- '<th>Thursday</th>'.
- '<th>Friday</th>'.
- '<th>Saturday</th>'.
- '</tr>'.
- '</thead>';
- echo '<tfoot>'.
- '<tr>'.
- '<th>Sunday</th>'.
- '<th>Monday</th>'.
- '<th>Tuesday</th>'.
- '<th>Wednesday</th>'.
- '<th>Thursday</th>'.
- '<th>Friday</th>'.
- '<th>Saturday</th>'.
- '</tr>'.
- '</tfoot>';
- echo '<tbody>';
- for ($i = 1 - $w_start; $i <= $t_start + 6 - $w_end; $i++) {
- $today = mktime(0, 0, 0, $m, $i, $y);
- if (idate('w', $today) == 0) {
- echo '<tr>';
- }
- $classname = 'date';
- if ($i <= 0 || $i > $t_start) {
- $classname .= ' differentmonth';
- } elseif (date('Y-m-d', $today) == date('Y-m-d')) {
- $classname .= ' today';
- }
- echo '<td class="'.$classname.'">';
- echo '<div class="dateinner">';
- echo '<div class="datemarker">'.date('j', $today).'</div>';
- if (isset($events[$today])) {
- echo '<ul class="events">';
- foreach ($events[$today] as $event) {
- printf(
- '<li><a href="%s" data-id="%u">%s</a></li>',
- CALENDAR_URL.'/events/'.substr($event['start'], 0, 10).'/'.$event['uri'],
- $event['id'],
- htmlSafe($event['title'])
- );
- }
- echo '</ul>';
- }
- echo '</div>';
- echo '</td>';
- if (idate('w', $today) == 6) {
- echo '</tr>';
- }
- }
- echo '</tbody>';
- echo '</table>';
- require_once 'footer.inc';