Cal day view : fix a display bug with timezone
[citadel.git] / webcit / calendar_view.c
1  /*
2  * $Id$
3  */
4 /**
5  * \defgroup CalHtmlHandles Handles the HTML display of calendar items.
6  * \ingroup Calendaring
7  */
8 /*@{*/
9 #include "webcit.h"
10 #include "webserver.h"
11
12 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
13
14 /****************************************************************************/
15
16
17 /**
18  */
19 void embeddable_mini_calendar(int year, int month, char *urlformat)
20 {
21         struct tm starting_tm;
22         struct tm tm;
23         time_t thetime;
24         int i;
25         time_t previous_month;
26         time_t next_month;
27         time_t colheader_time;
28         struct tm colheader_tm;
29         char colheader_label[32];
30         int weekstart = 0;
31         char weekstart_buf[16];
32         char url[256];
33         char div_id[256];
34
35         snprintf(div_id, sizeof div_id, "mini_calendar_%d", rand() );
36
37         /* Determine what day to start.
38          */
39         get_preference("weekstart", weekstart_buf, sizeof weekstart_buf);
40         weekstart = atoi(weekstart_buf);
41
42         /*
43          * Now back up to the 1st of the month...
44          */
45         memset(&starting_tm, 0, sizeof(struct tm));
46
47         starting_tm.tm_year = year - 1900;
48         starting_tm.tm_mon = month - 1;
49         starting_tm.tm_mday = 1;
50         thetime = mktime(&starting_tm);
51
52         memcpy(&tm, &starting_tm, sizeof(struct tm));
53         while (tm.tm_mday != 1) {
54                 thetime = thetime - (time_t)86400;      /* go back 24 hours */
55                 localtime_r(&thetime, &tm);
56         }
57
58         /** Determine previous and next months ... for links */
59         previous_month = thetime - (time_t)864000L;     /* back 10 days */
60         next_month = thetime + (time_t)(31L * 86400L);  /* ahead 31 days */
61
62         /** Now back up until we're on the user's preferred start day */
63         localtime_r(&thetime, &tm);
64         while (tm.tm_wday != weekstart) {
65                 thetime = thetime - (time_t)86400;      /* go back 24 hours */
66                 localtime_r(&thetime, &tm);
67         }
68
69         wprintf("<div class=\"mini_calendar\" id=\"%s\">\n", div_id);
70
71         localtime_r(&previous_month, &tm);
72
73         wprintf("<a href=\"javascript:minical_previous_month();\">&laquo;</a>");
74         wprintf("&nbsp;");
75 /* previous month
76         wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
77                 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
78         wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
79 */
80
81         wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
82         wprintf("&nbsp;&nbsp;"
83                 "<span class=\"mini_calendar_month_label\">"
84                 "%s %d"
85                 "</span>"
86                 "&nbsp;&nbsp;", colheader_label, year);
87
88         wprintf("&nbsp;");
89         wprintf("<a href=\"javascript:minical_next_month();\">&raquo;</a>");
90 /*
91         localtime_r(&next_month, &tm);
92         wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
93                 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
94         wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
95 */
96
97         wprintf("<table border=0 cellpadding=1 cellspacing=1 class=\"mini_calendar_days\">"
98                 "<tr>");
99         colheader_time = thetime;
100         for (i=0; i<7; ++i) {
101                 colheader_time = thetime + (i * 86400) ;
102                 localtime_r(&colheader_time, &colheader_tm);
103                 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
104                 wprintf("<th>%c</th>", colheader_label[0]);
105
106         }
107         wprintf("</tr>\n");
108
109
110         /** Now do 35 or 42 days */
111         for (i = 0; i < 42; ++i) {
112                 localtime_r(&thetime, &tm);
113
114                 if (i < 35) {
115
116                         /** Before displaying Sunday, start a new row */
117                         if ((i % 7) == 0) {
118                                 wprintf("<tr>");
119                         }
120
121                         if (tm.tm_mon == month-1) {
122                                 snprintf(url, sizeof url, urlformat,
123                                         tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday);
124                                 wprintf("<td><a href=\"%s\">%d</a></td>", url, tm.tm_mday);
125                         }
126                         else {
127                                 wprintf("<td> </td>");
128                         }
129
130                         /** After displaying one week, end the row */
131                         if ((i % 7) == 6) {
132                                 wprintf("</tr>\n");
133                         }
134
135                 }
136
137                 thetime += (time_t)86400;               /** ahead 24 hours */
138         }
139
140         wprintf("</table>"                      /** end of inner table */
141                 "</div>\n");
142 }
143
144
145 /**
146  * \brief Display one day of a whole month view of a calendar
147  * \param thetime the month we want to see 
148  */
149 void calendar_month_view_display_events(int year, int month, int day)
150 {
151         int i;
152         icalproperty *p = NULL;
153         icalproperty *q = NULL;
154         struct icaltimetype t;
155         struct icaltimetype end_t;
156         struct icaltimetype today_start_t;
157         struct icaltimetype today_end_t;
158         struct tm starting_tm;
159         struct tm ending_tm;
160         int all_day_event = 0;
161         int show_event = 0;
162         char buf[256];
163         struct wcsession *WCC = WC;     /* This is done to make it run faster; WC is a function */
164         struct disp_cal *Cal;
165         time_t tt;
166
167         if (WCC->num_cal == 0) {
168                 wprintf("<br /><br /><br />\n");
169                 return;
170         }
171
172         /* Create an imaginary event which spans the 24 hours of today.  Any events which
173          * overlap with this one take place at least partially in this day.  We have to
174          * convert it from a struct tm in order to make it UTC.
175          */
176         memset(&starting_tm, 0, sizeof(struct tm));
177         starting_tm.tm_year = year - 1900;
178         starting_tm.tm_mon = month - 1;
179         starting_tm.tm_mday = day;
180         starting_tm.tm_hour = 0;
181         starting_tm.tm_min = 0;
182         today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
183         today_start_t.is_utc = 1;
184
185         memset(&ending_tm, 0, sizeof(struct tm));
186         ending_tm.tm_year = year - 1900;
187         ending_tm.tm_mon = month - 1;
188         ending_tm.tm_mday = day;
189         ending_tm.tm_hour = 23;
190         ending_tm.tm_min = 59;
191         today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
192         today_end_t.is_utc = 1;
193
194         /* Now loop through our list of events to see which ones occur today.
195          */
196         for (i=0; i<(WCC->num_cal); ++i) {
197                 Cal = &WCC->disp_cal[i];
198                 all_day_event = 0;
199                 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
200                 if (q != NULL) {
201                         t = icalproperty_get_dtstart(q);
202                 }
203                 else {
204                         memset(&t, 0, sizeof t);
205                 }
206                 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
207                 if (q != NULL) {
208                         end_t = icalproperty_get_dtend(q);
209                 }
210                 else {
211                         memset(&end_t, 0, sizeof end_t);
212                 }
213                 if (t.is_date) all_day_event = 1;
214
215                 if (all_day_event)
216                 {
217                         show_event = ((t.year == year) && (t.month == month) && (t.day == day));
218                 }
219                 else
220                 {
221                         show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
222                 }
223
224                 /* If we determined that this event occurs today, then display it.
225                  */
226                 if (show_event) {
227                         p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
228                         if (p != NULL) {
229
230                                 if (all_day_event) {
231                                         wprintf("<table border=0 cellpadding=2><TR>"
232                                                 "<td bgcolor=\"#CCCCDD\">"
233                                                 );
234                                 }
235
236                                 wprintf("<font size=-1>"
237                                         "<a href=\"display_edit_event?"
238                                         "msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\""
239                                         " btt_tooltext=\"",
240                                         WC->disp_cal[i].cal_msgnum,
241                                         bstr("calview"),
242                                         bstr("year"),
243                                         bstr("month"),
244                                         bstr("day")
245                                         );
246
247                                 wprintf("<i>%s</i> ", _("Summary:"));
248                                 escputs((char *)icalproperty_get_comment(p));
249                                 wprintf("<br />");
250                                 
251                                 q = icalcomponent_get_first_property(
252                                         WC->disp_cal[i].cal,
253                                         ICAL_LOCATION_PROPERTY);
254                                 if (q) {
255                                         wprintf("<i>%s</i> ", _("Location:"));
256                                         escputs((char *)icalproperty_get_comment(q));
257                                         wprintf("<br />");
258                                         }
259                                 
260                                 /**
261                                  * Only show start/end times if we're actually looking at the VEVENT
262                                  * component.  Otherwise it shows bogus dates for e.g. timezones
263                                  */
264                                 if (icalcomponent_isa(Cal->cal) == ICAL_VEVENT_COMPONENT) {
265                                         
266                                         q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
267                                         if (q != NULL) {
268                                                 t = icalproperty_get_dtstart(q);
269                                                 
270                                                 if (t.is_date) {
271                                                         struct tm d_tm;
272                                                         char d_str[32];
273                                                         memset(&d_tm, 0, sizeof d_tm);
274                                                         d_tm.tm_year = t.year - 1900;
275                                                         d_tm.tm_mon = t.month - 1;
276                                                         d_tm.tm_mday = t.day;
277                                                         wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
278                                                         wprintf("<i>%s</i> %s<br>",
279                                                                 _("Date:"), d_str);
280                                                 }
281                                                 else {
282                                                         tt = icaltime_as_timet(t);
283                                                         fmt_date(buf, tt, 1);
284                                                         wprintf("<i>%s</i> %s<br>",
285                                                                 _("Starting date/time:"), buf);
286                                                         
287                                                         /* Embed the 'show end date/time' loop inside here so it
288                                                          * only executes if this is NOT an all day event.
289                                                          */
290                                                         q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
291                                                         if (q != NULL) {
292                                                                 t = icalproperty_get_dtend(q);
293                                                                 tt = icaltime_as_timet(t);
294                                                                 fmt_date(buf, tt, 1);
295                                                                 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
296                                                         }
297                                                         
298                                                 }
299                                         }
300                                         
301                                 }
302                                 
303                                 q = icalcomponent_get_first_property(Cal->cal, ICAL_DESCRIPTION_PROPERTY);
304                                 if (q) {
305                                         wprintf("<i>%s</i> ", _("Notes:"));
306                                         escputs((char *)icalproperty_get_comment(q));
307                                         wprintf("<br />");
308                                 }
309                                 
310                                 wprintf("\">");
311                                 escputs((char *)
312                                         icalproperty_get_comment(p));
313                                 wprintf("</a></font><br />\n");
314                                 
315                                 if (all_day_event) {
316                                         wprintf("</td></tr></table>");
317                                 }
318                                 
319                         }
320                         
321                 }
322                 
323                 
324         }
325 }
326
327
328 /**
329  * \brief Display one day of a whole month view of a calendar
330  * \param thetime the month we want to see 
331  */
332 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
333         int i;
334         time_t event_tt;
335         time_t event_tts;
336         time_t event_tte;
337         struct tm event_tms;
338         struct tm event_tme;
339         struct tm today_tm;
340         icalproperty *p;
341         icalproperty *e;
342         struct icaltimetype t;
343         int month, day, year;
344         int all_day_event = 0;
345         char *timeformat;
346         int time_format;
347         
348         time_format = get_time_format_cached ();
349
350         if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
351         else timeformat="%I:%M %p";
352
353         localtime_r(&thetime, &today_tm);
354         month = today_tm.tm_mon + 1;
355         day = today_tm.tm_mday;
356         year = today_tm.tm_year + 1900;
357
358         for (i=0; i<(WC->num_cal); ++i) {
359                 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
360                                                 ICAL_DTSTART_PROPERTY);
361                 if (p != NULL) {
362                         t = icalproperty_get_dtstart(p);
363                         event_tt = icaltime_as_timet(t);
364                         event_tts=event_tt;
365                         if (t.is_date) all_day_event = 1;
366                         else all_day_event = 0;
367
368                         if (all_day_event) {
369                                 gmtime_r(&event_tts, &event_tms);
370                         }
371                         else {
372                                 localtime_r(&event_tts, &event_tms);
373                         }
374                         /** \todo epoch &! daymask */
375                         if ((event_tms.tm_year == today_tm.tm_year)
376                            && (event_tms.tm_mon == today_tm.tm_mon)
377                            && (event_tms.tm_mday == today_tm.tm_mday)) {
378                                 
379                                 
380                                 char sbuf[255];
381                                 char ebuf[255];
382
383                                 p = icalcomponent_get_first_property(
384                                                         WC->disp_cal[i].cal,
385                                                         ICAL_SUMMARY_PROPERTY);
386                                 e = icalcomponent_get_first_property(
387                                                         WC->disp_cal[i].cal, 
388                                                         ICAL_DTEND_PROPERTY);
389                                 if ((p != NULL) && (e != NULL)) {
390                                         time_t difftime;
391                                         int hours, minutes;
392                                         t = icalproperty_get_dtend(e);
393                                         event_tte = icaltime_as_timet(t);
394                                         localtime_r(&event_tte, &event_tme);
395                                         difftime=(event_tte-event_tts)/60;
396                                         hours=(int)(difftime / 60);
397                                         minutes=difftime % 60;
398                                         wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
399                                                         "<font size=-1>"
400                                                         "<a href=\"display_edit_event?msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\">",
401                                                         daycolor,
402                                                         hours, minutes,
403                                                         daycolor,
404                                                         WC->disp_cal[i].cal_msgnum,
405                                                         bstr("calview"),
406                                                         bstr("year"),
407                                                         bstr("month"),
408                                                         bstr("day")
409                                                         );
410
411                                         escputs((char *)
412                                                         icalproperty_get_comment(p));
413                                         /** \todo: allso ammitime format */
414                                         wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
415                                         wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
416
417                                         wprintf("</a></font></td>"
418                                                         "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
419                                                         daycolor,
420                                                         sbuf,
421                                                         daycolor,
422                                                         ebuf);
423                                         
424                                 }
425                                 
426                         }
427                         
428                         
429                 }
430         }
431 }
432
433
434 /**
435  * \brief view one month. pretty view
436  * \param year the year
437  * \param month the month
438  * \param day the actual day we want to see
439  */
440 void calendar_month_view(int year, int month, int day) {
441         struct tm starting_tm;
442         struct tm tm;
443         time_t thetime;
444         int i;
445         time_t previous_month;
446         time_t next_month;
447         time_t colheader_time;
448         struct tm colheader_tm;
449         char colheader_label[32];
450         int chg_month = 0;
451         int weekstart = 0;
452         char weekstart_buf[16];
453
454         /* Determine what day to start.
455          */
456         get_preference("weekstart", weekstart_buf, sizeof weekstart_buf);
457         weekstart = atoi(weekstart_buf);
458
459         /*
460          * Now back up to the 1st of the month...
461          */
462         memset(&starting_tm, 0, sizeof(struct tm));
463
464         starting_tm.tm_year = year - 1900;
465         starting_tm.tm_mon = month - 1;
466         starting_tm.tm_mday = day;
467         thetime = mktime(&starting_tm);
468
469         memcpy(&tm, &starting_tm, sizeof(struct tm));
470         while (tm.tm_mday != 1) {
471                 thetime = thetime - (time_t)86400;      /* go back 24 hours */
472                 localtime_r(&thetime, &tm);
473         }
474
475         /** Determine previous and next months ... for links */
476         previous_month = thetime - (time_t)864000L;     /* back 10 days */
477         next_month = thetime + (time_t)(31L * 86400L);  /* ahead 31 days */
478
479         /** Now back up until we're on the user's preferred start day */
480         localtime_r(&thetime, &tm);
481         while (tm.tm_wday != weekstart) {
482                 thetime = thetime - (time_t)86400;      /* go back 24 hours */
483                 localtime_r(&thetime, &tm);
484         }
485
486         /** Outer table (to get the background color) */
487         wprintf("<div class=\"fix_scrollbar_bug\">"
488                 "<table class=\"calendar\"> \n <tr><td>"); 
489
490         wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
491
492         wprintf("<td align=center>");
493
494         localtime_r(&previous_month, &tm);
495         wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
496                 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
497         wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
498
499         wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
500         wprintf("&nbsp;&nbsp;"
501                 "<font size=+1 color=\"#FFFFFF\">"
502                 "%s %d"
503                 "</font>"
504                 "&nbsp;&nbsp;", colheader_label, year);
505
506         localtime_r(&next_month, &tm);
507         wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
508                 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
509         wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
510
511         wprintf("</td></tr></table>\n");
512
513         /** Inner table (the real one) */
514         wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
515                 "bgcolor=#204B78 id=\"inner_month\"><tr>");
516         colheader_time = thetime;
517         for (i=0; i<7; ++i) {
518                 colheader_time = thetime + (i * 86400) ;
519                 localtime_r(&colheader_time, &colheader_tm);
520                 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
521                 wprintf("<td align=center width=14%%>"
522                         "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
523
524         }
525         wprintf("</tr>\n");
526
527
528         /** Now do 35 or 42 days */
529         for (i = 0; i < 42; ++i) {
530                 localtime_r(&thetime, &tm);
531
532                 if ((i < 35) || (chg_month == 0)) {
533
534                         if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) {
535                                 chg_month = 1;
536                         }
537                         if (i > 35) {
538                                 chg_month = 0;
539                         }
540
541                         /** Before displaying Sunday, start a new row */
542                         if ((i % 7) == 0) {
543                                 wprintf("<tr>");
544                         }
545
546                         wprintf("<td class=\"cal%s\"><div class=\"day\">",
547                                 ((tm.tm_mon != month-1) ? "out" :
548                                 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
549                                 "day"))
550                         );
551                         if ((i==0) || (tm.tm_mday == 1)) {
552                                 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
553                                 wprintf("%s ", colheader_label);
554                         }
555                         wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
556                                 "%d</a></div>",
557                                 tm.tm_year + 1900,
558                                 tm.tm_mon + 1,
559                                 tm.tm_mday,
560                                 tm.tm_mday);
561
562                         /** put the data here, stupid */
563                         calendar_month_view_display_events(
564                                 tm.tm_year + 1900,
565                                 tm.tm_mon + 1,
566                                 tm.tm_mday
567                         );
568
569                         wprintf("</td>");
570
571                         /** After displaying Saturday, end the row */
572                         if ((i % 7) == 6) {
573                                 wprintf("</tr>\n");
574                         }
575
576                 }
577
578                 thetime += (time_t)86400;               /** ahead 24 hours */
579         }
580
581         wprintf("</table>"                      /** end of inner table */
582                 "</td></tr></table>"            /** end of outer table */
583                 "</div>\n");
584
585         /**
586          * Initialize the bubble tooltips.
587          *
588          * Yes, this is as stupid as it looks.  Instead of just making the call
589          * to btt_enableTooltips() straight away, we have to create a timer event
590          * and let it initialize as an event after 1 millisecond.  This is to
591          * work around a bug in Internet Explorer that causes it to crash if we
592          * manipulate the innerHTML of various DOM nodes while the page is still
593          * being rendered.  See http://www.shaftek.org/blog/archives/000212.html
594          * for more information.
595          */ 
596         wprintf("<script type=\"text/javascript\">"
597                 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
598                 "</script>\n"
599         );
600 }
601
602 /**
603  * \brief view one month. brief view
604  * \param year the year
605  * \param month the month
606  * \param day the actual day we want to see
607  */
608 void calendar_brief_month_view(int year, int month, int day) {
609         struct tm starting_tm;
610         struct tm tm;
611         time_t thetime;
612         int i;
613         time_t previous_month;
614         time_t next_month;
615         char month_label[32];
616
617         /** Determine what day to start.
618          * First, back up to the 1st of the month...
619          */
620         memset(&starting_tm, 0, sizeof(struct tm));
621         starting_tm.tm_year = year - 1900;
622         starting_tm.tm_mon = month - 1;
623         starting_tm.tm_mday = day;
624         thetime = mktime(&starting_tm);
625
626         memcpy(&tm, &starting_tm, sizeof(struct tm));
627         while (tm.tm_mday != 1) {
628                 thetime = thetime - (time_t)86400;      /* go back 24 hours */
629                 localtime_r(&thetime, &tm);
630         }
631
632         /** Determine previous and next months ... for links */
633         previous_month = thetime - (time_t)864000L;     /* back 10 days */
634         next_month = thetime + (time_t)(31L * 86400L);  /* ahead 31 days */
635
636         /** Now back up until we're on a Sunday */
637         localtime_r(&thetime, &tm);
638         while (tm.tm_wday != 0) {
639                 thetime = thetime - (time_t)86400;      /* go back 24 hours */
640                 localtime_r(&thetime, &tm);
641         }
642
643         /** Outer table (to get the background color) */
644         wprintf("<div class=\"fix_scrollbar_bug\">"
645                 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
646                 "bgcolor=#204B78><TR><TD>\n");
647
648         wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
649
650         wprintf("<td align=center>");
651
652         localtime_r(&previous_month, &tm);
653         wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
654                 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
655         wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
656
657         wc_strftime(month_label, sizeof month_label, "%B", &tm);
658         wprintf("&nbsp;&nbsp;"
659                 "<font size=+1 color=\"#FFFFFF\">"
660                 "%s %d"
661                 "</font>"
662                 "&nbsp;&nbsp;", month_label, year);
663
664         localtime_r(&next_month, &tm);
665         wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
666                 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
667         wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
668
669         wprintf("</td></tr></table>\n");
670
671         /** Inner table (the real one) */
672         wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
673                 "bgcolor=#EEEECC><TR>");
674         wprintf("</tr>\n");
675         wprintf("<tr><td colspan=\"100%\">\n");
676
677         /** Now do 35 days */
678         for (i = 0; i < 35; ++i) {
679                 char weeknumber[255];
680                 char weekday_name[32];
681                 char *daycolor;
682                 localtime_r(&thetime, &tm);
683
684
685                 /** Before displaying Sunday, start a new CELL */
686                 if ((i % 7) == 0) {
687                         wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
688                         wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
689                                         "   <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
690                                         _("Week"), 
691                                         weeknumber,
692                                         _("Hours"),
693                                         _("Subject"),
694                                         _("Start"),
695                                         _("End")
696                                         );
697                 }
698                 
699                 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
700                                   ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
701                                    "FFFFFF"));
702                 
703                 /** Day Header */
704                 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
705                 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
706                                 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
707                                 daycolor,
708                                 weekday_name,tm.tm_mday,
709                                 daycolor);
710
711                 /** put the data of one day  here, stupid */
712                 calendar_month_view_brief_events(thetime, daycolor);
713
714
715                 /** After displaying Saturday, end the row */
716                 if ((i % 7) == 6) {
717                         wprintf("</td></tr></table>\n");
718                 }
719
720                 thetime += (time_t)86400;               /** ahead 24 hours */
721         }
722
723         wprintf("</table>"                      /** end of inner table */
724                 "</td></tr></table>"            /** end of outer table */
725                 "</div>\n");
726 }
727
728 /** 
729  * \brief view one week
730  * this should view just one week, but it's not here yet.
731  * \todo ny implemented
732  * \param year the year
733  * \param month the month
734  * \param day the day which we want to see the week around
735  */
736 void calendar_week_view(int year, int month, int day) {
737         wprintf("<center><i>week view FIXME</i></center><br />\n");
738 }
739
740
741 /**
742  * \brief display one day
743  * Display events for a particular hour of a particular day.
744  * (Specify hour < 0 to show "all day" events)
745  * \param year the year
746  * \param month the month
747  * \param day the day
748  * \param hour the hour we want to start displaying
749  * \param dstart daystart 
750  * \param dend dayend 
751  */
752 void calendar_day_view_display_events(time_t thetime, int year, int month,
753                                         int day, int hour,
754                                         int dstart, int dend) {
755         int i;
756         icalproperty *p = NULL;
757         icalproperty *q = NULL;
758         time_t event_start;
759         time_t event_end;
760         time_t event_tt;
761         time_t event_tte;
762         struct tm event_te;
763         struct tm event_tm;
764         int show_event = 0;
765         int all_day_event = 0;
766         int ongoing_event = 0;
767         struct wcsession *WCC = WC;     /* This is done to make it run faster; WC is a function */
768         struct disp_cal *Cal;
769         struct icaltimetype t;
770         struct icaltimetype end_t;
771         struct icaltimetype today_start_t;
772         struct icaltimetype today_end_t;
773         struct tm starting_tm;
774         struct tm ending_tm;
775         int top = 0;
776         int height = 0;
777
778         if (WCC->num_cal == 0) {
779                 // \todo FIXME wprintf("<br /><br /><br />\n");
780                 return;
781         }
782
783         event_start = thetime + 60 * 60 * hour;
784         event_end = thetime + 60 * 60 * (hour + 1);
785
786
787         /* Create an imaginary event which spans the current hour.  Any events which
788          * overlap with this one take place at least partially in this day.
789          */
790         memset(&starting_tm, 0, sizeof(struct tm));
791         starting_tm.tm_year = year - 1900;
792         starting_tm.tm_mon = month - 1;
793         starting_tm.tm_mday = day;
794         starting_tm.tm_hour = hour;
795         starting_tm.tm_min = 0;
796         today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
797         today_start_t.is_utc = 1;
798
799         memset(&ending_tm, 0, sizeof(struct tm));
800         ending_tm.tm_year = year - 1900;
801         ending_tm.tm_mon = month - 1;
802         ending_tm.tm_mday = day;
803         ending_tm.tm_hour = hour;
804         ending_tm.tm_min = 59;
805         today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
806         today_end_t.is_utc = 1;
807
808         /* Now loop through our list of events to see which ones occur today.
809          */
810         for (i=0; i<(WCC->num_cal); ++i) {
811                 Cal = &WCC->disp_cal[i];
812
813                 all_day_event = 0;
814                 ongoing_event=0;
815
816                 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
817                 if (q != NULL) {
818                         t = icalproperty_get_dtstart(q);
819                         event_tt = icaltime_as_timet(t);
820                         localtime_r(&event_tt, &event_te);
821                 }
822                 else {
823                         memset(&t, 0, sizeof t);
824                 }
825                 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
826                 if (q != NULL) {
827                         end_t = icalproperty_get_dtend(q);
828                         event_tte = icaltime_as_timet(end_t);
829                         localtime_r(&event_tte, &event_tm);
830                 }
831                 else {
832                         memset(&end_t, 0, sizeof end_t);
833                 }
834                 if (t.is_date) all_day_event = 1;
835
836                 if (all_day_event)
837                 {
838                         show_event = ((t.year == year) && (t.month == month) && (t.day == day) && (hour == -1));
839                 }
840                 else
841                 {
842                         show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
843                 }
844
845  
846                 /* If we determined that this event occurs today, then display it.
847                  */
848                 p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
849                 if ((show_event) && (p != NULL)) {
850
851                         if ((event_te.tm_mday != today_start_t.day) && (event_tm.tm_mday != today_start_t.day)) ongoing_event = 1; 
852
853                         if (all_day_event) 
854                         {
855                                 wprintf("<li><a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
856                                         Cal->cal_msgnum, year, month, day, hour);
857                                 escputs((char *) icalproperty_get_comment(p));
858                                 wprintf("</a> (");
859                                 wprintf(_("All day event"));
860                                 wprintf(")</li>\n");
861                         }
862                         else if (ongoing_event && (hour == -1)) 
863                         {
864                                 wprintf("<li><a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
865                                         Cal->cal_msgnum, year, month, day, hour);
866                                 escputs((char *) icalproperty_get_comment(p));
867                                 wprintf("</a> (");
868                                 wprintf(_("Ongoing event"));
869                                 wprintf(")</li>\n");
870                         }
871                         else 
872                         {
873                                 if ((hour == event_te.tm_hour) && ! ongoing_event ) {
874
875                                         if (event_te.tm_mday != today_start_t.day)      event_te.tm_hour = 0;
876                                         if (event_tm.tm_mday != today_start_t.day) event_tm.tm_hour = 24;
877
878                                         if ((event_te.tm_hour < dstart) && (event_tm.tm_hour <= dstart)) {
879                                                 top = (event_te.tm_hour * 11) -1;
880                                                 height= (event_tm.tm_hour - event_te.tm_hour) * 11;
881                                         }
882                                         if ((event_te.tm_hour < dstart) && (event_tm.tm_hour >= dstart)) {
883                                                 top = (event_te.tm_hour * 11) - 1;
884                                                 height = ((dstart - event_te.tm_hour) * 11) + ((event_tm.tm_hour - dstart) * 31);
885                                         }
886                                         if ((event_te.tm_hour <= dstart) && (event_tm.tm_hour > dend)) {
887                                                 top = (event_te.tm_hour * 11) - 1;
888                                                 height = ((dstart - event_te.tm_hour) * 11) + ((dend - dstart + 1) * 31) + ((event_tm.tm_hour - dend - 1) * 10);
889                                         }
890                                         if ((event_te.tm_hour >= dstart) && (event_tm.tm_hour <= dend)) {
891                                                 top = (dstart * 11) + ((event_te.tm_hour - dstart) * 31) - 1;
892                                                 height = ((event_tm.tm_hour - event_te.tm_hour) * 31);
893                                         }
894                                         if ((event_te.tm_hour >= dstart) && (event_te.tm_hour <= dend) && (event_tm.tm_hour > dend)) {
895                                                 top = (dstart * 11) + ((event_te.tm_hour - dstart) * 31) - 1;
896                                                 height = (((dend - event_te.tm_hour + 1) * 31) + ((event_tm.tm_hour - dend - 1) * 11));
897                                         }
898                                         if ((event_te.tm_hour > dend) && (event_tm.tm_hour > dend)) {
899                                                 top = (dstart * 11) + ((dend - dstart + 1) * 31) + ((event_tm.tm_hour - event_te.tm_hour) * 11) - 1;
900                                                 height = ((event_tm.tm_hour - event_te.tm_hour) * 11);
901                                         }
902                                 wprintf("<dd  class=\"event\" "
903                                         "style=\"position: absolute; "
904                                         "top:%dpx; left:100px; "
905                                         "height:%dpx; \" >",
906                                         top, height
907                                         );
908                                 wprintf("<a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d&case=%d\">",
909                                         Cal->cal_msgnum, year, month, day, t.hour, hour);
910                                 escputs((char *) icalproperty_get_comment(p));
911                                 wprintf("</a></dd>\n");
912                                 }
913                                 
914                         }
915                 }
916         }
917 }
918
919 /**
920  * \brief view one day
921  * \param year the year
922  * \param month the month 
923  * \param day the day we want to display
924  */
925 void calendar_day_view(int year, int month, int day) {
926         int hour;
927         struct icaltimetype today, yesterday, tomorrow;
928         int daystart = 8;
929         int dayend = 17;
930         char daystart_str[16], dayend_str[16];
931         struct tm d_tm;
932         char d_str[128];
933         int time_format;
934         time_t today_t;
935
936         time_format = get_time_format_cached ();
937         get_preference("daystart", daystart_str, sizeof daystart_str);
938         if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
939         get_preference("dayend", dayend_str, sizeof dayend_str);
940         if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str);
941         
942         /** Today's date */
943         memset(&d_tm, 0, sizeof d_tm);
944         d_tm.tm_year = year - 1900;
945         d_tm.tm_mon = month - 1;
946         d_tm.tm_mday = day;
947         today_t = mktime(&d_tm); 
948
949         /** Figure out the dates for "yesterday" and "tomorrow" links */
950
951         memset(&today, 0, sizeof(struct icaltimetype));
952         today.year = year;
953         today.month = month;
954         today.day = day;
955         today.is_date = 1;
956
957         memcpy(&yesterday, &today, sizeof(struct icaltimetype));
958         --yesterday.day;
959         yesterday = icaltime_normalize(yesterday);
960
961         memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
962         ++tomorrow.day;
963         tomorrow = icaltime_normalize(tomorrow);
964
965         wprintf("<div class=\"fix_scrollbar_bug\">");
966
967         /** Inner table (the real one) */
968         wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
969
970         /** Innermost cell (contains hours etc.) */
971         wprintf("<td class=\"events_of_the_day\" >");
972         wprintf("<dl class=\"events\" >");
973         /** Now the middle of the day... */     
974         for (hour = 0; hour < 24; ++hour) {     /* could do HEIGHT=xx */
975                 wprintf("<dt class=\"hour%s\"><a href=\"display_edit_event?msgnum=0"
976                         "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
977                         (hour < daystart ? "before" : (hour > dayend ? "after" : "")),
978                         year, month, day, hour
979                 );
980
981                 if (time_format == WC_TIMEFORMAT_24) {
982                         wprintf("%2d:00</a> ", hour);
983                 }
984                 else {
985                         wprintf("%d:00%s</a> ",
986                                 (hour <= 12 ? hour : hour-12),
987                                 (hour < 12 ? "am" : "pm")
988                         );
989                 }
990
991                 wprintf("</dt>");
992         
993
994                 /* put the data here, stupid */
995                 calendar_day_view_display_events(today_t, year, month, day, hour, daystart, dayend);
996
997         }
998
999         wprintf("</dl>");
1000         wprintf("</td>");                       /* end of innermost table */
1001
1002         /** Extra events on the middle */
1003         wprintf("<td class=\"extra_events\">");
1004
1005         wprintf("<ul>");
1006
1007         /** Display all-day events) */
1008                 calendar_day_view_display_events(today_t, year, month, day, -1, daystart, dayend);
1009
1010         wprintf("</ul>");
1011
1012         wprintf("</td>");       /** end extra on the middle */
1013
1014         wprintf("<td width=20%% align=center valign=top>");     /** begin stuff-on-the-right */
1015
1016         /** Begin todays-date-with-left-and-right-arrows */
1017         wprintf("<table border=0 width=100%% "
1018                 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
1019         wprintf("<tr>");
1020
1021         /** Left arrow */       
1022         wprintf("<td align=center>");
1023         wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
1024                 yesterday.year, yesterday.month, yesterday.day);
1025         wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
1026         wprintf("</td>");
1027
1028         wc_strftime(d_str, sizeof d_str,
1029                 "<td align=center>"
1030                 "<font size=+2>%B</font><br />"
1031                 "<font size=+3>%d</font><br />"
1032                 "<font size=+2>%Y</font><br />"
1033                 "</td>",
1034                 &d_tm
1035         );
1036         wprintf("%s", d_str);
1037
1038         /** Right arrow */
1039         wprintf("<td align=center>");
1040         wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
1041                 tomorrow.year, tomorrow.month, tomorrow.day);
1042         wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
1043                 " border=0></a>\n");
1044         wprintf("</td>");
1045
1046         wprintf("</tr></table>\n");
1047         /** End todays-date-with-left-and-right-arrows */
1048
1049         /** Embed a mini month calendar in this space */
1050         wprintf("<br />\n");
1051         embeddable_mini_calendar(year, month, "readfwd?calview=day&year=%d&month=%d&day=%d");
1052
1053         wprintf("</font></center>\n");
1054
1055         wprintf("</td></tr>");                  /** end stuff-on-the-right */
1056
1057         wprintf("</table>"                      /** end of inner table */
1058                 "</div>");
1059
1060         wprintf("<script type=\"text/javascript\">"
1061                 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); "
1062                 "</script>\n"
1063         );
1064 }
1065
1066
1067 /**
1068  * \brief Display today's events.
1069  */
1070 void calendar_summary_view(void) {
1071         int i;
1072         icalproperty *p;
1073         struct icaltimetype t;
1074         time_t event_tt;
1075         struct tm event_tm;
1076         struct tm today_tm;
1077         time_t now;
1078         int all_day_event = 0;
1079         char timestring[SIZ];
1080
1081         if (WC->num_cal == 0) {
1082                 return;
1083         }
1084
1085         now = time(NULL);
1086         localtime_r(&now, &today_tm);
1087
1088         for (i=0; i<(WC->num_cal); ++i) {
1089                 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1090                                                 ICAL_DTSTART_PROPERTY);
1091                 if (p != NULL) {
1092                         t = icalproperty_get_dtstart(p);
1093                         event_tt = icaltime_as_timet(t);
1094                         if (t.is_date) {
1095                                 all_day_event = 1;
1096                         }
1097                         else {
1098                                 all_day_event = 0;
1099                         }
1100                         fmt_time(timestring, event_tt);
1101
1102                         if (all_day_event) {
1103                                 gmtime_r(&event_tt, &event_tm);
1104                         }
1105                         else {
1106                                 localtime_r(&event_tt, &event_tm);
1107                         }
1108
1109                         if ( (event_tm.tm_year == today_tm.tm_year)
1110                            && (event_tm.tm_mon == today_tm.tm_mon)
1111                            && (event_tm.tm_mday == today_tm.tm_mday)
1112                            ) {
1113
1114
1115                                 p = icalcomponent_get_first_property(
1116                                                         WC->disp_cal[i].cal,
1117                                                         ICAL_SUMMARY_PROPERTY);
1118                                 if (p != NULL) {
1119                                         escputs((char *)
1120                                                 icalproperty_get_comment(p));
1121                                         wprintf(" (%s)<br />\n", timestring);
1122                                 }
1123                         }
1124                 }
1125         }
1126         free_calendar_buffer();
1127 }
1128
1129
1130 /**
1131  * \brief clean up ical memory
1132  * \todo this could get troubel with future ical versions
1133  */
1134 void free_calendar_buffer(void) {
1135         int i;
1136         if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1137                 icalcomponent_free(WC->disp_cal[i].cal);
1138         }
1139         WC->num_cal = 0;
1140         free(WC->disp_cal);
1141         WC->disp_cal = NULL;
1142 }
1143
1144
1145
1146 /**
1147  * \brief do the whole calendar page
1148  * view any part of the calender. decide which way, etc.
1149  */
1150 void do_calendar_view(void) {
1151         time_t now;
1152         struct tm tm;
1153         int year, month, day;
1154         char calview[SIZ];
1155
1156         /** In case no date was specified, go with today */
1157         now = time(NULL);
1158         localtime_r(&now, &tm);
1159         year = tm.tm_year + 1900;
1160         month = tm.tm_mon + 1;
1161         day = tm.tm_mday;
1162
1163         /** Now see if a date was specified */
1164         if (!IsEmptyStr(bstr("year"))) year = atoi(bstr("year"));
1165         if (!IsEmptyStr(bstr("month"))) month = atoi(bstr("month"));
1166         if (!IsEmptyStr(bstr("day"))) day = atoi(bstr("day"));
1167
1168         /** How would you like that cooked? */
1169         if (!IsEmptyStr(bstr("calview"))) {
1170                 strcpy(calview, bstr("calview"));
1171         }
1172         else {
1173                 strcpy(calview, "month");
1174         }
1175
1176         /** Display the selected view */
1177         if (!strcasecmp(calview, "day")) {
1178                 calendar_day_view(year, month, day);
1179         }
1180         else if (!strcasecmp(calview, "week")) {
1181                 calendar_week_view(year, month, day);
1182         }
1183         else {
1184                 if (WC->wc_view == VIEW_CALBRIEF) {
1185                         calendar_brief_month_view(year, month, day);
1186                 }
1187                 else {
1188                         calendar_month_view(year, month, day);
1189                 }
1190         }
1191
1192         /** Free the calendar stuff */
1193         free_calendar_buffer();
1194
1195 }
1196
1197
1198 /**
1199  * \brief get task due date
1200  * Helper function for do_tasks_view().  
1201  * \param vtodo a task to get the due date
1202  * \return the date/time due.
1203  */
1204 time_t get_task_due_date(icalcomponent *vtodo) {
1205         icalproperty *p;
1206
1207         if (vtodo == NULL) {
1208                 return(0L);
1209         }
1210
1211         /**
1212          * If we're looking at a fully encapsulated VCALENDAR
1213          * rather than a VTODO component, recurse into the data
1214          * structure until we get a VTODO.
1215          */
1216         if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1217                 return get_task_due_date(
1218                         icalcomponent_get_first_component(
1219                                 vtodo, ICAL_VTODO_COMPONENT
1220                         )
1221                 );
1222         }
1223
1224         p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1225         if (p != NULL) {
1226                 return(icaltime_as_timet(icalproperty_get_due(p)));
1227         }
1228         else {
1229                 return(0L);
1230         }
1231 }
1232
1233
1234 /**
1235  * \brief Compare the due dates of two tasks (this is for sorting)
1236  * \param task1 first task to compare
1237  * \param task2 second task to compare
1238  */
1239 int task_due_cmp(const void *task1, const void *task2) {
1240         time_t t1;
1241         time_t t2;
1242
1243         t1 =  get_task_due_date(((struct disp_cal *)task1)->cal);
1244         t2 =  get_task_due_date(((struct disp_cal *)task2)->cal);
1245
1246         if (t1 < t2) return(-1);
1247         if (t1 > t2) return(1);
1248         return(0);
1249 }
1250
1251
1252
1253
1254 /**
1255  * \brief do the whole task view stuff
1256  */
1257 void do_tasks_view(void) {
1258         int i;
1259         time_t due;
1260         int bg = 0;
1261         char buf[SIZ];
1262         icalproperty *p;
1263
1264         wprintf("<div class=\"fix_scrollbar_bug\">"
1265                 "<table class=\"calendar_view_background\">\n<tr>\n"
1266                 "<th>");
1267         wprintf(_("Name of task"));
1268         wprintf("</th><th>");
1269         wprintf(_("Date due"));
1270         wprintf("</th></tr>\n"
1271         );
1272
1273         /** Sort them if necessary */
1274         if (WC->num_cal > 1) {
1275                 qsort(WC->disp_cal,
1276                         WC->num_cal,
1277                         sizeof(struct disp_cal),
1278                         task_due_cmp
1279                 );
1280         }
1281
1282         if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1283
1284                 bg = 1 - bg;
1285                 wprintf("<tr bgcolor=\"#%s\"><td>",
1286                         (bg ? "DDDDDD" : "FFFFFF")
1287                 );
1288
1289                 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1290                                                         ICAL_SUMMARY_PROPERTY);
1291                 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1292                         WC->disp_cal[i].cal_msgnum );
1293                 urlescputs(WC->wc_roomname);
1294                 wprintf("\">");
1295                 wprintf("<img align=middle "
1296                         "src=\"static/taskmanag_16x.gif\" border=0>&nbsp;");
1297                 if (p != NULL) {
1298                         escputs((char *)icalproperty_get_comment(p));
1299                 }
1300                 wprintf("</a>\n");
1301                 wprintf("</td>\n");
1302
1303                 due = get_task_due_date(WC->disp_cal[i].cal);
1304                 fmt_date(buf, due, 0);
1305                 wprintf("<td><font");
1306                 if (due < time(NULL)) {
1307                         wprintf(" color=\"#FF0000\"");
1308                 }
1309                 wprintf(">%s</font></td></tr>\n", buf);
1310         }
1311
1312         wprintf("</table></div>\n");
1313
1314         /** Free the list */
1315         free_calendar_buffer();
1316
1317 }
1318
1319 #else   /* WEBCIT_WITH_CALENDAR_SERVICE */
1320
1321 /**\brief stub for non-libical builds */
1322 void do_calendar_view(void) {
1323         wprintf("<center><i>");
1324         wprintf(_("The calendar view is not available."));
1325         wprintf("</i></center><br />\n");
1326 }
1327
1328 /**\brief stub for non-libical builds */
1329 void do_tasks_view(void) {      
1330         wprintf("<center><I>");
1331         wprintf(_("The tasks view is not available."));
1332         wprintf("</i></center><br />\n");
1333 }
1334
1335
1336 #endif  /* WEBCIT_WITH_CALENDAR_SERVICE */
1337
1338 /** @} */