1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
<?php
$block_name = _("Upcoming Events");
/**
* Horde_Block_Kronolith_monthlist:: Implementation of the Horde_Block API
* to display a list of calendar items grouped by month.
*
* $Horde: kronolith/lib/Block/monthlist.php,v 1.27.2.10 2008/01/14 01:54:45 chuck Exp $
*
* @package Horde_Block
*/
class Horde_Block_Kronolith_monthlist extends Horde_Block {
var $_app = 'kronolith';
function _params()
{
require_once dirname(__FILE__) . '/../base.php';
$params = array('calendar' => array('name' => _("Calendar"),
'type' => 'enum',
'default' => '__all'),
'months' => array('name' => _("Months Ahead"),
'type' => 'int',
'default' => 2),
'maxevents' => array('name' => _("Maximum number of events to display (0 = no limit)"),
'type' => 'int',
'default' => 0));
$params['calendar']['values']['__all'] = _("All Visible");
foreach (Kronolith::listCalendars() as $id => $cal) {
$params['calendar']['values'][$id] = $cal->get('name');
}
return $params;
}
/**
* The title to go in this block.
*
* @return string The title text.
*/
function _title()
{
global $registry;
return Horde::link(Horde::url($registry->getInitialPage(), true)) . _("Upcoming Events") . '</a>';
}
/**
* The content to go in this block.
*
* @return string The content
*/
function _content()
{
require_once dirname(__FILE__) . '/../base.php';
require_once KRONOLITH_BASE . '/lib/Day.php';
global $registry, $prefs;
Horde::addScriptFile('tooltip.js', 'horde', true);
$now = $_SERVER['REQUEST_TIME'];
$today = date('j');
$current_month = '';
$startDate = new Horde_Date(array('year' => date('Y'), 'month' => date('n'), 'mday' => date('j')));
$endDate = new Horde_Date(array('year' => date('Y'), 'month' => date('n') + $this->_params['months'], 'mday' => date('j') - 1));
$endDate->correct();
if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') {
$all_events = Kronolith::listEvents($startDate, $endDate, array($this->_params['calendar']));
} else {
$all_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['display_calendars']);
}
if (is_a($all_events, 'PEAR_Error')) {
return '<em>' . $all_events->getMessage() . '</em>';
}
$html = '<link href="' . Horde::applicationUrl('themes/categoryCSS.php') . '" rel="stylesheet" type="text/css" />';
/* How many days do we need to check. */
$days = Date_Calc::dateDiff($startDate->mday, $startDate->month, $startDate->year,
$endDate->mday, $endDate->month, $endDate->year);
/* Loop through the days. */
$totalevents = 0;
for ($i = 0; $i < $days; ++$i) {
$day = new Kronolith_Day($startDate->month, $today + $i);
$today_stamp = $day->getStamp();
if (empty($all_events[$today_stamp])) {
continue;
}
if (!empty($this->_params['maxevents']) &&
$totalevents >= $this->_params['maxevents']) {
break;
}
$firstevent = true;
/* Output month header. */
if ($current_month != $day->month) {
$current_month = strftime('%m', $today_stamp);
$html .= '<tr><td colspan="4" class="control"><strong>' . strftime('%B', $today_stamp) . '</strong></td></tr>';
}
$today12am = mktime(0, 0, 0, $day->month, $day->mday, $day->year);
$tomorrow12am = mktime(0, 0, 0, $day->month, $day->mday + 1, $day->year);
foreach ($all_events[$today_stamp] as $event) {
if ($event->recurs()) {
$event->start = new Horde_Date(array('hour' => $event->start->hour, 'min' => $event->start->min, 'sec' => $event->start->sec,
'month' => $day->month, 'mday' => $day->mday, 'year' => $day->year));
$event->end = new Horde_Date($event->start->timestamp() + $event->durMin * 60);
} else {
if ($event->start->timestamp() < $today12am) {
$event->start = new Horde_Date($today12am);
}
if ($event->end->timestamp() >= $tomorrow12am) {
$event->end = new Horde_Date($tomorrow12am);
}
}
if ($event->end->timestamp() < $now ||
($prefs->getValue('summary_alarms') && !$event->alarm)) {
continue;
}
if ($firstevent) {
$html .= '<tr><td class="text" valign="top" align="right"><strong>';
if ($day->isToday()) {
$html .= _("Today");
} elseif ($day->isTomorrow()) {
$html .= _("Tomorrow");
} else {
$html .= date('j', $today_stamp);
}
$html .= '</strong> </td>';
$firstevent = false;
} else {
$html .= '<tr><td class="text"> </td>';
}
$html .= '<td class="text" nowrap="nowrap" valign="top">';
if ($event->start->timestamp() < $now && $event->end->timestamp() > $now) {
$html .= '<strong>' . $event->getLocation() . '</strong>';
} else {
$html .= $event->getLocation();
}
$html .= '</td><td class="text"> </td>' .
'<td class="block-eventbox category' . md5($event->getCategory()) . '" valign="top">';
if ($event->start->timestamp() < $now && $event->end->timestamp() > $now) {
$html .= '<strong>';
}
if (isset($event->eventID)) {
$html .= $event->getLink();
} elseif (isset($this->external)) {
$html .= Horde::link(Horde::url($registry->link($this->external . '/show', $event->external_params),
true), $event->getTitle()) . $event->getTitle() . '</a>';
} else {
$html .= $event->getTitle();
}
if ($event->start->timestamp() < $now && $event->end->timestamp() > $now) {
$html .= '</strong>';
}
$html .= '</td></tr>';
$totalevents++;
}
}
if (empty($html)) {
return '<em>' . _("No events to display") . '</em>';
}
return '<table cellspacing="0" width="100%">' . $html . '</table>';
}
}
|