File: api.php

package info (click to toggle)
kronolith 1.1.4-2sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,212 kB
  • ctags: 1,074
  • sloc: php: 4,187; sh: 724; xml: 522; makefile: 96; sql: 42; perl: 20
file content (153 lines) | stat: -rw-r--r-- 7,097 bytes parent folder | download
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
<?php
/**
 * Kronolith external API interface.
 *
 * $Horde: kronolith/lib/api.php,v 1.28.2.9 2003/04/06 14:07:52 jan Exp $
 *
 * This file defines Kronolith's external API interface. Other
 * applications can interact with Kronolith through this API.
 */

// Find the base file paths for Kronolith
@define('KRONOLITH_BASE', dirname(__FILE__) . '/..');

function kronolithSummary()
{
    require_once dirname(__FILE__) . '/base.php';
    require_once KRONOLITH_BASE . '/lib/Day.php';

    global $prefs, $registry;

    $html  = '<table border="0" cellpadding="2" cellspacing="0" width="100%"><tr><td class="header">';
    $html .= Horde::link(Horde::url($registry->getInitialPage(), true), $registry->getParam('name'), 'header') . $registry->getParam('name') . '</a> - ';
    $html .= Horde::link(Horde::applicationUrl('addevent.php', true), _("New Event"), 'smallheader') . Horde::img('new.gif', 'alt="' . _("New Event") . '"') . _("New Event") . '</a>';
    $html .= '</td></tr><tr><td class="summarytext"><table border="0" cellpadding="0" cellspacing="0">';

    $now = time();
    $colors = Kronolith::categoryColors();
    $startDate = Kronolith::timestampToObject(mktime(0, 0, 0));
    $endDate = Kronolith::timestampToObject(mktime(0, 0, 0, date('n'),
                                                   date('j') + $prefs->getValue('summary_days')));
    $allevents = Kronolith::listEvents($startDate, $endDate);

    for ($i = date('j'); $i < date('j') + $prefs->getValue('summary_days'); $i++) {
        $day = new Kronolith_Day(date('n'), $i);

        if (empty($allevents[$day->getStamp()])) {
            continue;
        }

        $events = &$allevents[$day->getStamp()];

        $firstevent = true;
        $htmldays = array();

        $today12am = mktime(0, 0, 0, $day->month, $day->mday, $day->year);
        $tomorrow12am = mktime(0, 0, 0, $day->month, $day->mday + 1, $day->year);
        foreach ($events as $event) {
            if (!$event->hasRecurType(KRONOLITH_RECUR_NONE)) {
                $event->startTimestamp = mktime($event->start->hour, $event->start->min, $event->start->sec, $day->month, $day->mday, $day->year);
                $event->endTimestamp = $event->startTimestamp + $event->durMin * 60;
            } else {
                if ($event->startTimestamp < $today12am) {
                    $event->startTimestamp = $today12am;
                }
                if ($event->endTimestamp >= $tomorrow12am) {
                    $event->endTimestamp = $tomorrow12am;
                }
            }
            if ($event->endTimestamp < $now) continue;
            if ($prefs->getValue('summary_alarms') && !$event->alarm) continue;
            if ($firstevent) {
                $html .= '<tr><td colspan="3" class="text"><b>';
                if ($day->isToday()) {
                    $html .= _("Today");
                } elseif ($day->isTomorrow()) {
                    $html .= _("Tomorrow");
                } else {
                    $html .= strftime($prefs->getValue('date_format'), $day->getStamp());
                }
                $html .= '</b></td></tr>';
                $firstevent = false;
            }
            $htmlday = '<tr><td class="text" nowrap="nowrap" valign="top">';
            if ($event->startTimestamp < $now && $event->endTimestamp > $now) {
                $htmlday .= '<b>';
            }

            /* The following check to make sure the start time is not
               12AM was changed to use the getStartDate function to
               get the startTimestamp hour and min instead of using
               start->hour and start->min. When using the SQL driver
               this change properly lists a multiday event as 'All
               day' if it spans the entire day. It shouldn't affect
               the MCAL driver since in the case of the MCAL driver
               the startTimestamp hour and min are the same as
               start->hour and start->min. */
            if ($event->getStartDate('G') != 0 ||
                $event->getStartDate('i') != 0 ||
                (($event->endTimestamp - $event->startTimestamp) % (24 * 60 * 60)) != 0) {
                if ($prefs->getValue('twentyFour')) {
                    $time  = date('G:i', $event->startTimestamp) . '-';
                    $time .= date('G:i', $event->endTimestamp);
                } else {
                    $time  = date('g:i A', $event->startTimestamp) . '-';
                    $time .= date('g:i A', $event->endTimestamp);
                }
            } else {
                $time = _("All day event");
            }

            $text = $event->getTitle();
            if ($location = $event->getLocation()) {
                $text .= ' (' . $location . ')';
            }
            if (isset($event->eventID)) {
                $htmlday .= $time;
            } elseif (isset($event->taskID)) {
                $htmlday .= Horde::link(Horde::url($registry->link('tasks/show',
                                                                   array('task' => $event->taskID)),
                                                   $event->title)) . $time . '</a>';
            } else {
                $htmlday .= $time;
            }
            if ($event->startTimestamp < $now && $event->endTimestamp > $now) {
                $htmlday .= '</b>';
            }

            $categoryColor = isset($colors[$event->getCategory()]) ? $colors[$event->getCategory()] : '#ccccff' ;
            $htmlday .= '</td><td class="text">&nbsp;&nbsp;&nbsp;</td>';
            $htmlday .= '<td class="month-eventbox" style="background-color: ' . $categoryColor . '; ' ;
            $htmlday .= 'border-color: ' . Kronolith::borderColor($categoryColor) . '" ' ;
            $htmlday .= 'onmouseover="javascript:style.backgroundColor=\'' . Kronolith::modifyColor($categoryColor) . '\'" ' ;
            $htmlday .= 'onmouseout="javascript:style.backgroundColor=\'' . $categoryColor . '\'" ' ;
            $htmlday .= 'valign="top">';

            if ($event->startTimestamp < $now && $event->endTimestamp > $now) {
                $htmlday .= '<b>';
            }
            if (isset($event->eventID)) {
                $htmlday .= $event->getLink(null, false);
            } elseif (isset($event->taskID)) {
                $htmlday .= Horde::link(Horde::url($registry->link('tasks/show', array('task' => $event->taskID)),
                                                   true),
                                        $event->title) . $text . '</a>';
            } else {
                $htmlday .= $text;
            }
            if ($event->startTimestamp < $now && $event->endTimestamp > $now) {
                $html .= '</b>';
            }
            $htmlday .= '</td></tr>';
            while (isset($htmldays[$event->startTimestamp])) {
                $event->startTimestamp++;
            }
            $htmldays[$event->startTimestamp] = $htmlday;
        }
        ksort($htmldays);
        $html .= implode("\n", $htmldays);
    }
    $html .= '</table></td></tr></table>';

    return $html;
}