5 * \defgroup CalHtmlHandles Handles the HTML display of calendar items.
10 #include "webserver.h"
12 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
14 /****************************************************************************/
17 * \brief Display one day of a whole month view of a calendar
18 * \param thetime the month we want to see
20 void calendar_month_view_display_events(time_t thetime) {
23 icalproperty *p = NULL;
24 icalproperty *q = NULL;
25 struct icaltimetype t;
27 int all_day_event = 0;
28 int multi_day_event = 0;
29 int fill_day_event = 0;
34 struct wcsession *WCC;
39 if (WCC->num_cal == 0) {
40 wprintf("<br /><br /><br />\n");
44 localtime_r(&thetime, &today_tm);
45 month = today_tm.tm_mon + 1;
46 day = today_tm.tm_mday;
47 year = today_tm.tm_year + 1900;
48 dst_day = thetime - 3600;
49 for (i=0; i<(WCC->num_cal); ++i) {
53 Cal = &WCC->disp_cal[i];
54 all_day_event = Cal->start_hour == -1;
55 // lprintf(1,"Date: %d %d %d %d\n", thetime, Cal->start_day, day, thetime - Cal->start_day);
58 // are we in the range of the event?
59 show_event = (Cal->start_day <= thetime) &&
60 (Cal->end_day >= thetime);
62 // are we in the range of the event?
63 show_event = (Cal->start_day <= dst_day) &&
64 (Cal->end_day >= dst_day);
66 // are we not start or end day?
67 fill_day_event = (Cal->start_day < thetime) &&
68 (Cal->end_day > thetime);
72 show_event = (thetime == Cal->start_day) || (dst_day == Cal->start_day);
75 p = icalcomponent_get_first_property(
77 ICAL_SUMMARY_PROPERTY);
81 wprintf("<table border=0 cellpadding=2><TR>"
82 "<td bgcolor=\"#CCCCDD\">"
86 wprintf("<font size=-1>"
87 "<a href=\"display_edit_event?"
88 "msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\""
90 WC->disp_cal[i].cal_msgnum,
97 wprintf("<i>%s</i> ", _("Summary:"));
98 escputs((char *)icalproperty_get_comment(p));
101 q = icalcomponent_get_first_property(
103 ICAL_LOCATION_PROPERTY);
105 wprintf("<i>%s</i> ", _("Location:"));
106 escputs((char *)icalproperty_get_comment(q));
111 * Only show start/end times if we're actually looking at the VEVENT
112 * component. Otherwise it shows bogus dates for e.g. timezones
114 if (icalcomponent_isa(Cal->cal) == ICAL_VEVENT_COMPONENT) {
116 q = icalcomponent_get_first_property(Cal->cal,
117 ICAL_DTSTART_PROPERTY);
119 t = icalproperty_get_dtstart(q);
124 memset(&d_tm, 0, sizeof d_tm);
125 d_tm.tm_year = t.year - 1900;
126 d_tm.tm_mon = t.month - 1;
127 d_tm.tm_mday = t.day;
128 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
129 wprintf("<i>%s</i> %s<br>",
133 tt = icaltime_as_timet(t);
134 fmt_date(buf, tt, 1);
135 wprintf("<i>%s</i> %s<br>",
136 _("Starting date/time:"), buf);
138 /* Embed the 'show end date/time' loop inside here so it
139 * only executes if this is NOT an all day event.
141 q = icalcomponent_get_first_property(Cal->cal,
142 ICAL_DTEND_PROPERTY);
144 t = icalproperty_get_dtend(q);
145 tt = icaltime_as_timet(t);
146 fmt_date(buf, tt, 1);
147 wprintf("<i>%s</i> %s<br>",
148 _("Ending date/time:"), buf);
156 q = icalcomponent_get_first_property(
158 ICAL_DESCRIPTION_PROPERTY);
160 wprintf("<i>%s</i> ", _("Notes:"));
161 escputs((char *)icalproperty_get_comment(q));
167 icalproperty_get_comment(p));
168 wprintf("</a></font><br />\n");
171 wprintf("</td></tr></table>");
184 * \brief Display one day of a whole month view of a calendar
185 * \param thetime the month we want to see
187 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
197 struct icaltimetype t;
198 int month, day, year;
199 int all_day_event = 0;
203 time_format = get_time_format_cached ();
205 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
206 else timeformat="%I:%M %p";
208 localtime_r(&thetime, &today_tm);
209 month = today_tm.tm_mon + 1;
210 day = today_tm.tm_mday;
211 year = today_tm.tm_year + 1900;
213 for (i=0; i<(WC->num_cal); ++i) {
214 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
215 ICAL_DTSTART_PROPERTY);
217 t = icalproperty_get_dtstart(p);
218 event_tt = icaltime_as_timet(t);
220 if (t.is_date) all_day_event = 1;
221 else all_day_event = 0;
224 gmtime_r(&event_tts, &event_tms);
227 localtime_r(&event_tts, &event_tms);
229 /** \todo epoch &! daymask */
230 if ((event_tms.tm_year == today_tm.tm_year)
231 && (event_tms.tm_mon == today_tm.tm_mon)
232 && (event_tms.tm_mday == today_tm.tm_mday)) {
238 p = icalcomponent_get_first_property(
240 ICAL_SUMMARY_PROPERTY);
241 e = icalcomponent_get_first_property(
243 ICAL_DTEND_PROPERTY);
244 if ((p != NULL) && (e != NULL)) {
247 t = icalproperty_get_dtend(e);
248 event_tte = icaltime_as_timet(t);
249 localtime_r(&event_tte, &event_tme);
250 difftime=(event_tte-event_tts)/60;
251 hours=(int)(difftime / 60);
252 minutes=difftime % 60;
253 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
255 "<a href=\"display_edit_event?msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\">",
259 WC->disp_cal[i].cal_msgnum,
267 icalproperty_get_comment(p));
268 /** \todo: allso ammitime format */
269 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
270 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
272 wprintf("</a></font></td>"
273 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
290 * \brief view one month. pretty view
291 * \param year the year
292 * \param month the month
293 * \param day the actual day we want to see
295 void calendar_month_view(int year, int month, int day) {
296 struct tm starting_tm;
300 time_t previous_month;
302 time_t colheader_time;
303 struct tm colheader_tm;
304 char colheader_label[32];
307 char weekstart_buf[16];
309 /* Determine what day to start.
311 get_preference("weekstart", weekstart_buf, sizeof weekstart_buf);
312 weekstart = atoi(weekstart_buf);
315 * Now back up to the 1st of the month...
317 memset(&starting_tm, 0, sizeof(struct tm));
319 starting_tm.tm_year = year - 1900;
320 starting_tm.tm_mon = month - 1;
321 starting_tm.tm_mday = day;
322 thetime = mktime(&starting_tm);
324 memcpy(&tm, &starting_tm, sizeof(struct tm));
325 while (tm.tm_mday != 1) {
326 thetime = thetime - (time_t)86400; /* go back 24 hours */
327 localtime_r(&thetime, &tm);
330 /** Determine previous and next months ... for links */
331 previous_month = thetime - (time_t)864000L; /* back 10 days */
332 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
334 /** Now back up until we're on the user's preferred start day */
335 localtime_r(&thetime, &tm);
336 while (tm.tm_wday != weekstart) {
337 thetime = thetime - (time_t)86400; /* go back 24 hours */
338 localtime_r(&thetime, &tm);
341 /** Outer table (to get the background color) */
342 wprintf("<div class=\"fix_scrollbar_bug\">"
343 "<table class=\"calendar\"> \n <tr><td>");
345 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
347 wprintf("<td align=center>");
349 localtime_r(&previous_month, &tm);
350 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
351 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
352 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
354 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
355 wprintf(" "
356 "<font size=+1 color=\"#FFFFFF\">"
359 " ", colheader_label, year);
361 localtime_r(&next_month, &tm);
362 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
363 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
364 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
366 wprintf("</td></tr></table>\n");
368 /** Inner table (the real one) */
369 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
370 "bgcolor=#204B78 id=\"inner_month\"><tr>");
371 colheader_time = thetime;
372 for (i=0; i<7; ++i) {
373 colheader_time = thetime + (i * 86400) ;
374 localtime_r(&colheader_time, &colheader_tm);
375 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
376 wprintf("<td align=center width=14%%>"
377 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
383 /** Now do 35 or 42 days */
384 for (i = 0; i < 42; ++i) {
385 localtime_r(&thetime, &tm);
387 if ((i < 35) || (chg_month == 0)) {
389 if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) {
396 /** Before displaying Sunday, start a new row */
401 wprintf("<td class=\"cal%s\"><div class=\"day\">",
402 ((tm.tm_mon != month-1) ? "out" :
403 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
406 if ((i==0) || (tm.tm_mday == 1)) {
407 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
408 wprintf("%s ", colheader_label);
410 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
417 /** put the data here, stupid */
418 calendar_month_view_display_events(thetime);
422 /** After displaying Saturday, end the row */
429 thetime += (time_t)86400; /** ahead 24 hours */
432 wprintf("</table>" /** end of inner table */
433 "</td></tr></table>" /** end of outer table */
437 * Initialize the bubble tooltips.
439 * Yes, this is as stupid as it looks. Instead of just making the call
440 * to btt_enableTooltips() straight away, we have to create a timer event
441 * and let it initialize as an event after 1 millisecond. This is to
442 * work around a bug in Internet Explorer that causes it to crash if we
443 * manipulate the innerHTML of various DOM nodes while the page is still
444 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
445 * for more information.
447 wprintf("<script type=\"text/javascript\">"
448 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
454 * \brief view one month. brief view
455 * \param year the year
456 * \param month the month
457 * \param day the actual day we want to see
459 void calendar_brief_month_view(int year, int month, int day) {
460 struct tm starting_tm;
464 time_t previous_month;
466 char month_label[32];
468 /** Determine what day to start.
469 * First, back up to the 1st of the month...
471 memset(&starting_tm, 0, sizeof(struct tm));
472 starting_tm.tm_year = year - 1900;
473 starting_tm.tm_mon = month - 1;
474 starting_tm.tm_mday = day;
475 thetime = mktime(&starting_tm);
477 memcpy(&tm, &starting_tm, sizeof(struct tm));
478 while (tm.tm_mday != 1) {
479 thetime = thetime - (time_t)86400; /* go back 24 hours */
480 localtime_r(&thetime, &tm);
483 /** Determine previous and next months ... for links */
484 previous_month = thetime - (time_t)864000L; /* back 10 days */
485 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
487 /** Now back up until we're on a Sunday */
488 localtime_r(&thetime, &tm);
489 while (tm.tm_wday != 0) {
490 thetime = thetime - (time_t)86400; /* go back 24 hours */
491 localtime_r(&thetime, &tm);
494 /** Outer table (to get the background color) */
495 wprintf("<div class=\"fix_scrollbar_bug\">"
496 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
497 "bgcolor=#204B78><TR><TD>\n");
499 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
501 wprintf("<td align=center>");
503 localtime_r(&previous_month, &tm);
504 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
505 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
506 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
508 wc_strftime(month_label, sizeof month_label, "%B", &tm);
509 wprintf(" "
510 "<font size=+1 color=\"#FFFFFF\">"
513 " ", month_label, year);
515 localtime_r(&next_month, &tm);
516 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
517 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
518 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
520 wprintf("</td></tr></table>\n");
522 /** Inner table (the real one) */
523 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
524 "bgcolor=#EEEECC><TR>");
526 wprintf("<tr><td colspan=\"100%\">\n");
528 /** Now do 35 days */
529 for (i = 0; i < 35; ++i) {
530 char weeknumber[255];
531 char weekday_name[32];
533 localtime_r(&thetime, &tm);
536 /** Before displaying Sunday, start a new CELL */
538 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
539 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
540 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
550 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
551 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
555 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
556 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
557 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
559 weekday_name,tm.tm_mday,
562 /** put the data of one day here, stupid */
563 calendar_month_view_brief_events(thetime, daycolor);
566 /** After displaying Saturday, end the row */
568 wprintf("</td></tr></table>\n");
571 thetime += (time_t)86400; /** ahead 24 hours */
574 wprintf("</table>" /** end of inner table */
575 "</td></tr></table>" /** end of outer table */
580 * \brief view one week
581 * this should view just one week, but it's not here yet.
582 * \todo ny implemented
583 * \param year the year
584 * \param month the month
585 * \param day the day which we want to see the week around
587 void calendar_week_view(int year, int month, int day) {
588 wprintf("<center><i>week view FIXME</i></center><br />\n");
593 * \brief display one day
594 * Display events for a particular hour of a particular day.
595 * (Specify hour < 0 to show "all day" events)
596 * \param year the year
597 * \param month the month
599 * \param hour the hour we want to start displaying
600 * \param dstart daystart
603 void calendar_day_view_display_events(time_t thetime, int year, int month,
605 int dstart, int dend) {
613 int all_day_event = 0;
614 struct wcsession *WCC;
615 struct disp_cal *Cal;
619 if (WCC->num_cal == 0) {
620 // \todo FIXME wprintf("<br /><br /><br />\n");
624 event_start = thetime + 60 * 60 * hour;
625 event_end = thetime + 60 * 60 * (hour + 1);
627 for (i=0; i<(WCC->num_cal); ++i) {
628 Cal = &WCC->disp_cal[i];
629 all_day_event = Cal->start_hour == -1;
632 if (! all_day_event )
634 show_event = (thetime == Cal->start_day) &&
635 (event_start <= Cal->start_hour) &&
636 ((Cal->end_hour != -1)?
637 (Cal->end_hour < event_end) : 1);
642 show_event = (Cal->start_day == thetime);
645 p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
646 if ((show_event) && (p != NULL)) {
647 if (all_day_event && (hour == -1)) {
648 wprintf("<dd><a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
649 Cal->cal_msgnum, year, month, day, hour);
650 escputs((char *) icalproperty_get_comment(p));
651 wprintf("</a></dd>\n");
654 wprintf("<dd><a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
655 Cal->cal_msgnum, year, month, day, hour);
656 escputs((char *) icalproperty_get_comment(p));
657 wprintf("</a></dd>\n");
665 * \brief view one day
666 * \param year the year
667 * \param month the month
668 * \param day the day we want to display
670 void calendar_day_view(int year, int month, int day) {
672 struct icaltimetype today, yesterday, tomorrow;
675 char daystart_str[16], dayend_str[16];
681 time_format = get_time_format_cached ();
682 get_preference("daystart", daystart_str, sizeof daystart_str);
683 if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
684 get_preference("dayend", dayend_str, sizeof dayend_str);
685 if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str);
688 memset(&d_tm, 0, sizeof d_tm);
690 localtime_r(&WC->disp_cal[0].start_day, &d_tm);
692 d_tm.tm_year = year - 1900;
693 d_tm.tm_mon = month - 1;
695 today_t = mktime(&d_tm);
697 /** Figure out the dates for "yesterday" and "tomorrow" links */
699 memset(&today, 0, sizeof(struct icaltimetype));
705 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
707 yesterday = icaltime_normalize(yesterday);
709 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
711 tomorrow = icaltime_normalize(tomorrow);
713 wprintf("<div class=\"fix_scrollbar_bug\">");
715 /** Inner table (the real one) */
716 wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
718 /** Innermost cell (contains hours etc.) */
719 wprintf("<td class=\"events_of_the_day\" >");
720 wprintf("<dl class=\"events\" >");
721 /** Now the middle of the day... */
722 for (hour = 0; hour < 24; ++hour) { /* could do HEIGHT=xx */
723 wprintf("<dt class=\"hour%s\"><a href=\"display_edit_event?msgnum=0"
724 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
725 (hour < daystart ? "before" : (hour > dayend ? "after" : "")),
726 year, month, day, hour
729 if (time_format == WC_TIMEFORMAT_24) {
730 wprintf("%2d:00</a> ", hour);
733 wprintf("%d:00%s</a> ",
734 (hour <= 12 ? hour : hour-12),
735 (hour < 12 ? "am" : "pm")
742 /* put the data here, stupid */
743 calendar_day_view_display_events(today_t, year, month, day, hour, daystart, dayend);
748 wprintf("</td>"); /* end of innermost table */
750 /** Extra events on the middle */
751 wprintf("<td class=\"extra_events\">");
755 /** Display all-day events) */
756 wprintf("<dt>All day events</dt>");
757 calendar_day_view_display_events(today_t, year, month, day, -1, daystart, dayend);
761 wprintf("</td>"); /** end extra on the middle */
763 wprintf("<td width=20%% valign=top>"); /** begin stuff-on-the-right */
765 /** Begin todays-date-with-left-and-right-arrows */
766 wprintf("<table border=0 width=100%% "
767 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
771 wprintf("<td align=center>");
772 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
773 yesterday.year, yesterday.month, yesterday.day);
774 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
777 wc_strftime(d_str, sizeof d_str,
779 "<font size=+2>%B</font><br />"
780 "<font size=+3>%d</font><br />"
781 "<font size=+2>%Y</font><br />"
785 wprintf("%s", d_str);
788 wprintf("<td align=center>");
789 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
790 tomorrow.year, tomorrow.month, tomorrow.day);
791 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
795 wprintf("</tr></table>\n");
796 /** End todays-date-with-left-and-right-arrows */
798 /** \todo In the future we might want to put a month-o-matic here */
800 wprintf("</font></center>\n");
802 wprintf("</td></tr>"); /** end stuff-on-the-right */
804 wprintf("</table>" /** end of inner table */
807 wprintf("<script type=\"text/javascript\">"
808 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); "
815 * \brief Display today's events.
817 void calendar_summary_view(void) {
820 struct icaltimetype t;
825 int all_day_event = 0;
826 char timestring[SIZ];
828 if (WC->num_cal == 0) {
833 localtime_r(&now, &today_tm);
835 for (i=0; i<(WC->num_cal); ++i) {
836 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
837 ICAL_DTSTART_PROPERTY);
839 t = icalproperty_get_dtstart(p);
840 event_tt = icaltime_as_timet(t);
847 fmt_time(timestring, event_tt);
850 gmtime_r(&event_tt, &event_tm);
853 localtime_r(&event_tt, &event_tm);
856 if ( (event_tm.tm_year == today_tm.tm_year)
857 && (event_tm.tm_mon == today_tm.tm_mon)
858 && (event_tm.tm_mday == today_tm.tm_mday)
862 p = icalcomponent_get_first_property(
864 ICAL_SUMMARY_PROPERTY);
867 icalproperty_get_comment(p));
868 wprintf(" (%s)<br />\n", timestring);
873 free_calendar_buffer();
878 * \brief clean up ical memory
879 * \todo this could get troubel with future ical versions
881 void free_calendar_buffer(void) {
883 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
884 icalcomponent_free(WC->disp_cal[i].cal);
894 * \brief do the whole calendar page
895 * view any part of the calender. decide which way, etc.
897 void do_calendar_view(void) {
900 int year, month, day;
903 /** In case no date was specified, go with today */
905 localtime_r(&now, &tm);
906 year = tm.tm_year + 1900;
907 month = tm.tm_mon + 1;
910 /** Now see if a date was specified */
911 if (!IsEmptyStr(bstr("year"))) year = atoi(bstr("year"));
912 if (!IsEmptyStr(bstr("month"))) month = atoi(bstr("month"));
913 if (!IsEmptyStr(bstr("day"))) day = atoi(bstr("day"));
915 /** How would you like that cooked? */
916 if (!IsEmptyStr(bstr("calview"))) {
917 strcpy(calview, bstr("calview"));
920 strcpy(calview, "month");
923 /** Display the selected view */
924 if (!strcasecmp(calview, "day")) {
925 calendar_day_view(year, month, day);
927 else if (!strcasecmp(calview, "week")) {
928 calendar_week_view(year, month, day);
931 if (WC->wc_view == VIEW_CALBRIEF) {
932 calendar_brief_month_view(year, month, day);
935 calendar_month_view(year, month, day);
939 /** Free the calendar stuff */
940 free_calendar_buffer();
946 * \brief get task due date
947 * Helper function for do_tasks_view().
948 * \param vtodo a task to get the due date
949 * \return the date/time due.
951 time_t get_task_due_date(icalcomponent *vtodo) {
959 * If we're looking at a fully encapsulated VCALENDAR
960 * rather than a VTODO component, recurse into the data
961 * structure until we get a VTODO.
963 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
964 return get_task_due_date(
965 icalcomponent_get_first_component(
966 vtodo, ICAL_VTODO_COMPONENT
971 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
973 return(icaltime_as_timet(icalproperty_get_due(p)));
982 * \brief Compare the due dates of two tasks (this is for sorting)
983 * \param task1 first task to compare
984 * \param task2 second task to compare
986 int task_due_cmp(const void *task1, const void *task2) {
990 t1 = get_task_due_date(((struct disp_cal *)task1)->cal);
991 t2 = get_task_due_date(((struct disp_cal *)task2)->cal);
993 if (t1 < t2) return(-1);
994 if (t1 > t2) return(1);
1002 * \brief do the whole task view stuff
1004 void do_tasks_view(void) {
1011 wprintf("<div class=\"fix_scrollbar_bug\">"
1012 "<table class=\"calendar_view_background\">\n<tr>\n"
1014 wprintf(_("Name of task"));
1015 wprintf("</th><th>");
1016 wprintf(_("Date due"));
1017 wprintf("</th></tr>\n"
1020 /** Sort them if necessary */
1021 if (WC->num_cal > 1) {
1024 sizeof(struct disp_cal),
1029 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1032 wprintf("<tr bgcolor=\"#%s\"><td>",
1033 (bg ? "DDDDDD" : "FFFFFF")
1036 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1037 ICAL_SUMMARY_PROPERTY);
1038 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1039 WC->disp_cal[i].cal_msgnum );
1040 urlescputs(WC->wc_roomname);
1042 wprintf("<img align=middle "
1043 "src=\"static/taskmanag_16x.gif\" border=0> ");
1045 escputs((char *)icalproperty_get_comment(p));
1050 due = get_task_due_date(WC->disp_cal[i].cal);
1051 fmt_date(buf, due, 0);
1052 wprintf("<td><font");
1053 if (due < time(NULL)) {
1054 wprintf(" color=\"#FF0000\"");
1056 wprintf(">%s</font></td></tr>\n", buf);
1059 wprintf("</table></div>\n");
1061 /** Free the list */
1062 free_calendar_buffer();
1066 #else /* WEBCIT_WITH_CALENDAR_SERVICE */
1068 /**\brief stub for non-libical builds */
1069 void do_calendar_view(void) {
1070 wprintf("<center><i>");
1071 wprintf(_("The calendar view is not available."));
1072 wprintf("</i></center><br />\n");
1075 /**\brief stub for non-libical builds */
1076 void do_tasks_view(void) {
1077 wprintf("<center><I>");
1078 wprintf(_("The tasks view is not available."));
1079 wprintf("</i></center><br />\n");
1083 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */