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);
143 /* Embed the 'show end date/time' loop inside here so it
144 * only executes if this is NOT an all day event.
146 q = icalcomponent_get_first_property(WC->disp_cal[i].cal,
147 ICAL_DTEND_PROPERTY);
149 t = icalproperty_get_dtend(q);
150 tt = icaltime_as_timet(t);
151 fmt_date(buf, tt, 1);
152 wprintf("<i>%s</i> %s<br>",
153 _("Ending date/time:"), buf);
161 q = icalcomponent_get_first_property(
163 ICAL_DESCRIPTION_PROPERTY);
165 wprintf("<i>%s</i> ", _("Notes:"));
166 escputs((char *)icalproperty_get_comment(q));
172 icalproperty_get_comment(p));
173 wprintf("</a></font><br />\n");
176 wprintf("</td></tr></table>");
190 * \brief Display one day of a whole month view of a calendar
191 * \param thetime the month we want to see
193 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
203 struct icaltimetype t;
204 int month, day, year;
205 int all_day_event = 0;
206 char calhourformat[16];
209 get_preference("calhourformat", calhourformat, sizeof calhourformat);
210 if (!strcasecmp(calhourformat, "24")) timeformat="%k:%M";
211 else timeformat="%I:%M %p";
213 localtime_r(&thetime, &today_tm);
214 month = today_tm.tm_mon + 1;
215 day = today_tm.tm_mday;
216 year = today_tm.tm_year + 1900;
218 for (i=0; i<(WC->num_cal); ++i) {
219 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
220 ICAL_DTSTART_PROPERTY);
222 t = icalproperty_get_dtstart(p);
223 event_tt = icaltime_as_timet(t);
225 if (t.is_date) all_day_event = 1;
226 else all_day_event = 0;
229 gmtime_r(&event_tts, &event_tms);
232 localtime_r(&event_tts, &event_tms);
234 /** \todo epoch &! daymask */
235 if ((event_tms.tm_year == today_tm.tm_year)
236 && (event_tms.tm_mon == today_tm.tm_mon)
237 && (event_tms.tm_mday == today_tm.tm_mday)) {
243 p = icalcomponent_get_first_property(
245 ICAL_SUMMARY_PROPERTY);
246 e = icalcomponent_get_first_property(
248 ICAL_DTEND_PROPERTY);
249 if ((p != NULL) && (e != NULL)) {
252 t = icalproperty_get_dtend(e);
253 event_tte = icaltime_as_timet(t);
254 localtime_r(&event_tte, &event_tme);
255 difftime=(event_tte-event_tts)/60;
256 hours=(int)(difftime / 60);
257 minutes=difftime % 60;
258 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
260 "<a href=\"display_edit_event?msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\">",
264 WC->disp_cal[i].cal_msgnum,
272 icalproperty_get_comment(p));
273 /** \todo: allso ammitime format */
274 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
275 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
277 wprintf("</a></font></td>"
278 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
295 * \brief view one month. pretty view
296 * \param year the year
297 * \param month the month
298 * \param day the actual day we want to see
300 void calendar_month_view(int year, int month, int day) {
301 struct tm starting_tm;
305 time_t previous_month;
307 time_t colheader_time;
308 struct tm colheader_tm;
309 char colheader_label[32];
311 /** Determine what day to start.
312 * First, back up to the 1st of the month...
314 memset(&starting_tm, 0, sizeof(struct tm));
315 starting_tm.tm_year = year - 1900;
316 starting_tm.tm_mon = month - 1;
317 starting_tm.tm_mday = day;
318 thetime = mktime(&starting_tm);
320 memcpy(&tm, &starting_tm, sizeof(struct tm));
321 while (tm.tm_mday != 1) {
322 thetime = thetime - (time_t)86400; /* go back 24 hours */
323 localtime_r(&thetime, &tm);
326 /** Determine previous and next months ... for links */
327 previous_month = thetime - (time_t)864000L; /* back 10 days */
328 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
330 /** Now back up until we're on a Sunday */
331 localtime_r(&thetime, &tm);
332 while (tm.tm_wday != 0) {
333 thetime = thetime - (time_t)86400; /* go back 24 hours */
334 localtime_r(&thetime, &tm);
337 /** Outer table (to get the background color) */
338 wprintf("<div class=\"fix_scrollbar_bug\">"
339 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
340 "bgcolor=#204B78><TR><TD>\n");
342 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
344 wprintf("<td align=center>");
346 localtime_r(&previous_month, &tm);
347 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
348 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
349 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
351 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
352 wprintf(" "
353 "<font size=+1 color=\"#FFFFFF\">"
356 " ", colheader_label, year);
358 localtime_r(&next_month, &tm);
359 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
360 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
361 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
363 wprintf("</td></tr></table>\n");
365 /** Inner table (the real one) */
366 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
367 "bgcolor=#204B78 id=\"inner_month\"><tr>");
368 colheader_time = thetime;
369 for (i=0; i<7; ++i) {
370 colheader_time = thetime + (i * 86400) ;
371 localtime_r(&colheader_time, &colheader_tm);
372 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
373 wprintf("<td align=center width=14%%>"
374 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
379 /** Now do 35 days */
380 for (i = 0; i < 35; ++i) {
381 localtime_r(&thetime, &tm);
383 /** Before displaying Sunday, start a new row */
388 wprintf("<td bgcolor=\"#%s\" width=14%% height=60 align=left valign=top><b>",
389 ((tm.tm_mon != month-1) ? "DDDDDD" :
390 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
393 if ((i==0) || (tm.tm_mday == 1)) {
394 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
395 wprintf("%s ", colheader_label);
397 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
404 /** put the data here, stupid */
405 calendar_month_view_display_events(thetime);
409 /** After displaying Saturday, end the row */
414 thetime += (time_t)86400; /** ahead 24 hours */
417 wprintf("</table>" /** end of inner table */
418 "</td></tr></table>" /** end of outer table */
422 * Initialize the bubble tooltips.
424 * Yes, this is as stupid as it looks. Instead of just making the call
425 * to btt_enableTooltips() straight away, we have to create a timer event
426 * and let it initialize as an event after 1 millisecond. This is to
427 * work around a bug in Internet Explorer that causes it to crash if we
428 * manipulate the innerHTML of various DOM nodes while the page is still
429 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
430 * for more information.
432 wprintf("<script type=\"text/javascript\">"
433 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
439 * \brief view one month. brief view
440 * \param year the year
441 * \param month the month
442 * \param day the actual day we want to see
444 void calendar_brief_month_view(int year, int month, int day) {
445 struct tm starting_tm;
449 time_t previous_month;
451 char month_label[32];
453 /** Determine what day to start.
454 * First, back up to the 1st of the month...
456 memset(&starting_tm, 0, sizeof(struct tm));
457 starting_tm.tm_year = year - 1900;
458 starting_tm.tm_mon = month - 1;
459 starting_tm.tm_mday = day;
460 thetime = mktime(&starting_tm);
462 memcpy(&tm, &starting_tm, sizeof(struct tm));
463 while (tm.tm_mday != 1) {
464 thetime = thetime - (time_t)86400; /* go back 24 hours */
465 localtime_r(&thetime, &tm);
468 /** Determine previous and next months ... for links */
469 previous_month = thetime - (time_t)864000L; /* back 10 days */
470 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
472 /** Now back up until we're on a Sunday */
473 localtime_r(&thetime, &tm);
474 while (tm.tm_wday != 0) {
475 thetime = thetime - (time_t)86400; /* go back 24 hours */
476 localtime_r(&thetime, &tm);
479 /** Outer table (to get the background color) */
480 wprintf("<div class=\"fix_scrollbar_bug\">"
481 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
482 "bgcolor=#204B78><TR><TD>\n");
484 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
486 wprintf("<td align=center>");
488 localtime_r(&previous_month, &tm);
489 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
490 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
491 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
493 wc_strftime(month_label, sizeof month_label, "%B", &tm);
494 wprintf(" "
495 "<font size=+1 color=\"#FFFFFF\">"
498 " ", month_label, year);
500 localtime_r(&next_month, &tm);
501 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
502 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
503 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
505 wprintf("</td></tr></table>\n");
507 /** Inner table (the real one) */
508 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
509 "bgcolor=#EEEECC><TR>");
511 wprintf("<tr><td colspan=\"100%\">\n");
513 /** Now do 35 days */
514 for (i = 0; i < 35; ++i) {
515 char weeknumber[255];
516 char weekday_name[32];
518 localtime_r(&thetime, &tm);
521 /** Before displaying Sunday, start a new CELL */
523 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
524 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
525 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
535 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
536 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
540 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
541 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
542 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
544 weekday_name,tm.tm_mday,
547 /** put the data of one day here, stupid */
548 calendar_month_view_brief_events(thetime, daycolor);
551 /** After displaying Saturday, end the row */
553 wprintf("</td></tr></table>\n");
556 thetime += (time_t)86400; /** ahead 24 hours */
559 wprintf("</table>" /** end of inner table */
560 "</td></tr></table>" /** end of outer table */
565 * \brief view one week
566 * this should view just one week, but it's not here yet.
567 * \todo ny implemented
568 * \param year the year
569 * \param month the month
570 * \param day the day which we want to see the week around
572 void calendar_week_view(int year, int month, int day) {
573 wprintf("<center><i>week view FIXME</i></center><br />\n");
578 * \brief display one day
579 * Display events for a particular hour of a particular day.
580 * (Specify hour < 0 to show "all day" events)
581 * \param year the year
582 * \param month the month
584 * \param hour the hour we want to start displaying?????
586 void calendar_day_view_display_events(int year, int month,
590 struct icaltimetype t;
593 int all_day_event = 0;
595 if (WC->num_cal == 0) {
596 // \todo FIXME wprintf("<br /><br /><br />\n");
600 for (i=0; i<(WC->num_cal); ++i) {
601 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
602 ICAL_DTSTART_PROPERTY);
604 t = icalproperty_get_dtstart(p);
605 event_tt = icaltime_as_timet(t);
614 event_tm = gmtime(&event_tt);
617 event_tm = localtime(&event_tt);
620 if ((event_tm->tm_year == (year-1900))
621 && (event_tm->tm_mon == (month-1))
622 && (event_tm->tm_mday == day)
623 && ( ((event_tm->tm_hour == hour)&&(!t.is_date)) || ((hour<0)&&(t.is_date)) )
627 p = icalcomponent_get_first_property(
629 ICAL_SUMMARY_PROPERTY);
633 wprintf("<table border=1 cellpadding=2><TR>"
634 "<td bgcolor=\"#CCCCCC\">"
638 wprintf("<font size=-1>"
639 "<a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d\">",
640 WC->disp_cal[i].cal_msgnum,
644 icalproperty_get_comment(p));
645 wprintf("</a></font><br />\n");
648 wprintf("</td></tr></table>");
661 * \brief view one day
662 * \param year the year
663 * \param month the month
664 * \param day the day we want to display
666 void calendar_day_view(int year, int month, int day) {
668 struct icaltimetype today, yesterday, tomorrow;
669 char calhourformat[16];
672 char daystart_str[16], dayend_str[16];
676 get_preference("calhourformat", calhourformat, sizeof calhourformat);
677 get_preference("daystart", daystart_str, sizeof daystart_str);
678 if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
679 get_preference("dayend", dayend_str, sizeof dayend_str);
680 if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str);
683 /** Figure out the dates for "yesterday" and "tomorrow" links */
685 memset(&today, 0, sizeof(struct icaltimetype));
691 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
693 yesterday = icaltime_normalize(yesterday);
695 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
697 tomorrow = icaltime_normalize(tomorrow);
700 /** Outer table (to get the background color) */
701 wprintf("<div class=\"fix_scrollbar_bug\">"
702 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
703 "bgcolor=#204B78><tr><td>\n");
705 /** Inner table (the real one) */
706 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
707 "bgcolor=#204B78><tr>\n");
709 /** Innermost table (contains hours etc.) */
710 wprintf("<td width=80%%>"
711 "<table width=100%% border=0 cellpadding=1 cellspacing=1 "
712 "bgcolor=#204B78>\n");
714 /** Display events before 8:00 (hour=-1 is all-day events) */
716 "<td bgcolor=\"#CCCCDD\" valign=middle width=10%%></td>"
717 "<td bgcolor=\"#FFFFFF\" valign=top>");
718 for (hour = (-1); hour <= (daystart-1); ++hour) {
719 calendar_day_view_display_events(year, month, day, hour);
721 wprintf("</td></tr>\n");
723 /** Now the middle of the day... */
724 for (hour = daystart; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
725 wprintf("<tr height=30><td bgcolor=\"#CCCCDD\" align=middle "
726 "valign=middle width=10%%>");
727 wprintf("<a href=\"display_edit_event?msgnum=0"
728 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
729 year, month, day, hour
732 if (!strcasecmp(calhourformat, "24")) {
733 wprintf("%2d:00</a> ", hour);
736 wprintf("%d:00%s</a> ",
737 (hour <= 12 ? hour : hour-12),
738 (hour < 12 ? "am" : "pm")
742 wprintf("</td><td bgcolor=\"#FFFFFF\" valign=top>");
744 /* put the data here, stupid */
745 calendar_day_view_display_events(year, month, day, hour);
747 wprintf("</td></tr>\n");
750 /** Display events after 5:00... */
752 "<td bgcolor=\"#CCCCDD\" valign=middle width=10%%></td>"
753 "<td bgcolor=\"#FFFFFF\" valign=top>");
754 for (hour = (dayend+1); hour <= 23; ++hour) {
755 calendar_day_view_display_events(year, month, day, hour);
757 wprintf("</td></tr>\n");
760 wprintf("</table>" /* end of innermost table */
764 wprintf("<td width=20%% valign=top>"); /* begin stuff-on-the-right */
767 /** Begin todays-date-with-left-and-right-arrows */
768 wprintf("<table border=0 width=100%% "
769 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
773 wprintf("<td align=center>");
774 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
775 yesterday.year, yesterday.month, yesterday.day);
776 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
780 memset(&d_tm, 0, sizeof d_tm);
781 d_tm.tm_year = year - 1900;
782 d_tm.tm_mon = month - 1;
784 wc_strftime(d_str, sizeof d_str,
786 "<font size=+2>%B</font><br />"
787 "<font size=+3>%d</font><br />"
788 "<font size=+2>%Y</font><br />"
792 wprintf("%s", d_str);
795 wprintf("<td align=center>");
796 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
797 tomorrow.year, tomorrow.month, tomorrow.day);
798 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
802 wprintf("</tr></table>\n");
803 /** End todays-date-with-left-and-right-arrows */
805 /** \todo In the future we might want to put a month-o-matic here */
807 wprintf("</font></center>\n");
809 wprintf("</td>"); /** end stuff-on-the-right */
813 wprintf("</tr></table>" /** end of inner table */
814 "</td></tr></table></div>" /** end of outer table */
822 * \brief Display today's events.
824 void calendar_summary_view(void) {
827 struct icaltimetype t;
832 int all_day_event = 0;
833 char timestring[SIZ];
835 if (WC->num_cal == 0) {
840 localtime_r(&now, &today_tm);
842 for (i=0; i<(WC->num_cal); ++i) {
843 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
844 ICAL_DTSTART_PROPERTY);
846 t = icalproperty_get_dtstart(p);
847 event_tt = icaltime_as_timet(t);
854 fmt_time(timestring, event_tt);
857 gmtime_r(&event_tt, &event_tm);
860 localtime_r(&event_tt, &event_tm);
863 if ( (event_tm.tm_year == today_tm.tm_year)
864 && (event_tm.tm_mon == today_tm.tm_mon)
865 && (event_tm.tm_mday == today_tm.tm_mday)
869 p = icalcomponent_get_first_property(
871 ICAL_SUMMARY_PROPERTY);
874 icalproperty_get_comment(p));
875 wprintf(" (%s)<br />\n", timestring);
880 free_calendar_buffer();
885 * \brief clean up ical memory
886 * \todo this could get troubel with future ical versions
888 void free_calendar_buffer(void) {
890 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
891 icalcomponent_free(WC->disp_cal[i].cal);
901 * \brief do the whole calendar page
902 * view any part of the calender. decide which way, etc.
904 void do_calendar_view(void) {
907 int year, month, day;
910 /** In case no date was specified, go with today */
912 localtime_r(&now, &tm);
913 year = tm.tm_year + 1900;
914 month = tm.tm_mon + 1;
917 /** Now see if a date was specified */
918 if (!IsEmptyStr(bstr("year"))) year = atoi(bstr("year"));
919 if (!IsEmptyStr(bstr("month"))) month = atoi(bstr("month"));
920 if (!IsEmptyStr(bstr("day"))) day = atoi(bstr("day"));
922 /** How would you like that cooked? */
923 if (!IsEmptyStr(bstr("calview"))) {
924 strcpy(calview, bstr("calview"));
927 strcpy(calview, "month");
930 /** Display the selected view */
931 if (!strcasecmp(calview, "day")) {
932 calendar_day_view(year, month, day);
934 else if (!strcasecmp(calview, "week")) {
935 calendar_week_view(year, month, day);
938 if (WC->wc_view == VIEW_CALBRIEF) {
939 calendar_brief_month_view(year, month, day);
942 calendar_month_view(year, month, day);
946 /** Free the calendar stuff */
947 free_calendar_buffer();
953 * \brief get task due date
954 * Helper function for do_tasks_view().
955 * \param vtodo a task to get the due date
956 * \return the date/time due.
958 time_t get_task_due_date(icalcomponent *vtodo) {
966 * If we're looking at a fully encapsulated VCALENDAR
967 * rather than a VTODO component, recurse into the data
968 * structure until we get a VTODO.
970 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
971 return get_task_due_date(
972 icalcomponent_get_first_component(
973 vtodo, ICAL_VTODO_COMPONENT
978 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
980 return(icaltime_as_timet(icalproperty_get_due(p)));
989 * \brief Compare the due dates of two tasks (this is for sorting)
990 * \param task1 first task to compare
991 * \param task2 second task to compare
993 int task_due_cmp(const void *task1, const void *task2) {
997 t1 = get_task_due_date(((struct disp_cal *)task1)->cal);
998 t2 = get_task_due_date(((struct disp_cal *)task2)->cal);
1000 if (t1 < t2) return(-1);
1001 if (t1 > t2) return(1);
1009 * \brief do the whole task view stuff
1011 void do_tasks_view(void) {
1018 wprintf("<div class=\"fix_scrollbar_bug\">"
1019 "<table class=\"calendar_view_background\">\n<tr>\n"
1021 wprintf(_("Name of task"));
1022 wprintf("</th><th>");
1023 wprintf(_("Date due"));
1024 wprintf("</th></tr>\n"
1027 /** Sort them if necessary */
1028 if (WC->num_cal > 1) {
1031 sizeof(struct disp_cal),
1036 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1039 wprintf("<tr bgcolor=\"#%s\"><td>",
1040 (bg ? "DDDDDD" : "FFFFFF")
1043 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1044 ICAL_SUMMARY_PROPERTY);
1045 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1046 WC->disp_cal[i].cal_msgnum );
1047 urlescputs(WC->wc_roomname);
1049 wprintf("<img align=middle "
1050 "src=\"static/taskmanag_16x.gif\" border=0> ");
1052 escputs((char *)icalproperty_get_comment(p));
1057 due = get_task_due_date(WC->disp_cal[i].cal);
1058 fmt_date(buf, due, 0);
1059 wprintf("<td><font");
1060 if (due < time(NULL)) {
1061 wprintf(" color=\"#FF0000\"");
1063 wprintf(">%s</font></td></tr>\n", buf);
1066 wprintf("</table></div>\n");
1068 /** Free the list */
1069 free_calendar_buffer();
1073 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */