Retrieve each calendar's events seperately.
case 'ListEvents':
$start = new Horde_Date(Util::getFormData('start'));
$end = new Horde_Date(Util::getFormData('end'));
- $dates = Kronolith::listEvents($start, $end);
- if (is_a($dates, 'PEAR_Error')) {
- $notification->push($dates, 'horde.error');
+ $cal = Util::getFormData('cal');
+ list($driver, $calendar) = explode('|', $cal);
+ $kronolith_driver = Kronolith::getDriver($driver, $calendar);
+ $events = $kronolith_driver->listEvents($start, $end, true, false, true);
+ if (is_a($events, 'PEAR_Error')) {
+ $notification->push($events, 'horde.error');
$result = false;
} else {
$result = new stdClass;
+ $result->cal = $cal;
$result->sig = $start->dateString() . $end->dateString();
- foreach ($dates as $date => $events) {
- foreach ($events as $id => $event) {
- $result->events[$date][$id] = $event->toJSON();
- }
+ if (count($events)) {
+ $result->events = $events;
}
}
break;
KronolithCore = {
// Vars used and defaulting to null/false:
// DMenu, alertrequest, inAjaxCallback, is_logout, onDoActionComplete,
- // eventForm, eventsLoading
+ // eventForm
view: '',
calendars: [],
ecache: {},
efifo: {},
+ eventsLoading: $H(),
date: new Date(),
doActionOpts: {
},
/**
+ * Rebuilds the list of calendars.
*/
- _loadEvents: function(firstDay, lastDay, callback, calendar)
+ updateCalendarList: function()
{
- this.eventsLoading = firstDay.dateString() + lastDay.dateString();
- this.doAction('ListEvents', { start: firstDay.dateString(), end: lastDay.dateString() }, callback);
+ var internal = $H(Kronolith.conf.calendars.internal),
+ remote = $H(Kronolith.conf.calendars.remote),
+ my = 0, shared = 0, div;
+
+ internal.each(function(cal) {
+ if (cal.value.owner) {
+ my++;
+ div = $('kronolithMyCalendars');
+ } else {
+ shared++;
+ div = $('kronolithSharedCalendars');
+ }
+ div.appendChild(new Element('DIV', { 'class': cal.value.show ? 'kronolithCalOn' : 'kronolithCalOff' }).setStyle({ backgroundColor: cal.value.bg, color: cal.value.fg }).update(cal.value.name));
+ });
+ if (my) {
+ $('kronolithMyCalendars').show();
+ } else {
+ $('kronolithMyCalendars').hide();
+ }
+ if (shared) {
+ $('kronolithSharedCalendars').show();
+ } else {
+ $('kronolithSharedCalendars').hide();
+ }
+
+ remote.each(function(cal) {
+ $('kronolithRemoteCalendars').appendChild(new Element('DIV', { 'class': cal.value.show ? 'kronolithCalOn' : 'kronolithCalOff' }).setStyle({ backgroundColor: cal.value.bg, color: cal.value.fg }).update(cal.value.name));
+ });
+ if (remote.size()) {
+ $('kronolithRemoteCalendars').show();
+ } else {
+ $('kronolithRemoteCalendars').hide();
+ }
+ },
+
+ /**
+ */
+ _loadEvents: function(firstDay, lastDay, callback, calendars)
+ {
+ var start = firstDay.dateString(), end = lastDay.dateString(),
+ driver, calendar;
+ if (typeof calendars == 'undefined') {
+ calendars = Kronolith.conf.calendars;
+ }
+ calendars = $H(calendars);
+ calendars.each(function(type) {
+ switch (type.key) {
+ case 'internal':
+ driver = '';
+ break;
+ case 'external':
+ driver = 'Horde';
+ break;
+ case 'remote':
+ driver = 'Ical';
+ break;
+ case 'holiday':
+ driver = 'Holiday';
+ break;
+ }
+ $H(type.value).each(function(cal) {
+ if (cal.value.show) {
+ calendar = driver + '|' + cal.key;
+ this.eventsLoading[calendar] = start + end;
+ this.doAction('ListEvents', { start: start, end: end, cal: calendar }, callback);
+ }
+ }, this);
+ }, this);
},
/**
var div;
// Check if this is the still the result of the most current request.
- if (r.response.sig != this.eventsLoading) {
+ if (r.response.sig != this.eventsLoading[r.response.cal]) {
return;
}
/* Onload function. */
onDomLoad: function()
{
- KronolithCore.init();
+ this.init();
if (Horde.dhtmlHistory.initialize()) {
Horde.dhtmlHistory.addListener(this.go.bind(this));
}
+ this.updateCalendarList();
+
/* Initialize the starting page if necessary. addListener() will have
* already fired if there is a current location so only do a go()
* call if there is no current location. */
* $startDate - $endDate range.
* @param boolean $hasAlarm Only return events with alarms? Has no
* effect in this driver.
+ * @param boolean $json Store the results of the events'
+ * toJSON() method?
*
* @return array Events in the given time range.
*/
public function listEvents($startDate = null, $endDate = null,
- $showRecurrence = false, $hasAlarm = false)
+ $showRecurrence = false, $hasAlarm = false,
+ $json = false)
{
if (!class_exists('Date_Holidays')) {
Horde::logMessage('Support for Date_Holidays has been enabled but the package seems to be missing.',
$events = $this->_getEvents($dh, $startDate, $endDate);
foreach ($events as $event) {
Kronolith::addEvents($results, $event, $startDate, $endDate,
- $showRecurrence);
+ $showRecurrence, $json);
}
}
* recurring events once inside the
* $startDate - $endDate range.
* @param boolean $hasAlarm Only return events with alarms?
+ * @param boolean $json Store the results of the events'
+ * toJSON() method?
*
* @return array Events in the given time range.
*/
public function listEvents($startDate = null, $endDate = null,
- $showRecurrence = false, $hasAlarm = false)
+ $showRecurrence = false, $hasAlarm = false,
+ $json = false)
{
list($this->api, $category) = explode('/', $this->_calendar, 2);
if (!$this->_params['registry']->hasMethod($this->api . '/listTimeObjects')) {
}
Kronolith::addEvents($results, $event, $startDate,
- $endDate, $showRecurrence);
+ $endDate, $showRecurrence, $json);
}
return $results;
* recurring events once inside the
* $startDate - $endDate range.
* @param boolean $hasAlarm Only return events with alarms?
+ * @param boolean $json Store the results of the events'
+ * toJSON() method?
*
* @return array Events in the given time range.
*/
public function listEvents($startDate = null, $endDate = null,
- $showRecurrence = false, $hasAlarm = false)
+ $showRecurrence = false, $hasAlarm = false,
+ $json = false)
{
$data = $this->_getRemoteCalendar();
if (is_a($data, 'PEAR_Error')) {
$timestamp = $exceptions[$event->getUID()][$event->getSequence()];
$events[$key]->recurrence->addException(date('Y', $timestamp), date('m', $timestamp), date('d', $timestamp));
Kronolith::addEvents($results, $event, $startDate, $endDate,
- $showRecurrence);
+ $showRecurrence, $json);
}
}
* recurring events once inside the
* $startDate - $endDate range.
* @param boolean $hasAlarm Only return events with alarms?
+ * @param boolean $json Store the results of the events'
+ * toJSON() method?
*
* @return array Events in the given time range.
*/
public function listEvents($startDate = null, $endDate = null,
- $showRecurrence = false, $hasAlarm = false)
+ $showRecurrence = false, $hasAlarm = false,
+ $json = false)
{
$result = $this->synchronize();
if (is_a($result, 'PEAR_Error')) {
}
Kronolith::addEvents($events, $event, $startDate, $endDate,
- $showRecurrence);
+ $showRecurrence, $json);
}
return $events;
* recurring events once inside the
* $startDate - $endDate range.
* @param boolean $hasAlarm Only return events with alarms?
+ * @param boolean $json Store the results of the events'
+ * toJSON() method?
*
* @return array Events in the given time range.
*/
public function listEvents($startDate = null, $endDate = null,
- $showRecurrence = false, $hasAlarm = false)
+ $showRecurrence = false, $hasAlarm = false,
+ $json = false)
{
if (is_null($startDate)) {
$startDate = new Horde_Date(array('mday' => 1,
$results = array();
foreach ($events as $id) {
Kronolith::addEvents($results, $this->getEvent($id), $startDate,
- $endDate, $showRecurrence);
+ $endDate, $showRecurrence, $json);
}
return $results;
// Turn debugging on?
'debug' => !empty($conf['js']['debug']),
);
+ foreach ($GLOBALS['all_calendars'] as $id => $calendar) {
+ $owner = $calendar->get('owner') == Auth::getAuth();
+ $code['conf']['calendars']['internal'][$id] = array(
+ 'name' => ($owner ? '' : '[' . Auth::removeHook($calendar->get('owner')) . '] ')
+ . $calendar->get('name'),
+ 'owner' => $owner,
+ 'fg' => Kronolith::foregroundColor($calendar),
+ 'bg' => Kronolith::backgroundColor($calendar),
+ 'show' => in_array($id, $GLOBALS['display_calendars']));
+ }
+ foreach ($GLOBALS['all_external_calendars'] as $api => $categories) {
+ foreach ($categories as $id => $name) {
+ $calendar = $api . '/' . $id;
+ $code['conf']['calendars']['external'][$calendar] = array(
+ 'name' => $name,
+ 'api' => $GLOBALS['registry']->get('name', $GLOBALS['registry']->hasInterface($api)),
+ 'show' => in_array($calendar, $GLOBALS['display_external_calendars']));
+ }
+ }
+ foreach ($GLOBALS['all_remote_calendars'] as $calendar) {
+ $code['conf']['calendars']['remote'][$calendar['url']] = array(
+ 'name' => $calendar['name'],
+ 'fg' => Kronolith::foregroundColor($calendar),
+ 'bg' => Kronolith::backgroundColor($calendar),
+ 'show' => in_array($calendar['url'], $GLOBALS['display_remote_calendars']));
+ }
/* Gettext strings used in core javascript files. */
$code['text'] = array_map('addslashes', array(
* @access private
*/
public static function addEvents(&$results, &$event, $startDate, $endDate,
- $showRecurrence)
+ $showRecurrence, $json)
{
if ($event->recurs() && $showRecurrence) {
/* Recurring Event. */
if (!$event->recurrence->hasException($event->start->year,
$event->start->month,
$event->start->mday)) {
- Kronolith::addCoverDates($results, $event, $event->start, $event->end);
+ Kronolith::addCoverDates($results, $event, $event->start, $event->end, $json);
}
/* Start searching for recurrences from the day after it
$nextEnd->mday += $diff[2];
$nextEnd->hour += $diff[3];
$nextEnd->min += $diff[4];
- Kronolith::addCoverDates($results, $event, $next, $nextEnd);
+ Kronolith::addCoverDates($results, $event, $next, $nextEnd, $json);
}
$next = $event->recurrence->nextRecurrence(
array('year' => $next->year,
'month' => $eventEnd->month, 'mday' => $eventEnd->mday, 'year' => $eventEnd->year));
}
- $results[$loopDate->dateString()][$addEvent->getId()] = $addEvent;
+ $results[$loopDate->dateString()][$addEvent->getId()] = $json ? $addEvent->toJSON() : $addEvent;
}
$loopDate = new Horde_Date(
* @param Horde_Date $eventStart The event's start at the actual
* recurrence.
* @param Horde_Date $eventEnd The event's end at the actual recurrence.
+ * @param boolean $json Store the results of the events' toJSON()
+ * method?
*/
public static function addCoverDates(&$results, $event, $eventStart,
- $eventEnd)
+ $eventEnd, $json)
{
$i = $eventStart->mday;
$loopDate = new Horde_Date(array('month' => $eventStart->month,
$addEvent = clone $event;
$addEvent->start = $eventStart;
$addEvent->end = $eventEnd;
- $results[$loopDate->dateString()][$addEvent->getId()] = $addEvent;
+ $results[$loopDate->dateString()][$addEvent->getId()] = $json ? $addEvent->toJSON() : $addEvent;
}
$loopDate = new Horde_Date(
array('month' => $eventStart->month,
/* Make sure all the remote calendars still exist. */
$_temp = $GLOBALS['display_remote_calendars'];
$GLOBALS['display_remote_calendars'] = array();
- $_all = @unserialize($GLOBALS['prefs']->getValue('remote_cals'));
- if (is_array($_all)) {
- foreach ($_all as $id) {
- if (in_array($id['url'], $_temp)) {
- $GLOBALS['display_remote_calendars'][] = $id['url'];
- }
+ $GLOBALS['all_remote_calendars'] = @unserialize($GLOBALS['prefs']->getValue('remote_cals'));
+ if (!is_array($GLOBALS['all_remote_calendars'])) {
+ $GLOBALS['all_remote_calendars'] = array();
+ }
+ foreach ($GLOBALS['all_remote_calendars'] as $id) {
+ if (in_array($id['url'], $_temp)) {
+ $GLOBALS['display_remote_calendars'][] = $id['url'];
}
}
$GLOBALS['prefs']->setValue('display_remote_cals', serialize($GLOBALS['display_remote_calendars']));
<?php echo _("My Calendars") ?>
</h3>
- <?php if (count($my_calendars)): ?>
- <div class="kronolithCalendars">
- <?php foreach ($my_calendars as $id => $cal): ?>
- <div class="<?php echo (in_array($id, $display_calendars)) ? 'kronolithCalOn' : 'kronolithCalOff' ?> full" style="background-color:<?php echo Kronolith::backgroundColor($cal) ?>;color:<?php echo Kronolith::foregroundColor($cal) ?>"><?php echo htmlspecialchars($cal->get('name')) ?></div>
- <?php endforeach; ?>
+ <div id="kronolithMyCalendars" class="kronolithCalendars" style="display:none">
</div>
- <?php endif; ?>
<h3>
<a href="#" class="kronolithAdd">+</a>
<?php echo _("Shared Calendars") ?>
</h3>
- <?php if (count($shared_calendars)): ?>
- <div class="kronolithCalendars">
- <?php foreach ($shared_calendars as $id => $cal): ?>
- <div class="<?php echo (in_array($id, $display_calendars)) ? 'kronolithCalOn' : 'kronolithCalOff' ?> full" style="background-color:<?php echo Kronolith::backgroundColor($cal) ?>;color:<?php echo Kronolith::foregroundColor($cal) ?>"><?php echo htmlspecialchars($cal->get('name')) ?></div>
- <?php endforeach; ?>
+ <div id="kronolithSharedCalendars" class="kronolithCalendars" style="display:none">
</div>
- <?php endif; ?>
<h3>
<a href="#" class="kronolithAdd">+</a>
<?php echo _("Remote Calendars") ?>
</h3>
- <?php if (count($remote_calendars)): ?>
- <div class="kronolithCalendars">
- <?php foreach ($remote_calendars as $id => $cal): ?>
- <div class="<?php echo (in_array($id, $display_calendars)) ? 'kronolithCalOn' : 'kronolithCalOff' ?> full" style="background-color:<?php echo Kronolith::backgroundColor($cal) ?>;color:<?php echo Kronolith::foregroundColor($cal) ?>"><?php echo htmlspecialchars($cal['name']) ?></div>
- <?php endforeach; ?>
+ <div id="kronolithRemoteCalendars" class="kronolithCalendars" style="display:none">
</div>
- <?php endif; ?>
<div id="kronolithMinical">
<table cellspacing="1" cellpadding="0" border="0">
<script type="text/javascript">
- function toggleTags(domid)
- {
- $('tag-show_' + domid).toggle();
- $('tag-hide_' + domid).toggle();
- $('tagnode_' + domid).toggle();
- }
+function toggleTags(domid)
+{
+ $('tag-show_' + domid).toggle();
+ $('tag-hide_' + domid).toggle();
+ $('tagnode_' + domid).toggle();
+}
</script>
<?php
Horde::addScriptFile('QuickFinder.js', 'horde', true);
$info_img = Horde::img('info_icon.png', _("Calendar Information"), array('class' => 'calendar-info'), $registry->getImageDir('horde'));
-$remote_calendars = @unserialize($prefs->getValue('remote_cals'));
$current_user = Auth::getAuth();
$my_calendars = array();
$shared_calendars = array();
</ul>
<?php endif; ?>
-<?php if (count($remote_calendars)): ?>
+<?php if (count($GLOBALS['all_remote_calendars'])): ?>
<h4><?php echo _("Remote Calendars:") ?></h4>
<ul id="remotecalendars">
-<?php foreach ($remote_calendars as $id => $cal): ?>
+<?php foreach ($GLOBALS['all_remote_calendars'] as $id => $cal): ?>
<li<?php echo Kronolith::getCSSColors($cal) ?>><label><input type="checkbox" class="checkbox" name="display_cal[]" value="remote_<?php echo htmlspecialchars($cal['url']) ?>"<?php echo (in_array($cal['url'], $display_remote_calendars) ? ' checked="checked"' : '') . ' /> ' . htmlspecialchars($cal['name']) ?></label> <?php echo $info_img ?></li>
<?php endforeach; ?>
</ul>