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) {
43 icalproperty *p = NULL;
44 icalproperty *pe = NULL;
45 icalproperty *q = NULL;
46 struct icaltimetype t;
48 int all_day_event = 0;
52 if (WC->num_cal == 0) {
53 wprintf("<br /><br /><br />\n");
57 localtime_r(&thetime, &today_tm);
58 month = today_tm.tm_mon + 1;
59 day = today_tm.tm_mday;
60 year = today_tm.tm_year + 1900;
62 for (i=0; i<(WC->num_cal); ++i) {
63 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
64 ICAL_DTSTART_PROPERTY);
65 pe = icalcomponent_get_first_property(WC->disp_cal[i].cal,
67 if ((p != NULL) && (pe != NULL)) {
68 t = icalproperty_get_dtend(pe);
69 event_tte = icaltime_as_timet(t);
71 t = icalproperty_get_dtstart(p);
72 event_tt = icaltime_as_timet(t);
74 if (t.is_date) all_day_event = 1;
75 else all_day_event = 0;
78 gmtime_r(&event_tt, &event_tm);
79 gmtime_r(&event_tte, &event_te);
82 localtime_r(&event_tt, &event_tm);
83 localtime_r(&event_tte, &event_te);
86 if ((event_tm.tm_year <= today_tm.tm_year)
87 && (event_tm.tm_mon <= today_tm.tm_mon)
88 && (event_tm.tm_mday <= today_tm.tm_mday)
89 && (event_te.tm_year >= today_tm.tm_year)
90 && (event_te.tm_mon >= today_tm.tm_mon)
91 && (event_te.tm_mday >= today_tm.tm_mday)) {
93 p = icalcomponent_get_first_property(
95 ICAL_SUMMARY_PROPERTY);
99 wprintf("<table border=0 cellpadding=2><TR>"
100 "<td bgcolor=\"#CCCCDD\">"
104 wprintf("<font size=-1>"
105 "<a href=\"display_edit_event?"
106 "msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\""
108 WC->disp_cal[i].cal_msgnum,
115 wprintf("<i>%s</i> ", _("Summary:"));
116 escputs((char *)icalproperty_get_comment(p));
119 q = icalcomponent_get_first_property(
121 ICAL_LOCATION_PROPERTY);
123 wprintf("<i>%s</i> ", _("Location:"));
124 escputs((char *)icalproperty_get_comment(q));
129 * Only show start/end times if we're actually looking at the VEVENT
130 * component. Otherwise it shows bogus dates for e.g. timezones
132 if (icalcomponent_isa(WC->disp_cal[i].cal) == ICAL_VEVENT_COMPONENT) {
134 q = icalcomponent_get_first_property(WC->disp_cal[i].cal,
135 ICAL_DTSTART_PROPERTY);
137 t = icalproperty_get_dtstart(q);
142 memset(&d_tm, 0, sizeof d_tm);
143 d_tm.tm_year = t.year - 1900;
144 d_tm.tm_mon = t.month - 1;
145 d_tm.tm_mday = t.day;
146 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
147 wprintf("<i>%s</i> %s<br>",
151 tt = icaltime_as_timet(t);
152 fmt_date(buf, tt, 1);
153 wprintf("<i>%s</i> %s<br>",
154 _("Starting date/time:"), buf);
156 /* Embed the 'show end date/time' loop inside here so it
157 * only executes if this is NOT an all day event.
159 q = icalcomponent_get_first_property(WC->disp_cal[i].cal,
160 ICAL_DTEND_PROPERTY);
162 t = icalproperty_get_dtend(q);
163 tt = icaltime_as_timet(t);
164 fmt_date(buf, tt, 1);
165 wprintf("<i>%s</i> %s<br>",
166 _("Ending date/time:"), buf);
174 q = icalcomponent_get_first_property(
176 ICAL_DESCRIPTION_PROPERTY);
178 wprintf("<i>%s</i> ", _("Notes:"));
179 escputs((char *)icalproperty_get_comment(q));
185 icalproperty_get_comment(p));
186 wprintf("</a></font><br />\n");
189 wprintf("</td></tr></table>");
203 * \brief Display one day of a whole month view of a calendar
204 * \param thetime the month we want to see
206 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
216 struct icaltimetype t;
217 int month, day, year;
218 int all_day_event = 0;
219 char calhourformat[16];
222 get_preference("calhourformat", calhourformat, sizeof calhourformat);
223 if (!strcasecmp(calhourformat, "24")) timeformat="%k:%M";
224 else timeformat="%I:%M %p";
226 localtime_r(&thetime, &today_tm);
227 month = today_tm.tm_mon + 1;
228 day = today_tm.tm_mday;
229 year = today_tm.tm_year + 1900;
231 for (i=0; i<(WC->num_cal); ++i) {
232 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
233 ICAL_DTSTART_PROPERTY);
235 t = icalproperty_get_dtstart(p);
236 event_tt = icaltime_as_timet(t);
238 if (t.is_date) all_day_event = 1;
239 else all_day_event = 0;
242 gmtime_r(&event_tts, &event_tms);
245 localtime_r(&event_tts, &event_tms);
247 /** \todo epoch &! daymask */
248 if ((event_tms.tm_year == today_tm.tm_year)
249 && (event_tms.tm_mon == today_tm.tm_mon)
250 && (event_tms.tm_mday == today_tm.tm_mday)) {
256 p = icalcomponent_get_first_property(
258 ICAL_SUMMARY_PROPERTY);
259 e = icalcomponent_get_first_property(
261 ICAL_DTEND_PROPERTY);
262 if ((p != NULL) && (e != NULL)) {
265 t = icalproperty_get_dtend(e);
266 event_tte = icaltime_as_timet(t);
267 localtime_r(&event_tte, &event_tme);
268 difftime=(event_tte-event_tts)/60;
269 hours=(int)(difftime / 60);
270 minutes=difftime % 60;
271 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
273 "<a href=\"display_edit_event?msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\">",
277 WC->disp_cal[i].cal_msgnum,
285 icalproperty_get_comment(p));
286 /** \todo: allso ammitime format */
287 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
288 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
290 wprintf("</a></font></td>"
291 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
308 * \brief view one month. pretty view
309 * \param year the year
310 * \param month the month
311 * \param day the actual day we want to see
313 void calendar_month_view(int year, int month, int day) {
314 struct tm starting_tm;
318 time_t previous_month;
320 time_t colheader_time;
321 struct tm colheader_tm;
322 char colheader_label[32];
324 /** Determine what day to start.
325 * First, back up to the 1st of the month...
327 memset(&starting_tm, 0, sizeof(struct tm));
328 starting_tm.tm_year = year - 1900;
329 starting_tm.tm_mon = month - 1;
330 starting_tm.tm_mday = day;
331 thetime = mktime(&starting_tm);
333 memcpy(&tm, &starting_tm, sizeof(struct tm));
334 while (tm.tm_mday != 1) {
335 thetime = thetime - (time_t)86400; /* go back 24 hours */
336 localtime_r(&thetime, &tm);
339 /** Determine previous and next months ... for links */
340 previous_month = thetime - (time_t)864000L; /* back 10 days */
341 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
343 /** Now back up until we're on a Sunday */
344 localtime_r(&thetime, &tm);
345 while (tm.tm_wday != 0) {
346 thetime = thetime - (time_t)86400; /* go back 24 hours */
347 localtime_r(&thetime, &tm);
350 /** Outer table (to get the background color) */
351 wprintf("<div class=\"fix_scrollbar_bug\">"
352 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
353 "bgcolor=#204B78><TR><TD>\n");
355 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
357 wprintf("<td align=center>");
359 localtime_r(&previous_month, &tm);
360 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
361 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
362 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
364 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
365 wprintf(" "
366 "<font size=+1 color=\"#FFFFFF\">"
369 " ", colheader_label, year);
371 localtime_r(&next_month, &tm);
372 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
373 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
374 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
376 wprintf("</td></tr></table>\n");
378 /** Inner table (the real one) */
379 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
380 "bgcolor=#204B78 id=\"inner_month\"><tr>");
381 colheader_time = thetime;
382 for (i=0; i<7; ++i) {
383 colheader_time = thetime + (i * 86400) ;
384 localtime_r(&colheader_time, &colheader_tm);
385 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
386 wprintf("<td align=center width=14%%>"
387 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
392 /** Now do 35 days */
393 for (i = 0; i < 35; ++i) {
394 localtime_r(&thetime, &tm);
396 /** Before displaying Sunday, start a new row */
401 wprintf("<td bgcolor=\"#%s\" width=14%% height=60 align=left valign=top><b>",
402 ((tm.tm_mon != month-1) ? "DDDDDD" :
403 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
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 */
427 thetime += (time_t)86400; /** ahead 24 hours */
430 wprintf("</table>" /** end of inner table */
431 "</td></tr></table>" /** end of outer table */
435 * Initialize the bubble tooltips.
437 * Yes, this is as stupid as it looks. Instead of just making the call
438 * to btt_enableTooltips() straight away, we have to create a timer event
439 * and let it initialize as an event after 1 millisecond. This is to
440 * work around a bug in Internet Explorer that causes it to crash if we
441 * manipulate the innerHTML of various DOM nodes while the page is still
442 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
443 * for more information.
445 wprintf("<script type=\"text/javascript\">"
446 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
452 * \brief view one month. brief view
453 * \param year the year
454 * \param month the month
455 * \param day the actual day we want to see
457 void calendar_brief_month_view(int year, int month, int day) {
458 struct tm starting_tm;
462 time_t previous_month;
464 char month_label[32];
466 /** Determine what day to start.
467 * First, back up to the 1st of the month...
469 memset(&starting_tm, 0, sizeof(struct tm));
470 starting_tm.tm_year = year - 1900;
471 starting_tm.tm_mon = month - 1;
472 starting_tm.tm_mday = day;
473 thetime = mktime(&starting_tm);
475 memcpy(&tm, &starting_tm, sizeof(struct tm));
476 while (tm.tm_mday != 1) {
477 thetime = thetime - (time_t)86400; /* go back 24 hours */
478 localtime_r(&thetime, &tm);
481 /** Determine previous and next months ... for links */
482 previous_month = thetime - (time_t)864000L; /* back 10 days */
483 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
485 /** Now back up until we're on a Sunday */
486 localtime_r(&thetime, &tm);
487 while (tm.tm_wday != 0) {
488 thetime = thetime - (time_t)86400; /* go back 24 hours */
489 localtime_r(&thetime, &tm);
492 /** Outer table (to get the background color) */
493 wprintf("<div class=\"fix_scrollbar_bug\">"
494 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
495 "bgcolor=#204B78><TR><TD>\n");
497 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
499 wprintf("<td align=center>");
501 localtime_r(&previous_month, &tm);
502 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
503 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
504 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
506 wc_strftime(month_label, sizeof month_label, "%B", &tm);
507 wprintf(" "
508 "<font size=+1 color=\"#FFFFFF\">"
511 " ", month_label, year);
513 localtime_r(&next_month, &tm);
514 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
515 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
516 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
518 wprintf("</td></tr></table>\n");
520 /** Inner table (the real one) */
521 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
522 "bgcolor=#EEEECC><TR>");
524 wprintf("<tr><td colspan=\"100%\">\n");
526 /** Now do 35 days */
527 for (i = 0; i < 35; ++i) {
528 char weeknumber[255];
529 char weekday_name[32];
531 localtime_r(&thetime, &tm);
534 /** Before displaying Sunday, start a new CELL */
536 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
537 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
538 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
548 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
549 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
553 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
554 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
555 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
557 weekday_name,tm.tm_mday,
560 /** put the data of one day here, stupid */
561 calendar_month_view_brief_events(thetime, daycolor);
564 /** After displaying Saturday, end the row */
566 wprintf("</td></tr></table>\n");
569 thetime += (time_t)86400; /** ahead 24 hours */
572 wprintf("</table>" /** end of inner table */
573 "</td></tr></table>" /** end of outer table */
578 * \brief view one week
579 * this should view just one week, but it's not here yet.
580 * \todo ny implemented
581 * \param year the year
582 * \param month the month
583 * \param day the day which we want to see the week around
585 void calendar_week_view(int year, int month, int day) {
586 wprintf("<center><i>week view FIXME</i></center><br />\n");
591 * \brief display one day
592 * Display events for a particular hour of a particular day.
593 * (Specify hour < 0 to show "all day" events)
594 * \param year the year
595 * \param month the month
597 * \param hour the hour we want to start displaying?????
599 void calendar_day_view_display_events(int year, int month,
603 icalproperty *pe = NULL;
604 struct icaltimetype t;
605 struct icaltimetype te;
610 int all_day_event = 0;
612 if (WC->num_cal == 0) {
613 // \todo FIXME wprintf("<br /><br /><br />\n");
617 for (i=0; i<(WC->num_cal); ++i) {
618 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
619 ICAL_DTSTART_PROPERTY);
620 pe = icalcomponent_get_first_property(WC->disp_cal[i].cal,
621 ICAL_DTEND_PROPERTY);
622 if ((p != NULL) && (pe != NULL)) {
623 te = icalproperty_get_dtend(pe);
624 event_tte = icaltime_as_timet(te);
626 t = icalproperty_get_dtstart(p);
627 event_tt = icaltime_as_timet(t);
636 gmtime_r(&event_tt, &event_tm);
637 gmtime_r(&event_tte, &event_te);
640 localtime_r(&event_tt, &event_tm);
641 localtime_r(&event_tte, &event_te);
644 if ((event_tm.tm_year <= (year-1900))
645 && (event_tm.tm_mon <= (month-1))
646 && (event_tm.tm_mday <= day)
647 && ( ((event_tm.tm_hour <= hour)&&(!t.is_date)) || ((hour<0)&&(t.is_date)))
648 && (event_te.tm_year >= (year-1900))
649 && (event_te.tm_mon >= (month-1))
650 && (event_te.tm_mday >= day)
651 && ( ((event_te.tm_hour >= hour)&&(!te.is_date)) || ((hour<0)&&(te.is_date)) ))
653 p = icalcomponent_get_first_property(
655 ICAL_SUMMARY_PROPERTY);
659 wprintf("<table border=1 cellpadding=2><TR>"
660 "<td bgcolor=\"#CCCCCC\">"
664 wprintf("<font size=-1>"
665 "<a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d\">",
666 WC->disp_cal[i].cal_msgnum,
670 icalproperty_get_comment(p));
671 wprintf("</a></font><br />\n");
674 wprintf("</td></tr></table>");
687 * \brief view one day
688 * \param year the year
689 * \param month the month
690 * \param day the day we want to display
692 void calendar_day_view(int year, int month, int day) {
694 struct icaltimetype today, yesterday, tomorrow;
695 char calhourformat[16];
698 char daystart_str[16], dayend_str[16];
702 get_preference("calhourformat", calhourformat, sizeof calhourformat);
703 get_preference("daystart", daystart_str, sizeof daystart_str);
704 if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
705 get_preference("dayend", dayend_str, sizeof dayend_str);
706 if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str);
709 /** Figure out the dates for "yesterday" and "tomorrow" links */
711 memset(&today, 0, sizeof(struct icaltimetype));
717 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
719 yesterday = icaltime_normalize(yesterday);
721 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
723 tomorrow = icaltime_normalize(tomorrow);
726 /** Outer table (to get the background color) */
727 wprintf("<div class=\"fix_scrollbar_bug\">"
728 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
729 "bgcolor=#204B78><tr><td>\n");
731 /** Inner table (the real one) */
732 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
733 "bgcolor=#204B78><tr>\n");
735 /** Innermost table (contains hours etc.) */
736 wprintf("<td width=80%%>"
737 "<table width=100%% border=0 cellpadding=1 cellspacing=1 "
738 "bgcolor=#204B78>\n");
740 /** Display events before 8:00 (hour=-1 is all-day events) */
742 "<td bgcolor=\"#CCCCDD\" valign=middle width=10%%></td>"
743 "<td bgcolor=\"#FFFFFF\" valign=top>");
744 for (hour = (-1); hour <= (daystart-1); ++hour) {
745 calendar_day_view_display_events(year, month, day, hour);
747 wprintf("</td></tr>\n");
749 /** Now the middle of the day... */
750 for (hour = daystart; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
751 wprintf("<tr height=30><td bgcolor=\"#CCCCDD\" align=middle "
752 "valign=middle width=10%%>");
753 wprintf("<a href=\"display_edit_event?msgnum=0"
754 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
755 year, month, day, hour
758 if (!strcasecmp(calhourformat, "24")) {
759 wprintf("%2d:00</a> ", hour);
762 wprintf("%d:00%s</a> ",
763 (hour <= 12 ? hour : hour-12),
764 (hour < 12 ? "am" : "pm")
768 wprintf("</td><td bgcolor=\"#FFFFFF\" valign=top>");
770 /* put the data here, stupid */
771 calendar_day_view_display_events(year, month, day, hour);
773 wprintf("</td></tr>\n");
776 /** Display events after 5:00... */
778 "<td bgcolor=\"#CCCCDD\" valign=middle width=10%%></td>"
779 "<td bgcolor=\"#FFFFFF\" valign=top>");
780 for (hour = (dayend+1); hour <= 23; ++hour) {
781 calendar_day_view_display_events(year, month, day, hour);
783 wprintf("</td></tr>\n");
786 wprintf("</table>" /* end of innermost table */
790 wprintf("<td width=20%% valign=top>"); /* begin stuff-on-the-right */
793 /** Begin todays-date-with-left-and-right-arrows */
794 wprintf("<table border=0 width=100%% "
795 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
799 wprintf("<td align=center>");
800 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
801 yesterday.year, yesterday.month, yesterday.day);
802 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
806 memset(&d_tm, 0, sizeof d_tm);
807 d_tm.tm_year = year - 1900;
808 d_tm.tm_mon = month - 1;
810 wc_strftime(d_str, sizeof d_str,
812 "<font size=+2>%B</font><br />"
813 "<font size=+3>%d</font><br />"
814 "<font size=+2>%Y</font><br />"
818 wprintf("%s", d_str);
821 wprintf("<td align=center>");
822 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
823 tomorrow.year, tomorrow.month, tomorrow.day);
824 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
828 wprintf("</tr></table>\n");
829 /** End todays-date-with-left-and-right-arrows */
831 /** \todo In the future we might want to put a month-o-matic here */
833 wprintf("</font></center>\n");
835 wprintf("</td>"); /** end stuff-on-the-right */
839 wprintf("</tr></table>" /** end of inner table */
840 "</td></tr></table></div>" /** end of outer table */
848 * \brief Display today's events.
850 void calendar_summary_view(void) {
853 struct icaltimetype t;
858 int all_day_event = 0;
859 char timestring[SIZ];
861 if (WC->num_cal == 0) {
866 localtime_r(&now, &today_tm);
868 for (i=0; i<(WC->num_cal); ++i) {
869 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
870 ICAL_DTSTART_PROPERTY);
872 t = icalproperty_get_dtstart(p);
873 event_tt = icaltime_as_timet(t);
880 fmt_time(timestring, event_tt);
883 gmtime_r(&event_tt, &event_tm);
886 localtime_r(&event_tt, &event_tm);
889 if ( (event_tm.tm_year == today_tm.tm_year)
890 && (event_tm.tm_mon == today_tm.tm_mon)
891 && (event_tm.tm_mday == today_tm.tm_mday)
895 p = icalcomponent_get_first_property(
897 ICAL_SUMMARY_PROPERTY);
900 icalproperty_get_comment(p));
901 wprintf(" (%s)<br />\n", timestring);
906 free_calendar_buffer();
911 * \brief clean up ical memory
912 * \todo this could get troubel with future ical versions
914 void free_calendar_buffer(void) {
916 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
917 icalcomponent_free(WC->disp_cal[i].cal);
927 * \brief do the whole calendar page
928 * view any part of the calender. decide which way, etc.
930 void do_calendar_view(void) {
933 int year, month, day;
936 /** In case no date was specified, go with today */
938 localtime_r(&now, &tm);
939 year = tm.tm_year + 1900;
940 month = tm.tm_mon + 1;
943 /** Now see if a date was specified */
944 if (!IsEmptyStr(bstr("year"))) year = atoi(bstr("year"));
945 if (!IsEmptyStr(bstr("month"))) month = atoi(bstr("month"));
946 if (!IsEmptyStr(bstr("day"))) day = atoi(bstr("day"));
948 /** How would you like that cooked? */
949 if (!IsEmptyStr(bstr("calview"))) {
950 strcpy(calview, bstr("calview"));
953 strcpy(calview, "month");
956 /** Display the selected view */
957 if (!strcasecmp(calview, "day")) {
958 calendar_day_view(year, month, day);
960 else if (!strcasecmp(calview, "week")) {
961 calendar_week_view(year, month, day);
964 if (WC->wc_view == VIEW_CALBRIEF) {
965 calendar_brief_month_view(year, month, day);
968 calendar_month_view(year, month, day);
972 /** Free the calendar stuff */
973 free_calendar_buffer();
979 * \brief get task due date
980 * Helper function for do_tasks_view().
981 * \param vtodo a task to get the due date
982 * \return the date/time due.
984 time_t get_task_due_date(icalcomponent *vtodo) {
992 * If we're looking at a fully encapsulated VCALENDAR
993 * rather than a VTODO component, recurse into the data
994 * structure until we get a VTODO.
996 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
997 return get_task_due_date(
998 icalcomponent_get_first_component(
999 vtodo, ICAL_VTODO_COMPONENT
1004 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1006 return(icaltime_as_timet(icalproperty_get_due(p)));
1015 * \brief Compare the due dates of two tasks (this is for sorting)
1016 * \param task1 first task to compare
1017 * \param task2 second task to compare
1019 int task_due_cmp(const void *task1, const void *task2) {
1023 t1 = get_task_due_date(((struct disp_cal *)task1)->cal);
1024 t2 = get_task_due_date(((struct disp_cal *)task2)->cal);
1026 if (t1 < t2) return(-1);
1027 if (t1 > t2) return(1);
1035 * \brief do the whole task view stuff
1037 void do_tasks_view(void) {
1044 wprintf("<div class=\"fix_scrollbar_bug\">"
1045 "<table class=\"calendar_view_background\">\n<tr>\n"
1047 wprintf(_("Name of task"));
1048 wprintf("</th><th>");
1049 wprintf(_("Date due"));
1050 wprintf("</th></tr>\n"
1053 /** Sort them if necessary */
1054 if (WC->num_cal > 1) {
1057 sizeof(struct disp_cal),
1062 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1065 wprintf("<tr bgcolor=\"#%s\"><td>",
1066 (bg ? "DDDDDD" : "FFFFFF")
1069 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1070 ICAL_SUMMARY_PROPERTY);
1071 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1072 WC->disp_cal[i].cal_msgnum );
1073 urlescputs(WC->wc_roomname);
1075 wprintf("<img align=middle "
1076 "src=\"static/taskmanag_16x.gif\" border=0> ");
1078 escputs((char *)icalproperty_get_comment(p));
1083 due = get_task_due_date(WC->disp_cal[i].cal);
1084 fmt_date(buf, due, 0);
1085 wprintf("<td><font");
1086 if (due < time(NULL)) {
1087 wprintf(" color=\"#FF0000\"");
1089 wprintf(">%s</font></td></tr>\n", buf);
1092 wprintf("</table></div>\n");
1094 /** Free the list */
1095 free_calendar_buffer();
1099 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */