5 * \defgroup CalHtmlHandles Handles the HTML display of calendar items.
10 #include "webserver.h"
12 #ifndef WEBCIT_WITH_CALENDAR_SERVICE
14 /**\brief stub for non-libical builds */
15 void do_calendar_view(void) {
16 wprintf("<center><i>");
17 wprintf(_("The calendar view is not available."));
18 wprintf("</i></center><br />\n");
21 /**\brief stub for non-libical builds */
22 void do_tasks_view(void) {
23 wprintf("<center><I>");
24 wprintf(_("The tasks view is not available."));
25 wprintf("</i></center><br />\n");
28 #else /* WEBCIT_WITH_CALENDAR_SERVICE */
30 /****************************************************************************/
33 * \brief Display one day of a whole month view of a calendar
34 * \param thetime the month we want to see
36 void calendar_month_view_display_events(time_t thetime) {
41 icalproperty *p = NULL;
42 icalproperty *q = NULL;
43 struct icaltimetype t;
45 int all_day_event = 0;
49 if (WC->num_cal == 0) {
50 wprintf("<br /><br /><br />\n");
54 localtime_r(&thetime, &today_tm);
55 month = today_tm.tm_mon + 1;
56 day = today_tm.tm_mday;
57 year = today_tm.tm_year + 1900;
59 for (i=0; i<(WC->num_cal); ++i) {
60 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
61 ICAL_DTSTART_PROPERTY);
63 t = icalproperty_get_dtstart(p);
64 event_tt = icaltime_as_timet(t);
66 if (t.is_date) all_day_event = 1;
67 else all_day_event = 0;
70 gmtime_r(&event_tt, &event_tm);
73 localtime_r(&event_tt, &event_tm);
76 if ((event_tm.tm_year == today_tm.tm_year)
77 && (event_tm.tm_mon == today_tm.tm_mon)
78 && (event_tm.tm_mday == today_tm.tm_mday)) {
80 p = icalcomponent_get_first_property(
82 ICAL_SUMMARY_PROPERTY);
86 wprintf("<table border=0 cellpadding=2><TR>"
87 "<td bgcolor=\"#CCCCDD\">"
91 wprintf("<font size=-1>"
92 "<a href=\"display_edit_event?"
93 "msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\""
95 WC->disp_cal[i].cal_msgnum,
102 wprintf("<i>%s</i> ", _("Summary:"));
103 escputs((char *)icalproperty_get_comment(p));
106 q = icalcomponent_get_first_property(
108 ICAL_LOCATION_PROPERTY);
110 wprintf("<i>%s</i> ", _("Location:"));
111 escputs((char *)icalproperty_get_comment(q));
116 * Only show start/end times if we're actually looking at the VEVENT
117 * component. Otherwise it shows bogus dates for e.g. timezones
119 if (icalcomponent_isa(WC->disp_cal[i].cal) == ICAL_VEVENT_COMPONENT) {
121 q = icalcomponent_get_first_property(WC->disp_cal[i].cal,
122 ICAL_DTSTART_PROPERTY);
124 t = icalproperty_get_dtstart(q);
129 memset(&d_tm, 0, sizeof d_tm);
130 d_tm.tm_year = t.year - 1900;
131 d_tm.tm_mon = t.month - 1;
132 d_tm.tm_mday = t.day;
133 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
134 wprintf("<i>%s</i> %s<br>",
138 tt = icaltime_as_timet(t);
139 fmt_date(buf, tt, 1);
140 wprintf("<i>%s</i> %s<br>",
141 _("Starting date/time:"), buf);
145 q = icalcomponent_get_first_property(WC->disp_cal[i].cal,
146 ICAL_DTEND_PROPERTY);
148 t = icalproperty_get_dtend(q);
149 tt = icaltime_as_timet(t);
150 fmt_date(buf, tt, 1);
151 wprintf("<i>%s</i> %s<br>",
152 _("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>");
185 * \brief Display one day of a whole month view of a calendar
186 * \param thetime the month we want to see
188 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
198 struct icaltimetype t;
199 int month, day, year;
200 int all_day_event = 0;
201 char calhourformat[16];
204 get_preference("calhourformat", calhourformat, sizeof calhourformat);
205 if (!strcasecmp(calhourformat, "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];
306 /** Determine what day to start.
307 * First, back up to the 1st of the month...
309 memset(&starting_tm, 0, sizeof(struct tm));
310 starting_tm.tm_year = year - 1900;
311 starting_tm.tm_mon = month - 1;
312 starting_tm.tm_mday = day;
313 thetime = mktime(&starting_tm);
315 memcpy(&tm, &starting_tm, sizeof(struct tm));
316 while (tm.tm_mday != 1) {
317 thetime = thetime - (time_t)86400; /* go back 24 hours */
318 localtime_r(&thetime, &tm);
321 /** Determine previous and next months ... for links */
322 previous_month = thetime - (time_t)864000L; /* back 10 days */
323 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
325 /** Now back up until we're on a Sunday */
326 localtime_r(&thetime, &tm);
327 while (tm.tm_wday != 0) {
328 thetime = thetime - (time_t)86400; /* go back 24 hours */
329 localtime_r(&thetime, &tm);
332 /** Outer table (to get the background color) */
333 wprintf("<div class=\"fix_scrollbar_bug\">"
334 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
335 "bgcolor=#204B78><TR><TD>\n");
337 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
339 wprintf("<td align=center>");
341 localtime_r(&previous_month, &tm);
342 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
343 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
344 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
346 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
347 wprintf(" "
348 "<font size=+1 color=\"#FFFFFF\">"
351 " ", colheader_label, year);
353 localtime_r(&next_month, &tm);
354 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
355 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
356 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
358 wprintf("</td></tr></table>\n");
360 /** Inner table (the real one) */
361 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
362 "bgcolor=#204B78 id=\"inner_month\"><tr>");
363 colheader_time = thetime;
364 for (i=0; i<7; ++i) {
365 colheader_time = thetime + (i * 86400) ;
366 localtime_r(&colheader_time, &colheader_tm);
367 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
368 wprintf("<td align=center width=14%%>"
369 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
374 /** Now do 35 days */
375 for (i = 0; i < 35; ++i) {
376 localtime_r(&thetime, &tm);
378 /** Before displaying Sunday, start a new row */
383 wprintf("<td bgcolor=\"#%s\" width=14%% height=60 align=left valign=top><b>",
384 ((tm.tm_mon != month-1) ? "DDDDDD" :
385 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
388 if ((i==0) || (tm.tm_mday == 1)) {
389 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
390 wprintf("%s ", colheader_label);
392 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
399 /** put the data here, stupid */
400 calendar_month_view_display_events(thetime);
404 /** After displaying Saturday, end the row */
409 thetime += (time_t)86400; /** ahead 24 hours */
412 wprintf("</table>" /** end of inner table */
413 "</td></tr></table>" /** end of outer table */
417 * Initialize the bubble tooltips.
419 * Yes, this is as stupid as it looks. Instead of just making the call
420 * to btt_enableTooltips() straight away, we have to create a timer event
421 * and let it initialize as an event after 1 millisecond. This is to
422 * work around a bug in Internet Explorer that causes it to crash if we
423 * manipulate the innerHTML of various DOM nodes while the page is still
424 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
425 * for more information.
427 wprintf("<script type=\"text/javascript\">"
428 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
434 * \brief view one month. brief view
435 * \param year the year
436 * \param month the month
437 * \param day the actual day we want to see
439 void calendar_brief_month_view(int year, int month, int day) {
440 struct tm starting_tm;
444 time_t previous_month;
446 char month_label[32];
448 /** Determine what day to start.
449 * First, back up to the 1st of the month...
451 memset(&starting_tm, 0, sizeof(struct tm));
452 starting_tm.tm_year = year - 1900;
453 starting_tm.tm_mon = month - 1;
454 starting_tm.tm_mday = day;
455 thetime = mktime(&starting_tm);
457 memcpy(&tm, &starting_tm, sizeof(struct tm));
458 while (tm.tm_mday != 1) {
459 thetime = thetime - (time_t)86400; /* go back 24 hours */
460 localtime_r(&thetime, &tm);
463 /** Determine previous and next months ... for links */
464 previous_month = thetime - (time_t)864000L; /* back 10 days */
465 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
467 /** Now back up until we're on a Sunday */
468 localtime_r(&thetime, &tm);
469 while (tm.tm_wday != 0) {
470 thetime = thetime - (time_t)86400; /* go back 24 hours */
471 localtime_r(&thetime, &tm);
474 /** Outer table (to get the background color) */
475 wprintf("<div class=\"fix_scrollbar_bug\">"
476 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
477 "bgcolor=#204B78><TR><TD>\n");
479 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
481 wprintf("<td align=center>");
483 localtime_r(&previous_month, &tm);
484 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
485 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
486 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
488 wc_strftime(month_label, sizeof month_label, "%B", &tm);
489 wprintf(" "
490 "<font size=+1 color=\"#FFFFFF\">"
493 " ", month_label, year);
495 localtime_r(&next_month, &tm);
496 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
497 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
498 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
500 wprintf("</td></tr></table>\n");
502 /** Inner table (the real one) */
503 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
504 "bgcolor=#EEEECC><TR>");
506 wprintf("<tr><td colspan=\"100%\">\n");
508 /** Now do 35 days */
509 for (i = 0; i < 35; ++i) {
510 char weeknumber[255];
511 char weekday_name[32];
513 localtime_r(&thetime, &tm);
516 /** Before displaying Sunday, start a new CELL */
518 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
519 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
520 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
530 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
531 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
535 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
536 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
537 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
539 weekday_name,tm.tm_mday,
542 /** put the data of one day here, stupid */
543 calendar_month_view_brief_events(thetime, daycolor);
546 /** After displaying Saturday, end the row */
548 wprintf("</td></tr></table>\n");
551 thetime += (time_t)86400; /** ahead 24 hours */
554 wprintf("</table>" /** end of inner table */
555 "</td></tr></table>" /** end of outer table */
560 * \brief view one week
561 * this should view just one week, but it's not here yet.
562 * \todo ny implemented
563 * \param year the year
564 * \param month the month
565 * \param day the day which we want to see the week around
567 void calendar_week_view(int year, int month, int day) {
568 wprintf("<center><i>week view FIXME</i></center><br />\n");
573 * \brief display one day
574 * Display events for a particular hour of a particular day.
575 * (Specify hour < 0 to show "all day" events)
576 * \param year the year
577 * \param month the month
579 * \param hour the hour we want to start displaying?????
581 void calendar_day_view_display_events(int year, int month,
585 struct icaltimetype t;
588 int all_day_event = 0;
590 if (WC->num_cal == 0) {
591 // \todo FIXME wprintf("<br /><br /><br />\n");
595 for (i=0; i<(WC->num_cal); ++i) {
596 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
597 ICAL_DTSTART_PROPERTY);
599 t = icalproperty_get_dtstart(p);
600 event_tt = icaltime_as_timet(t);
609 event_tm = gmtime(&event_tt);
612 event_tm = localtime(&event_tt);
615 if ((event_tm->tm_year == (year-1900))
616 && (event_tm->tm_mon == (month-1))
617 && (event_tm->tm_mday == day)
618 && ( ((event_tm->tm_hour == hour)&&(!t.is_date)) || ((hour<0)&&(t.is_date)) )
622 p = icalcomponent_get_first_property(
624 ICAL_SUMMARY_PROPERTY);
628 wprintf("<table border=1 cellpadding=2><TR>"
629 "<td bgcolor=\"#CCCCCC\">"
633 wprintf("<font size=-1>"
634 "<a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d\">",
635 WC->disp_cal[i].cal_msgnum,
639 icalproperty_get_comment(p));
640 wprintf("</a></font><br />\n");
643 wprintf("</td></tr></table>");
656 * \brief view one day
657 * \param year the year
658 * \param month the month
659 * \param day the day we want to display
661 void calendar_day_view(int year, int month, int day) {
663 struct icaltimetype today, yesterday, tomorrow;
664 char calhourformat[16];
667 char daystart_str[16], dayend_str[16];
671 get_preference("calhourformat", calhourformat, sizeof calhourformat);
672 get_preference("daystart", daystart_str, sizeof daystart_str);
673 if (strlen(daystart_str) > 0) daystart = atoi(daystart_str);
674 get_preference("dayend", dayend_str, sizeof dayend_str);
675 if (strlen(dayend_str) > 0) dayend = atoi(dayend_str);
678 /** Figure out the dates for "yesterday" and "tomorrow" links */
680 memset(&today, 0, sizeof(struct icaltimetype));
686 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
688 yesterday = icaltime_normalize(yesterday);
690 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
692 tomorrow = icaltime_normalize(tomorrow);
695 /** Outer table (to get the background color) */
696 wprintf("<div class=\"fix_scrollbar_bug\">"
697 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
698 "bgcolor=#204B78><tr><td>\n");
700 /** Inner table (the real one) */
701 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
702 "bgcolor=#204B78><tr>\n");
704 /** Innermost table (contains hours etc.) */
705 wprintf("<td width=80%%>"
706 "<table width=100%% border=0 cellpadding=1 cellspacing=1 "
707 "bgcolor=#204B78>\n");
709 /** Display events before 8:00 (hour=-1 is all-day events) */
711 "<td bgcolor=\"#CCCCDD\" valign=middle width=10%%></td>"
712 "<td bgcolor=\"#FFFFFF\" valign=top>");
713 for (hour = (-1); hour <= (daystart-1); ++hour) {
714 calendar_day_view_display_events(year, month, day, hour);
716 wprintf("</td></tr>\n");
718 /** Now the middle of the day... */
719 for (hour = daystart; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
720 wprintf("<tr height=30><td bgcolor=\"#CCCCDD\" align=middle "
721 "valign=middle width=10%%>");
722 wprintf("<a href=\"display_edit_event?msgnum=0"
723 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
724 year, month, day, hour
727 if (!strcasecmp(calhourformat, "24")) {
728 wprintf("%2d:00</a> ", hour);
731 wprintf("%d:00%s</a> ",
732 (hour <= 12 ? hour : hour-12),
733 (hour < 12 ? "am" : "pm")
737 wprintf("</td><td bgcolor=\"#FFFFFF\" valign=top>");
739 /* put the data here, stupid */
740 calendar_day_view_display_events(year, month, day, hour);
742 wprintf("</td></tr>\n");
745 /** Display events after 5:00... */
747 "<td bgcolor=\"#CCCCDD\" valign=middle width=10%%></td>"
748 "<td bgcolor=\"#FFFFFF\" valign=top>");
749 for (hour = (dayend+1); hour <= 23; ++hour) {
750 calendar_day_view_display_events(year, month, day, hour);
752 wprintf("</td></tr>\n");
755 wprintf("</table>" /* end of innermost table */
759 wprintf("<td width=20%% valign=top>"); /* begin stuff-on-the-right */
762 /** Begin todays-date-with-left-and-right-arrows */
763 wprintf("<table border=0 width=100%% "
764 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
768 wprintf("<td align=center>");
769 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
770 yesterday.year, yesterday.month, yesterday.day);
771 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
775 memset(&d_tm, 0, sizeof d_tm);
776 d_tm.tm_year = year - 1900;
777 d_tm.tm_mon = month - 1;
779 wc_strftime(d_str, sizeof d_str,
781 "<font size=+2>%B</font><br />"
782 "<font size=+3>%d</font><br />"
783 "<font size=+2>%Y</font><br />"
787 wprintf("%s", d_str);
790 wprintf("<td align=center>");
791 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
792 tomorrow.year, tomorrow.month, tomorrow.day);
793 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
797 wprintf("</tr></table>\n");
798 /** End todays-date-with-left-and-right-arrows */
800 /** \todo In the future we might want to put a month-o-matic here */
802 wprintf("</font></center>\n");
804 wprintf("</td>"); /** end stuff-on-the-right */
808 wprintf("</tr></table>" /** end of inner table */
809 "</td></tr></table></div>" /** end of outer table */
817 * \brief Display today's events.
819 void calendar_summary_view(void) {
822 struct icaltimetype t;
827 int all_day_event = 0;
828 char timestring[SIZ];
830 if (WC->num_cal == 0) {
835 localtime_r(&now, &today_tm);
837 for (i=0; i<(WC->num_cal); ++i) {
838 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
839 ICAL_DTSTART_PROPERTY);
841 t = icalproperty_get_dtstart(p);
842 event_tt = icaltime_as_timet(t);
849 fmt_time(timestring, event_tt);
852 gmtime_r(&event_tt, &event_tm);
855 localtime_r(&event_tt, &event_tm);
858 if ( (event_tm.tm_year == today_tm.tm_year)
859 && (event_tm.tm_mon == today_tm.tm_mon)
860 && (event_tm.tm_mday == today_tm.tm_mday)
864 p = icalcomponent_get_first_property(
866 ICAL_SUMMARY_PROPERTY);
869 icalproperty_get_comment(p));
870 wprintf(" (%s)<br />\n", timestring);
875 free_calendar_buffer();
880 * \brief clean up ical memory
881 * \todo this could get troubel with future ical versions
883 void free_calendar_buffer(void) {
885 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
886 icalcomponent_free(WC->disp_cal[i].cal);
896 * \brief do the whole calendar page
897 * view any part of the calender. decide which way, etc.
899 void do_calendar_view(void) {
902 int year, month, day;
905 /** In case no date was specified, go with today */
907 localtime_r(&now, &tm);
908 year = tm.tm_year + 1900;
909 month = tm.tm_mon + 1;
912 /** Now see if a date was specified */
913 if (strlen(bstr("year")) > 0) year = atoi(bstr("year"));
914 if (strlen(bstr("month")) > 0) month = atoi(bstr("month"));
915 if (strlen(bstr("day")) > 0) day = atoi(bstr("day"));
917 /** How would you like that cooked? */
918 if (strlen(bstr("calview")) > 0) {
919 strcpy(calview, bstr("calview"));
922 strcpy(calview, "month");
925 /** Display the selected view */
926 if (!strcasecmp(calview, "day")) {
927 calendar_day_view(year, month, day);
929 else if (!strcasecmp(calview, "week")) {
930 calendar_week_view(year, month, day);
933 if (WC->wc_view == VIEW_CALBRIEF) {
934 calendar_brief_month_view(year, month, day);
937 calendar_month_view(year, month, day);
941 /** Free the calendar stuff */
942 free_calendar_buffer();
948 * \brief get task due date
949 * Helper function for do_tasks_view().
950 * \param vtodo a task to get the due date
951 * \return the date/time due.
953 time_t get_task_due_date(icalcomponent *vtodo) {
961 * If we're looking at a fully encapsulated VCALENDAR
962 * rather than a VTODO component, recurse into the data
963 * structure until we get a VTODO.
965 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
966 return get_task_due_date(
967 icalcomponent_get_first_component(
968 vtodo, ICAL_VTODO_COMPONENT
973 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
975 return(icaltime_as_timet(icalproperty_get_due(p)));
984 * \brief Compare the due dates of two tasks (this is for sorting)
985 * \param task1 first task to compare
986 * \param task2 second task to compare
988 int task_due_cmp(const void *task1, const void *task2) {
992 t1 = get_task_due_date(((struct disp_cal *)task1)->cal);
993 t2 = get_task_due_date(((struct disp_cal *)task2)->cal);
995 if (t1 < t2) return(-1);
996 if (t1 > t2) return(1);
1004 * \brief do the whole task view stuff
1006 void do_tasks_view(void) {
1013 wprintf("<div class=\"fix_scrollbar_bug\">"
1014 "<table border=0 cellspacing=0 width=100%% bgcolor=\"#FFFFFF\">\n<tr>\n"
1016 wprintf(_("Name of task"));
1017 wprintf("</th><th>");
1018 wprintf(_("Date due"));
1019 wprintf("</th></tr>\n"
1022 /** Sort them if necessary */
1023 if (WC->num_cal > 1) {
1026 sizeof(struct disp_cal),
1031 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1034 wprintf("<tr bgcolor=\"#%s\"><td>",
1035 (bg ? "DDDDDD" : "FFFFFF")
1038 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1039 ICAL_SUMMARY_PROPERTY);
1040 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1041 WC->disp_cal[i].cal_msgnum );
1042 urlescputs(WC->wc_roomname);
1044 wprintf("<img align=middle "
1045 "src=\"static/taskmanag_16x.gif\" border=0> ");
1047 escputs((char *)icalproperty_get_comment(p));
1052 due = get_task_due_date(WC->disp_cal[i].cal);
1053 fmt_date(buf, due, 0);
1054 wprintf("<td><font");
1055 if (due < time(NULL)) {
1056 wprintf(" color=\"#FF0000\"");
1058 wprintf(">%s</font></td></tr>\n", buf);
1061 wprintf("</table></div>\n");
1063 /** Free the list */
1064 free_calendar_buffer();
1068 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */