|
[ Index ]
|
Source Code Reference for V1.00
|
[Summary view]
[Print]
[Text view]
1 <?php
2 if (!defined('W2P_BASE_DIR')) {
3 die('You should not access this file directly.');
4 }
5
6
7
8
9
10 require_once ($AppUI->getLibraryClass('PEAR/Date'));
11 require_once ($AppUI->getSystemClass('w2p'));
12 require_once $AppUI->getSystemClass('libmail');
13 require_once $AppUI->getSystemClass('date');
14
15
16
17
18
19
20 class CMonthCalendar {
21
22
23
24 var $this_month;
25 var $prev_month;
26 var $next_month;
27 var $prev_year;
28 var $next_year;
29
30
31
32
33 var $styleTitle;
34
35
36
37 var $styleMain;
38
39
40
41 var $callback;
42
43
44
45 var $showHeader;
46
47
48
49 var $showArrows;
50
51
52
53 var $showDays;
54
55
56
57 var $showWeek;
58
59
60
61 var $clickMonth;
62
63
64
65 var $showEvents;
66
67
68
69 var $dayFunc;
70
71
72
73 var $weekFunc;
74
75
76
77 var $showHighlightedDays;
78
79
80
81
82 function CMonthCalendar($date = null) {
83 $this->setDate($date);
84
85 $this->classes = array();
86 $this->callback = '';
87 $this->showTitle = true;
88 $this->showArrows = true;
89 $this->showDays = true;
90 $this->showWeek = true;
91 $this->showEvents = true;
92 $this->showHighlightedDays = true;
93
94 $this->styleTitle = '';
95 $this->styleMain = '';
96
97 $this->dayFunc = '';
98 $this->weekFunc = '';
99
100 $this->events = array();
101 $this->highlightedDays = array();
102 }
103
104
105
106
107
108
109
110
111
112
113 function setDate($date = null) {
114 $this->this_month = new CDate($date);
115
116 $d = $this->this_month->getDay();
117 $m = $this->this_month->getMonth();
118 $y = $this->this_month->getYear();
119
120 $this->prev_year = new CDate($date);
121 $this->prev_year->setYear($this->prev_year->getYear() - 1);
122
123 $this->next_year = new CDate($date);
124 $this->next_year->setYear($this->next_year->getYear() + 1);
125
126 setlocale(LC_TIME, 'en');
127 $date = Date_Calc::beginOfPrevMonth($d, $m, $y, FMT_TIMESTAMP_DATE);
128 setlocale(LC_ALL, $AppUI->user_lang);
129
130 $this->prev_month = new CDate($date);
131
132 setlocale(LC_TIME, 'en');
133 $date = Date_Calc::beginOfNextMonth($d, $m, $y, FMT_TIMESTAMP_DATE);
134 setlocale(LC_ALL, $AppUI->user_lang);
135 $this->next_month = new CDate($date);
136
137 }
138
139
140
141
142
143
144
145 function setStyles($title, $main) {
146 $this->styleTitle = $title;
147 $this->styleMain = $main;
148 }
149
150
151
152
153
154
155
156
157
158 function setLinkFunctions($day = '', $week = '') {
159 $this->dayFunc = $day;
160 $this->weekFunc = $week;
161 }
162
163
164
165
166
167
168
169 function setCallback($function) {
170 $this->callback = $function;
171 }
172
173
174
175
176
177
178
179 function setEvents($e) {
180 $this->events = $e;
181 }
182
183
184
185
186
187
188
189
190 function setHighlightedDays($hd) {
191 $this->highlightedDays = $hd;
192 }
193
194
195
196
197
198
199
200
201 function show() {
202 $s = '';
203 if ($this->showTitle) {
204 $s .= $this->_drawTitle();
205 }
206 $s .= '<table border="0" cellspacing="1" cellpadding="2" width="100%" class="' . $this->styleMain . '">';
207
208 if ($this->showDays) {
209 $s .= $this->_drawDays();
210 }
211
212 $s .= $this->_drawMain();
213
214 $s .= '</table>';
215
216 return $s;
217 }
218
219
220
221
222
223
224
225 function _drawTitle() {
226 global $AppUI, $m, $a, $locale_char_set;
227 $url = 'index.php?m=' . $m;
228 $url .= $a ? '&a=' . $a : '';
229 $url .= isset($_GET['dialog']) ? '&dialog=1' : '';
230
231 $s = '<table border="0" cellspacing="0" cellpadding="3" width="100%" class="' . $this->styleTitle . '">';
232 $s .= '<tr>';
233
234 if ($this->showArrows) {
235 $href = $url . '&date=' . $this->prev_month->format(FMT_TIMESTAMP_DATE) . ($this->callback ? '&callback=' . $this->callback : '') . ((count($this->highlightedDays) > 0) ? '&uts=' . key($this->highlightedDays) : '');
236 $s .= '<td align="left">';
237 $s .= '<a href="' . $href . '">' . w2PshowImage('prev.gif', 16, 16, $AppUI->_('previous month')) . '</a>';
238 $s .= '</td>';
239
240 }
241
242 $s .= '<th width="99%" align="center">';
243 if ($this->clickMonth) {
244 $s .= '<a href="index.php?m=' . $m . '&date=' . $this->this_month->format(FMT_TIMESTAMP_DATE) . '">';
245 }
246 setlocale(LC_TIME, 'en');
247 $s .= $AppUI->_($this->this_month->format('%B')) . ' ' . $AppUI->_($this->this_month->format('%Y')) . (($this->clickMonth) ? '</a>' : '');
248 setlocale(LC_ALL, $AppUI->user_lang);
249 $s .= '</th>';
250
251 if ($this->showArrows) {
252 $href = ($url . '&date=' . $this->next_month->format(FMT_TIMESTAMP_DATE) . (($this->callback) ? ('&callback=' . $this->callback) : '') . ((count($this->highlightedDays) > 0) ? ('&uts=' . key($this->highlightedDays)) : ''));
253 $s .= '<td align="right">';
254 $s .= ('<a href="' . $href . '">' . w2PshowImage('next.gif', 16, 16, $AppUI->_('next month')) . '</a>');
255 $s .= '</td>';
256 }
257
258 $s .= '</tr>';
259 $s .= '</table>';
260
261 return $s;
262 }
263
264
265
266
267
268
269
270 function _drawDays() {
271 global $AppUI, $locale_char_set;
272
273 setlocale(LC_TIME, 'en');
274 $wk = Date_Calc::getCalendarWeek(null, null, null, '%a', LOCALE_FIRST_DAY);
275 setlocale(LC_ALL, $AppUI->user_lang);
276
277 $s = (($this->showWeek) ? ('<th> </th>') : '');
278 foreach ($wk as $day) {
279 $s .= ('<th width="14%">' . $AppUI->_($day) . '</th>');
280 }
281
282 return ('<tr>' . $s . '</tr>');
283 }
284
285
286
287
288
289
290
291 function _drawMain() {
292 global $AppUI;
293 $today = new CDate();
294 $today = $today->format('%Y%m%d%w');
295
296 $date = $this->this_month;
297 $this_day = intval($date->getDay());
298 $this_month = intval($date->getMonth());
299 $this_year = intval($date->getYear());
300 setlocale(LC_TIME, 'en');
301 $cal = Date_Calc::getCalendarMonth($this_month, $this_year, '%Y%m%d%w', LOCALE_FIRST_DAY);
302 setlocale(LC_ALL, $AppUI->user_lang);
303
304 $df = $AppUI->getPref('SHDATEFORMAT');
305
306 $html = '';
307 foreach ($cal as $week) {
308 $html .= '<tr>';
309 if ($this->showWeek) {
310 $html .= '<td class="week">';
311 $html .= $this->dayFunc ? "<a href=\"javascript:$this->weekFunc('$week[0]')\">" : '';
312 $html .= '<img src="' . w2PfindImage('view.week.gif') . '" width="16" height="15" border="0" alt="Week View" /></a>';
313 $html .= $this->dayFunc ? '</a>' : '';
314 $html .= '</td>';
315 }
316
317 foreach ($week as $day) {
318 $this_day = new CDate($day);
319 $y = intval(substr($day, 0, 4));
320 $m = intval(substr($day, 4, 2));
321 $d = intval(substr($day, 6, 2));
322 $dow = intval(substr($day, 8, 1));
323 $cday = intval(substr($day, 0, 8));
324
325
326 if (array_key_exists($cday, $this->events) && $this->styleMain == 'minical') {
327 $nr_tasks = 0;
328 $nr_events = 0;
329
330 foreach ($this->events[$cday] as $record) {
331 if ($record['task']) {
332 ++$nr_tasks;
333 } else {
334 ++$nr_events;
335 }
336 }
337 if ($nr_events && $nr_tasks) {
338
339 $class = 'eventtask';
340 } elseif ($nr_events) {
341
342 $class = 'event';
343 } elseif ($nr_tasks) {
344
345 $class = 'task';
346 }
347 if ($day == $today) {
348 $class .= 'today';
349 }
350 } elseif ($m != $this_month) {
351 $class = 'empty';
352 } elseif ($day == $today) {
353 $class = 'today';
354 } elseif ($dow == 0 || $dow == 6) {
355 $class = 'weekend';
356 } else {
357 $class = 'day';
358 }
359 $day = substr($day, 0, 8);
360 $html .= '<td class="' . $class . '"';
361 if ($this->showHighlightedDays && isset($this->highlightedDays[$day])) {
362 $html .= ' style="border: 1px solid ' . $this->highlightedDays[$day] . '"';
363 }
364 $html .= ' onclick="' . $this->dayFunc . '(\'' . $day . '\',\'' . $this_day->format($df) . '\')' . '">';
365 if ($m == $this_month) {
366 if ($this->dayFunc) {
367 $html .= "<a href=\"javascript:$this->dayFunc('$day','" . $this_day->format($df) . "')\" class=\"$class\">";
368 $html .= $d;
369 $html .= '</a>';
370 } else {
371 $html .= $d;
372 }
373 if ($this->showEvents) {
374 $html .= $this->_drawEvents(substr($day, 0, 8));
375 }
376 }
377 $html .= '</td>';
378 }
379 $html .= '</tr>';
380 }
381 return $html;
382 }
383
384
385
386
387
388
389
390 function _drawWeek($dateObj) {
391 $href = "javascript:$this->weekFunc(" . $dateObj->getTimestamp() . ',\'' . $dateObj->toString() . '\')';
392 $w = ' <td class="week">';
393 $w .= $this->dayFunc ? '<a href="' . $href . '">' : '';
394 $w .= '<img src="' . w2PfindImage('view.week.gif') . '" width="16" height="15" border="0" alt="Week View" /></a>';
395 $w .= $this->dayFunc ? '</a>' : '';
396 $w .= '</td>';
397 return $w;
398 }
399
400
401
402
403
404
405
406 function _drawEvents($day) {
407 $s = '';
408 if (!isset($this->events[$day]) || $this->styleMain == 'minical') {
409 return '';
410 }
411 $events = $this->events[$day];
412 foreach ($events as $e) {
413 $href = isset($e['href']) ? $e['href'] : null;
414 $alt = isset($e['alt']) ? str_replace("\n", ' ', $e['alt']) : null;
415
416 $s .= '<br />';
417 $s .= $href ? '<a href="'.$href.'" class="event" title="'.$alt.'">' : '';
418 $s .= $e['text'];
419 $s .= $href ? '</a>' : '';
420 }
421 return $s;
422 }
423 }
424
425
426
427
428
429
430
431 class CEvent extends CW2pObject {
432
433
434 var $event_id = null;
435
436
437
438 var $event_title = null;
439
440 var $event_start_date = null;
441 var $event_end_date = null;
442 var $event_parent = null;
443 var $event_description = null;
444 var $event_times_recuring = null;
445 var $event_recurs = null;
446 var $event_remind = null;
447 var $event_icon = null;
448 var $event_owner = null;
449 var $event_project = null;
450 var $event_private = null;
451 var $event_type = null;
452 var $event_notify = null;
453 var $event_cwd = null;
454
455 function CEvent() {
456 $this->CW2pObject('events', 'event_id');
457 }
458
459
460 function check() {
461
462 $this->event_private = intval($this->event_private);
463 $this->event_type = intval($this->event_type);
464 $this->event_cwd = intval($this->event_cwd);
465
466
467
468 if ($this->event_recurs) {
469 $start_date = new CDate($this->event_start_date);
470 $end_date = new CDate($this->event_end_date);
471 $hour = $end_date->