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,
68 t = icalproperty_get_dtstart(p);
69 event_tt = icaltime_as_timet(t);
71 if (t.is_date) all_day_event = 1;
72 else all_day_event = 0;
75 gmtime_r(&event_tt, &event_tm);
76 gmtime_r(&event_tt, &event_te);// allday events don't have end-dates.
79 localtime_r(&event_tt, &event_tm);
82 t = icalproperty_get_dtend(pe);
83 event_tte = icaltime_as_timet(t);
84 localtime_r(&event_tte, &event_te);
87 localtime_r(&event_tt, &event_te);
90 if ((event_tm.tm_year <= today_tm.tm_year)
91 && (event_tm.tm_mon <= today_tm.tm_mon)
92 && (event_tm.tm_mday <= today_tm.tm_mday)
93 && (event_te.tm_year >= today_tm.tm_year)
94 && (event_te.tm_mon >= today_tm.tm_mon)
95 && (event_te.tm_mday >= today_tm.tm_mday)) {
97 p = icalcomponent_get_first_property(
99 ICAL_SUMMARY_PROPERTY);
103 wprintf("<table border=0 cellpadding=2><TR>"
104 "<td bgcolor=\"#CCCCDD\">"
108 wprintf("<font size=-1>"
109 "<a href=\"display_edit_event?"
110 "msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\""
112 WC->disp_cal[i].cal_msgnum,
119 wprintf("<i>%s</i> ", _("Summary:"));
120 escputs((char *)icalproperty_get_comment(p));
123 q = icalcomponent_get_first_property(
125 ICAL_LOCATION_PROPERTY);
127 wprintf("<i>%s</i> ", _("Location:"));
128 escputs((char *)icalproperty_get_comment(q));
133 * Only show start/end times if we're actually looking at the VEVENT
134 * component. Otherwise it shows bogus dates for e.g. timezones
136 if (icalcomponent_isa(WC->disp_cal[i].cal) == ICAL_VEVENT_COMPONENT) {
138 q = icalcomponent_get_first_property(WC->disp_cal[i].cal,
139 ICAL_DTSTART_PROPERTY);
141 t = icalproperty_get_dtstart(q);
146 memset(&d_tm, 0, sizeof d_tm);
147 d_tm.tm_year = t.year - 1900;
148 d_tm.tm_mon = t.month - 1;
149 d_tm.tm_mday = t.day;
150 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
151 wprintf("<i>%s</i> %s<br>",
155 tt = icaltime_as_timet(t);
156 fmt_date(buf, tt, 1);
157 wprintf("<i>%s</i> %s<br>",
158 _("Starting date/time:"), buf);
160 /* Embed the 'show end date/time' loop inside here so it
161 * only executes if this is NOT an all day event.
163 q = icalcomponent_get_first_property(WC->disp_cal[i].cal,
164 ICAL_DTEND_PROPERTY);
166 t = icalproperty_get_dtend(q);
167 tt = icaltime_as_timet(t);
168 fmt_date(buf, tt, 1);
169 wprintf("<i>%s</i> %s<br>",
170 _("Ending date/time:"), buf);
178 q = icalcomponent_get_first_property(
180 ICAL_DESCRIPTION_PROPERTY);
182 wprintf("<i>%s</i> ", _("Notes:"));
183 escputs((char *)icalproperty_get_comment(q));
189 icalproperty_get_comment(p));
190 wprintf("</a></font><br />\n");
193 wprintf("</td></tr></table>");
207 * \brief Display one day of a whole month view of a calendar
208 * \param thetime the month we want to see
210 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
220 struct icaltimetype t;
221 int month, day, year;
222 int all_day_event = 0;
226 time_format = get_time_format_cached ();
228 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
229 else timeformat="%I:%M %p";
231 localtime_r(&thetime, &today_tm);
232 month = today_tm.tm_mon + 1;
233 day = today_tm.tm_mday;
234 year = today_tm.tm_year + 1900;
236 for (i=0; i<(WC->num_cal); ++i) {
237 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
238 ICAL_DTSTART_PROPERTY);
240 t = icalproperty_get_dtstart(p);
241 event_tt = icaltime_as_timet(t);
243 if (t.is_date) all_day_event = 1;
244 else all_day_event = 0;
247 gmtime_r(&event_tts, &event_tms);
250 localtime_r(&event_tts, &event_tms);
252 /** \todo epoch &! daymask */
253 if ((event_tms.tm_year == today_tm.tm_year)
254 && (event_tms.tm_mon == today_tm.tm_mon)
255 && (event_tms.tm_mday == today_tm.tm_mday)) {
261 p = icalcomponent_get_first_property(
263 ICAL_SUMMARY_PROPERTY);
264 e = icalcomponent_get_first_property(
266 ICAL_DTEND_PROPERTY);
267 if ((p != NULL) && (e != NULL)) {
270 t = icalproperty_get_dtend(e);
271 event_tte = icaltime_as_timet(t);
272 localtime_r(&event_tte, &event_tme);
273 difftime=(event_tte-event_tts)/60;
274 hours=(int)(difftime / 60);
275 minutes=difftime % 60;
276 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
278 "<a href=\"display_edit_event?msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\">",
282 WC->disp_cal[i].cal_msgnum,
290 icalproperty_get_comment(p));
291 /** \todo: allso ammitime format */
292 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
293 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
295 wprintf("</a></font></td>"
296 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
313 * \brief view one month. pretty view
314 * \param year the year
315 * \param month the month
316 * \param day the actual day we want to see
318 void calendar_month_view(int year, int month, int day) {
319 struct tm starting_tm;
323 time_t previous_month;
325 time_t colheader_time;
326 struct tm colheader_tm;
327 char colheader_label[32];
329 /** Determine what day to start.
330 * First, back up to the 1st of the month...
332 memset(&starting_tm, 0, sizeof(struct tm));
333 starting_tm.tm_year = year - 1900;
334 starting_tm.tm_mon = month - 1;
335 starting_tm.tm_mday = day;
336 thetime = mktime(&starting_tm);
338 memcpy(&tm, &starting_tm, sizeof(struct tm));
339 while (tm.tm_mday != 1) {
340 thetime = thetime - (time_t)86400; /* go back 24 hours */
341 localtime_r(&thetime, &tm);
344 /** Determine previous and next months ... for links */
345 previous_month = thetime - (time_t)864000L; /* back 10 days */
346 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
348 /** Now back up until we're on a Sunday */
349 localtime_r(&thetime, &tm);
350 while (tm.tm_wday != 0) {
351 thetime = thetime - (time_t)86400; /* go back 24 hours */
352 localtime_r(&thetime, &tm);
355 /** Outer table (to get the background color) */
356 wprintf("<div class=\"fix_scrollbar_bug\">"
357 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
358 "bgcolor=#204B78><TR><TD>\n");
360 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
362 wprintf("<td align=center>");
364 localtime_r(&previous_month, &tm);
365 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
366 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
367 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
369 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
370 wprintf(" "
371 "<font size=+1 color=\"#FFFFFF\">"
374 " ", colheader_label, year);
376 localtime_r(&next_month, &tm);
377 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
378 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
379 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
381 wprintf("</td></tr></table>\n");
383 /** Inner table (the real one) */
384 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
385 "bgcolor=#204B78 id=\"inner_month\"><tr>");
386 colheader_time = thetime;
387 for (i=0; i<7; ++i) {
388 colheader_time = thetime + (i * 86400) ;
389 localtime_r(&colheader_time, &colheader_tm);
390 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
391 wprintf("<td align=center width=14%%>"
392 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
397 /** Now do 35 days */
398 for (i = 0; i < 35; ++i) {
399 localtime_r(&thetime, &tm);
401 /** Before displaying Sunday, start a new row */
406 wprintf("<td bgcolor=\"#%s\" width=14%% height=60 align=left valign=top><b>",
407 ((tm.tm_mon != month-1) ? "DDDDDD" :
408 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
411 if ((i==0) || (tm.tm_mday == 1)) {
412 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
413 wprintf("%s ", colheader_label);
415 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
422 /** put the data here, stupid */
423 calendar_month_view_display_events(thetime);
427 /** After displaying Saturday, end the row */
432 thetime += (time_t)86400; /** ahead 24 hours */
435 wprintf("</table>" /** end of inner table */
436 "</td></tr></table>" /** end of outer table */
440 * Initialize the bubble tooltips.
442 * Yes, this is as stupid as it looks. Instead of just making the call
443 * to btt_enableTooltips() straight away, we have to create a timer event
444 * and let it initialize as an event after 1 millisecond. This is to
445 * work around a bug in Internet Explorer that causes it to crash if we
446 * manipulate the innerHTML of various DOM nodes while the page is still
447 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
448 * for more information.
450 wprintf("<script type=\"text/javascript\">"
451 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
457 * \brief view one month. brief view
458 * \param year the year
459 * \param month the month
460 * \param day the actual day we want to see
462 void calendar_brief_month_view(int year, int month, int day) {
463 struct tm starting_tm;
467 time_t previous_month;
469 char month_label[32];
471 /** Determine what day to start.
472 * First, back up to the 1st of the month...
474 memset(&starting_tm, 0, sizeof(struct tm));
475 starting_tm.tm_year = year - 1900;
476 starting_tm.tm_mon = month - 1;
477 starting_tm.tm_mday = day;
478 thetime = mktime(&starting_tm);
480 memcpy(&tm, &starting_tm, sizeof(struct tm));
481 while (tm.tm_mday != 1) {
482 thetime = thetime - (time_t)86400; /* go back 24 hours */
483 localtime_r(&thetime, &tm);
486 /** Determine previous and next months ... for links */
487 previous_month = thetime - (time_t)864000L; /* back 10 days */
488 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
490 /** Now back up until we're on a Sunday */
491 localtime_r(&thetime, &tm);
492 while (tm.tm_wday != 0) {
493 thetime = thetime - (time_t)86400; /* go back 24 hours */
494 localtime_r(&thetime, &tm);
497 /** Outer table (to get the background color) */
498 wprintf("<div class=\"fix_scrollbar_bug\">"
499 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
500 "bgcolor=#204B78><TR><TD>\n");
502 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
504 wprintf("<td align=center>");
506 localtime_r(&previous_month, &tm);
507 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
508 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
509 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
511 wc_strftime(month_label, sizeof month_label, "%B", &tm);
512 wprintf(" "
513 "<font size=+1 color=\"#FFFFFF\">"
516 " ", month_label, year);
518 localtime_r(&next_month, &tm);
519 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
520 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
521 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
523 wprintf("</td></tr></table>\n");
525 /** Inner table (the real one) */
526 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
527 "bgcolor=#EEEECC><TR>");
529 wprintf("<tr><td colspan=\"100%\">\n");
531 /** Now do 35 days */
532 for (i = 0; i < 35; ++i) {
533 char weeknumber[255];
534 char weekday_name[32];
536 localtime_r(&thetime, &tm);
539 /** Before displaying Sunday, start a new CELL */
541 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
542 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
543 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
553 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
554 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
558 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
559 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
560 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
562 weekday_name,tm.tm_mday,
565 /** put the data of one day here, stupid */
566 calendar_month_view_brief_events(thetime, daycolor);
569 /** After displaying Saturday, end the row */
571 wprintf("</td></tr></table>\n");
574 thetime += (time_t)86400; /** ahead 24 hours */
577 wprintf("</table>" /** end of inner table */
578 "</td></tr></table>" /** end of outer table */
583 * \brief view one week
584 * this should view just one week, but it's not here yet.
585 * \todo ny implemented
586 * \param year the year
587 * \param month the month
588 * \param day the day which we want to see the week around
590 void calendar_week_view(int year, int month, int day) {
591 wprintf("<center><i>week view FIXME</i></center><br />\n");
596 * \brief display one day
597 * Display events for a particular hour of a particular day.
598 * (Specify hour < 0 to show "all day" events)
599 * \param year the year
600 * \param month the month
602 * \param hour the hour we want to start displaying?????
604 void calendar_day_view_display_events(int year, int month,
608 icalproperty *pe = NULL;
609 struct icaltimetype t;
610 struct icaltimetype te;
615 int all_day_event = 0;
617 if (WC->num_cal == 0) {
618 // \todo FIXME wprintf("<br /><br /><br />\n");
622 for (i=0; i<(WC->num_cal); ++i) {
623 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
624 ICAL_DTSTART_PROPERTY);
625 pe = icalcomponent_get_first_property(WC->disp_cal[i].cal,
626 ICAL_DTEND_PROPERTY);
628 t = icalproperty_get_dtstart(p);
629 event_tt = icaltime_as_timet(t);
638 gmtime_r(&event_tt, &event_tm);
639 gmtime_r(&event_tt, &event_te);
642 localtime_r(&event_tt, &event_tm);
645 te = icalproperty_get_dtend(pe);
646 event_tte = icaltime_as_timet(te);
647 localtime_r(&event_tte, &event_te);
650 localtime_r(&event_tt, &event_te);
653 if (((event_tm.tm_year <= (year-1900))
654 && (event_tm.tm_mon <= (month-1))
655 && (event_tm.tm_mday <= day)
656 && (event_te.tm_year >= (year-1900))
657 && (event_te.tm_mon >= (month-1))
658 && (event_te.tm_mday >= day))
660 // are we in the start hour?
661 ((event_tm.tm_mday == day)
662 && (event_tm.tm_hour == hour)
664 // are we an all day event?
665 || ((hour<0)&&(t.is_date))
666 // does it span multible days and we're not at the start day?
668 && (event_tm.tm_mday < day)
669 && (event_te.tm_mday >= day))
672 p = icalcomponent_get_first_property(
674 ICAL_SUMMARY_PROPERTY);
678 wprintf("<table border=1 cellpadding=2><TR>"
679 "<td bgcolor=\"#CCCCCC\">"
683 wprintf("<font size=-1>"
684 "<a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d\">",
685 WC->disp_cal[i].cal_msgnum,
689 icalproperty_get_comment(p));
690 wprintf("</a></font><br />\n");
693 wprintf("</td></tr></table>");
706 * \brief view one day
707 * \param year the year
708 * \param month the month
709 * \param day the day we want to display
711 void calendar_day_view(int year, int month, int day) {
713 struct icaltimetype today, yesterday, tomorrow;
716 char daystart_str[16], dayend_str[16];
721 time_format = get_time_format_cached ();
722 get_preference("daystart", daystart_str, sizeof daystart_str);
723 if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
724 get_preference("dayend", dayend_str, sizeof dayend_str);
725 if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str);
728 /** Figure out the dates for "yesterday" and "tomorrow" links */
730 memset(&today, 0, sizeof(struct icaltimetype));
736 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
738 yesterday = icaltime_normalize(yesterday);
740 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
742 tomorrow = icaltime_normalize(tomorrow);
745 /** Outer table (to get the background color) */
746 wprintf("<div class=\"fix_scrollbar_bug\">"
747 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
748 "bgcolor=#204B78><tr><td>\n");
750 /** Inner table (the real one) */
751 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
752 "bgcolor=#204B78><tr>\n");
754 /** Innermost table (contains hours etc.) */
755 wprintf("<td width=80%%>"
756 "<table width=100%% border=0 cellpadding=1 cellspacing=1 "
757 "bgcolor=#204B78>\n");
759 /** Display events before 8:00 (hour=-1 is all-day events) */
761 "<td bgcolor=\"#CCCCDD\" valign=middle width=10%%></td>"
762 "<td bgcolor=\"#FFFFFF\" valign=top>");
763 for (hour = (-1); hour <= (daystart-1); ++hour) {
764 calendar_day_view_display_events(year, month, day, hour);
766 wprintf("</td></tr>\n");
768 /** Now the middle of the day... */
769 for (hour = daystart; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
770 wprintf("<tr height=30><td bgcolor=\"#CCCCDD\" align=middle "
771 "valign=middle width=10%%>");
772 wprintf("<a href=\"display_edit_event?msgnum=0"
773 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
774 year, month, day, hour
777 if (time_format == WC_TIMEFORMAT_24) {
778 wprintf("%2d:00</a> ", hour);
781 wprintf("%d:00%s</a> ",
782 (hour <= 12 ? hour : hour-12),
783 (hour < 12 ? "am" : "pm")
787 wprintf("</td><td bgcolor=\"#FFFFFF\" valign=top>");
789 /* put the data here, stupid */
790 calendar_day_view_display_events(year, month, day, hour);
792 wprintf("</td></tr>\n");
795 /** Display events after 5:00... */
797 "<td bgcolor=\"#CCCCDD\" valign=middle width=10%%></td>"
798 "<td bgcolor=\"#FFFFFF\" valign=top>");
799 for (hour = (dayend+1); hour <= 23; ++hour) {
800 calendar_day_view_display_events(year, month, day, hour);
802 wprintf("</td></tr>\n");
805 wprintf("</table>" /* end of innermost table */
809 wprintf("<td width=20%% valign=top>"); /* begin stuff-on-the-right */
812 /** Begin todays-date-with-left-and-right-arrows */
813 wprintf("<table border=0 width=100%% "
814 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
818 wprintf("<td align=center>");
819 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
820 yesterday.year, yesterday.month, yesterday.day);
821 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
825 memset(&d_tm, 0, sizeof d_tm);
826 d_tm.tm_year = year - 1900;
827 d_tm.tm_mon = month - 1;
829 wc_strftime(d_str, sizeof d_str,
831 "<font size=+2>%B</font><br />"
832 "<font size=+3>%d</font><br />"
833 "<font size=+2>%Y</font><br />"
837 wprintf("%s", d_str);
840 wprintf("<td align=center>");
841 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
842 tomorrow.year, tomorrow.month, tomorrow.day);
843 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
847 wprintf("</tr></table>\n");
848 /** End todays-date-with-left-and-right-arrows */
850 /** \todo In the future we might want to put a month-o-matic here */
852 wprintf("</font></center>\n");
854 wprintf("</td>"); /** end stuff-on-the-right */
858 wprintf("</tr></table>" /** end of inner table */
859 "</td></tr></table></div>" /** end of outer table */
867 * \brief Display today's events.
869 void calendar_summary_view(void) {
872 struct icaltimetype t;
877 int all_day_event = 0;
878 char timestring[SIZ];
880 if (WC->num_cal == 0) {
885 localtime_r(&now, &today_tm);
887 for (i=0; i<(WC->num_cal); ++i) {
888 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
889 ICAL_DTSTART_PROPERTY);
891 t = icalproperty_get_dtstart(p);
892 event_tt = icaltime_as_timet(t);
899 fmt_time(timestring, event_tt);
902 gmtime_r(&event_tt, &event_tm);
905 localtime_r(&event_tt, &event_tm);
908 if ( (event_tm.tm_year == today_tm.tm_year)
909 && (event_tm.tm_mon == today_tm.tm_mon)
910 && (event_tm.tm_mday == today_tm.tm_mday)
914 p = icalcomponent_get_first_property(
916 ICAL_SUMMARY_PROPERTY);
919 icalproperty_get_comment(p));
920 wprintf(" (%s)<br />\n", timestring);
925 free_calendar_buffer();
930 * \brief clean up ical memory
931 * \todo this could get troubel with future ical versions
933 void free_calendar_buffer(void) {
935 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
936 icalcomponent_free(WC->disp_cal[i].cal);
946 * \brief do the whole calendar page
947 * view any part of the calender. decide which way, etc.
949 void do_calendar_view(void) {
952 int year, month, day;
955 /** In case no date was specified, go with today */
957 localtime_r(&now, &tm);
958 year = tm.tm_year + 1900;
959 month = tm.tm_mon + 1;
962 /** Now see if a date was specified */
963 if (!IsEmptyStr(bstr("year"))) year = atoi(bstr("year"));
964 if (!IsEmptyStr(bstr("month"))) month = atoi(bstr("month"));
965 if (!IsEmptyStr(bstr("day"))) day = atoi(bstr("day"));
967 /** How would you like that cooked? */
968 if (!IsEmptyStr(bstr("calview"))) {
969 strcpy(calview, bstr("calview"));
972 strcpy(calview, "month");
975 /** Display the selected view */
976 if (!strcasecmp(calview, "day")) {
977 calendar_day_view(year, month, day);
979 else if (!strcasecmp(calview, "week")) {
980 calendar_week_view(year, month, day);
983 if (WC->wc_view == VIEW_CALBRIEF) {
984 calendar_brief_month_view(year, month, day);
987 calendar_month_view(year, month, day);
991 /** Free the calendar stuff */
992 free_calendar_buffer();
998 * \brief get task due date
999 * Helper function for do_tasks_view().
1000 * \param vtodo a task to get the due date
1001 * \return the date/time due.
1003 time_t get_task_due_date(icalcomponent *vtodo) {
1006 if (vtodo == NULL) {
1011 * If we're looking at a fully encapsulated VCALENDAR
1012 * rather than a VTODO component, recurse into the data
1013 * structure until we get a VTODO.
1015 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1016 return get_task_due_date(
1017 icalcomponent_get_first_component(
1018 vtodo, ICAL_VTODO_COMPONENT
1023 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1025 return(icaltime_as_timet(icalproperty_get_due(p)));
1034 * \brief Compare the due dates of two tasks (this is for sorting)
1035 * \param task1 first task to compare
1036 * \param task2 second task to compare
1038 int task_due_cmp(const void *task1, const void *task2) {
1042 t1 = get_task_due_date(((struct disp_cal *)task1)->cal);
1043 t2 = get_task_due_date(((struct disp_cal *)task2)->cal);
1045 if (t1 < t2) return(-1);
1046 if (t1 > t2) return(1);
1054 * \brief do the whole task view stuff
1056 void do_tasks_view(void) {
1063 wprintf("<div class=\"fix_scrollbar_bug\">"
1064 "<table class=\"calendar_view_background\">\n<tr>\n"
1066 wprintf(_("Name of task"));
1067 wprintf("</th><th>");
1068 wprintf(_("Date due"));
1069 wprintf("</th></tr>\n"
1072 /** Sort them if necessary */
1073 if (WC->num_cal > 1) {
1076 sizeof(struct disp_cal),
1081 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1084 wprintf("<tr bgcolor=\"#%s\"><td>",
1085 (bg ? "DDDDDD" : "FFFFFF")
1088 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1089 ICAL_SUMMARY_PROPERTY);
1090 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1091 WC->disp_cal[i].cal_msgnum );
1092 urlescputs(WC->wc_roomname);
1094 wprintf("<img align=middle "
1095 "src=\"static/taskmanag_16x.gif\" border=0> ");
1097 escputs((char *)icalproperty_get_comment(p));
1102 due = get_task_due_date(WC->disp_cal[i].cal);
1103 fmt_date(buf, due, 0);
1104 wprintf("<td><font");
1105 if (due < time(NULL)) {
1106 wprintf(" color=\"#FF0000\"");
1108 wprintf(">%s</font></td></tr>\n", buf);
1111 wprintf("</table></div>\n");
1113 /** Free the list */
1114 free_calendar_buffer();
1118 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */