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) {
39 time_t event_tt_stripped;
43 icalproperty *p = NULL;
44 icalproperty *pe = NULL;
45 icalproperty *q = NULL;
46 struct icaltimetype t;
48 int all_day_event = 0;
49 int multi_day_event = 0;
50 int fill_day_event = 0;
55 if (WC->num_cal == 0) {
56 wprintf("<br /><br /><br />\n");
60 localtime_r(&thetime, &today_tm);
61 month = today_tm.tm_mon + 1;
62 day = today_tm.tm_mday;
63 year = today_tm.tm_year + 1900;
65 for (i=0; i<(WC->num_cal); ++i) {
68 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
69 ICAL_DTSTART_PROPERTY);
70 pe = icalcomponent_get_first_property(WC->disp_cal[i].cal,
73 t = icalproperty_get_dtstart(p);
74 event_tt = icaltime_as_timet(t);
75 if (t.is_date) all_day_event = 1;
76 else all_day_event = 0;
79 gmtime_r(&event_tt, &event_tm);
84 event_tt_stripped = mktime (&event_tm);
85 show_event = thetime == event_tt_stripped;
88 localtime_r(&event_tt, &event_tm);
89 // we're not interested in the hours.
90 // we just want the date for easy comparison.
93 event_tt_stripped = mktime (&event_tm);
94 if (pe != NULL) // do we have a span?
97 time_t event_end_stripped;
99 t = icalproperty_get_dtend(pe);
100 event_tte = icaltime_as_timet(t);
101 gmtime_r(&event_tte, &event_ttm);
102 event_ttm.tm_sec = 0;
103 event_ttm.tm_min = 0;
104 event_ttm.tm_hour = 0;
105 event_end_stripped = mktime(&event_ttm);
107 // do we span ore than one day?
108 multi_day_event = event_tt_stripped != event_end_stripped;
110 // are we in the range of the event?
111 show_event = ((event_tt_stripped <= thetime) &&
112 (event_end_stripped >= thetime));
114 // are we not start or end day?
115 fill_day_event = ((event_tt_stripped < thetime) &&
116 (event_end_stripped > thetime));
120 show_event = event_tt_stripped == thetime;
125 p = icalcomponent_get_first_property(
127 ICAL_SUMMARY_PROPERTY);
131 wprintf("<table border=0 cellpadding=2><TR>"
132 "<td bgcolor=\"#CCCCDD\">"
136 wprintf("<font size=-1>"
137 "<a href=\"display_edit_event?"
138 "msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\""
140 WC->disp_cal[i].cal_msgnum,
147 wprintf("<i>%s</i> ", _("Summary:"));
148 escputs((char *)icalproperty_get_comment(p));
151 q = icalcomponent_get_first_property(
153 ICAL_LOCATION_PROPERTY);
155 wprintf("<i>%s</i> ", _("Location:"));
156 escputs((char *)icalproperty_get_comment(q));
161 * Only show start/end times if we're actually looking at the VEVENT
162 * component. Otherwise it shows bogus dates for e.g. timezones
164 if (icalcomponent_isa(WC->disp_cal[i].cal) == ICAL_VEVENT_COMPONENT) {
166 q = icalcomponent_get_first_property(WC->disp_cal[i].cal,
167 ICAL_DTSTART_PROPERTY);
169 t = icalproperty_get_dtstart(q);
174 memset(&d_tm, 0, sizeof d_tm);
175 d_tm.tm_year = t.year - 1900;
176 d_tm.tm_mon = t.month - 1;
177 d_tm.tm_mday = t.day;
178 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
179 wprintf("<i>%s</i> %s<br>",
183 tt = icaltime_as_timet(t);
184 fmt_date(buf, tt, 1);
185 wprintf("<i>%s</i> %s<br>",
186 _("Starting date/time:"), buf);
188 /* Embed the 'show end date/time' loop inside here so it
189 * only executes if this is NOT an all day event.
191 q = icalcomponent_get_first_property(WC->disp_cal[i].cal,
192 ICAL_DTEND_PROPERTY);
194 t = icalproperty_get_dtend(q);
195 tt = icaltime_as_timet(t);
196 fmt_date(buf, tt, 1);
197 wprintf("<i>%s</i> %s<br>",
198 _("Ending date/time:"), buf);
206 q = icalcomponent_get_first_property(
208 ICAL_DESCRIPTION_PROPERTY);
210 wprintf("<i>%s</i> ", _("Notes:"));
211 escputs((char *)icalproperty_get_comment(q));
217 icalproperty_get_comment(p));
218 wprintf("</a></font><br />\n");
221 wprintf("</td></tr></table>");
235 * \brief Display one day of a whole month view of a calendar
236 * \param thetime the month we want to see
238 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
248 struct icaltimetype t;
249 int month, day, year;
250 int all_day_event = 0;
254 time_format = get_time_format_cached ();
256 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
257 else timeformat="%I:%M %p";
259 localtime_r(&thetime, &today_tm);
260 month = today_tm.tm_mon + 1;
261 day = today_tm.tm_mday;
262 year = today_tm.tm_year + 1900;
264 for (i=0; i<(WC->num_cal); ++i) {
265 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
266 ICAL_DTSTART_PROPERTY);
268 t = icalproperty_get_dtstart(p);
269 event_tt = icaltime_as_timet(t);
271 if (t.is_date) all_day_event = 1;
272 else all_day_event = 0;
275 gmtime_r(&event_tts, &event_tms);
278 localtime_r(&event_tts, &event_tms);
280 /** \todo epoch &! daymask */
281 if ((event_tms.tm_year == today_tm.tm_year)
282 && (event_tms.tm_mon == today_tm.tm_mon)
283 && (event_tms.tm_mday == today_tm.tm_mday)) {
289 p = icalcomponent_get_first_property(
291 ICAL_SUMMARY_PROPERTY);
292 e = icalcomponent_get_first_property(
294 ICAL_DTEND_PROPERTY);
295 if ((p != NULL) && (e != NULL)) {
298 t = icalproperty_get_dtend(e);
299 event_tte = icaltime_as_timet(t);
300 localtime_r(&event_tte, &event_tme);
301 difftime=(event_tte-event_tts)/60;
302 hours=(int)(difftime / 60);
303 minutes=difftime % 60;
304 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
306 "<a href=\"display_edit_event?msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\">",
310 WC->disp_cal[i].cal_msgnum,
318 icalproperty_get_comment(p));
319 /** \todo: allso ammitime format */
320 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
321 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
323 wprintf("</a></font></td>"
324 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
341 * \brief view one month. pretty view
342 * \param year the year
343 * \param month the month
344 * \param day the actual day we want to see
346 void calendar_month_view(int year, int month, int day) {
347 struct tm starting_tm;
351 time_t previous_month;
353 time_t colheader_time;
354 struct tm colheader_tm;
355 char colheader_label[32];
358 /** Determine what day to start.
359 * First, back up to the 1st of the month...
361 memset(&starting_tm, 0, sizeof(struct tm));
362 starting_tm.tm_year = year - 1900;
363 starting_tm.tm_mon = month - 1;
364 starting_tm.tm_mday = day;
365 thetime = mktime(&starting_tm);
367 memcpy(&tm, &starting_tm, sizeof(struct tm));
368 while (tm.tm_mday != 1) {
369 thetime = thetime - (time_t)86400; /* go back 24 hours */
370 localtime_r(&thetime, &tm);
373 /** Determine previous and next months ... for links */
374 previous_month = thetime - (time_t)864000L; /* back 10 days */
375 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
377 /** Now back up until we're on a Sunday */
378 localtime_r(&thetime, &tm);
379 while (tm.tm_wday != 0) {
380 thetime = thetime - (time_t)86400; /* go back 24 hours */
381 localtime_r(&thetime, &tm);
384 /** Outer table (to get the background color) */
385 wprintf("<div class=\"fix_scrollbar_bug\">"
386 "<table class=\"calendar\"> \n <tr><td>");
388 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
390 wprintf("<td align=center>");
392 localtime_r(&previous_month, &tm);
393 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
394 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
395 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
397 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
398 wprintf(" "
399 "<font size=+1 color=\"#FFFFFF\">"
402 " ", colheader_label, year);
404 localtime_r(&next_month, &tm);
405 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
406 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
407 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
409 wprintf("</td></tr></table>\n");
411 /** Inner table (the real one) */
412 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
413 "bgcolor=#204B78 id=\"inner_month\"><tr>");
414 colheader_time = thetime;
415 for (i=0; i<7; ++i) {
416 colheader_time = thetime + (i * 86400) ;
417 localtime_r(&colheader_time, &colheader_tm);
418 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
419 wprintf("<td align=center width=14%%>"
420 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
426 /** Now do 35 or 42 days */
427 for (i = 0; i < 42; ++i) {
428 localtime_r(&thetime, &tm);
430 if ((i < 35) || (chg_month == 0)) {
432 if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) {
439 /** Before displaying Sunday, start a new row */
444 wprintf("<td class=\"cal%s\"><div class=\"day\">",
445 ((tm.tm_mon != month-1) ? "out" :
446 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
449 if ((i==0) || (tm.tm_mday == 1)) {
450 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
451 wprintf("%s ", colheader_label);
453 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
460 /** put the data here, stupid */
461 calendar_month_view_display_events(thetime);
465 /** After displaying Saturday, end the row */
472 thetime += (time_t)86400; /** ahead 24 hours */
475 wprintf("</table>" /** end of inner table */
476 "</td></tr></table>" /** end of outer table */
480 * Initialize the bubble tooltips.
482 * Yes, this is as stupid as it looks. Instead of just making the call
483 * to btt_enableTooltips() straight away, we have to create a timer event
484 * and let it initialize as an event after 1 millisecond. This is to
485 * work around a bug in Internet Explorer that causes it to crash if we
486 * manipulate the innerHTML of various DOM nodes while the page is still
487 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
488 * for more information.
490 wprintf("<script type=\"text/javascript\">"
491 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
497 * \brief view one month. brief view
498 * \param year the year
499 * \param month the month
500 * \param day the actual day we want to see
502 void calendar_brief_month_view(int year, int month, int day) {
503 struct tm starting_tm;
507 time_t previous_month;
509 char month_label[32];
511 /** Determine what day to start.
512 * First, back up to the 1st of the month...
514 memset(&starting_tm, 0, sizeof(struct tm));
515 starting_tm.tm_year = year - 1900;
516 starting_tm.tm_mon = month - 1;
517 starting_tm.tm_mday = day;
518 thetime = mktime(&starting_tm);
520 memcpy(&tm, &starting_tm, sizeof(struct tm));
521 while (tm.tm_mday != 1) {
522 thetime = thetime - (time_t)86400; /* go back 24 hours */
523 localtime_r(&thetime, &tm);
526 /** Determine previous and next months ... for links */
527 previous_month = thetime - (time_t)864000L; /* back 10 days */
528 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
530 /** Now back up until we're on a Sunday */
531 localtime_r(&thetime, &tm);
532 while (tm.tm_wday != 0) {
533 thetime = thetime - (time_t)86400; /* go back 24 hours */
534 localtime_r(&thetime, &tm);
537 /** Outer table (to get the background color) */
538 wprintf("<div class=\"fix_scrollbar_bug\">"
539 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
540 "bgcolor=#204B78><TR><TD>\n");
542 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
544 wprintf("<td align=center>");
546 localtime_r(&previous_month, &tm);
547 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
548 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
549 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
551 wc_strftime(month_label, sizeof month_label, "%B", &tm);
552 wprintf(" "
553 "<font size=+1 color=\"#FFFFFF\">"
556 " ", month_label, year);
558 localtime_r(&next_month, &tm);
559 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
560 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
561 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
563 wprintf("</td></tr></table>\n");
565 /** Inner table (the real one) */
566 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
567 "bgcolor=#EEEECC><TR>");
569 wprintf("<tr><td colspan=\"100%\">\n");
571 /** Now do 35 days */
572 for (i = 0; i < 35; ++i) {
573 char weeknumber[255];
574 char weekday_name[32];
576 localtime_r(&thetime, &tm);
579 /** Before displaying Sunday, start a new CELL */
581 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
582 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
583 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
593 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
594 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
598 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
599 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
600 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
602 weekday_name,tm.tm_mday,
605 /** put the data of one day here, stupid */
606 calendar_month_view_brief_events(thetime, daycolor);
609 /** After displaying Saturday, end the row */
611 wprintf("</td></tr></table>\n");
614 thetime += (time_t)86400; /** ahead 24 hours */
617 wprintf("</table>" /** end of inner table */
618 "</td></tr></table>" /** end of outer table */
623 * \brief view one week
624 * this should view just one week, but it's not here yet.
625 * \todo ny implemented
626 * \param year the year
627 * \param month the month
628 * \param day the day which we want to see the week around
630 void calendar_week_view(int year, int month, int day) {
631 wprintf("<center><i>week view FIXME</i></center><br />\n");
636 * \brief display one day
637 * Display events for a particular hour of a particular day.
638 * (Specify hour < 0 to show "all day" events)
639 * \param year the year
640 * \param month the month
642 * \param hour the hour we want to start displaying?????
644 void calendar_day_view_display_events(int year, int month,
648 icalproperty *pe = NULL;
649 struct icaltimetype t;
650 struct icaltimetype te;
655 int all_day_event = 0;
657 if (WC->num_cal == 0) {
658 // \todo FIXME wprintf("<br /><br /><br />\n");
662 for (i=0; i<(WC->num_cal); ++i) {
663 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
664 ICAL_DTSTART_PROPERTY);
665 pe = icalcomponent_get_first_property(WC->disp_cal[i].cal,
666 ICAL_DTEND_PROPERTY);
668 t = icalproperty_get_dtstart(p);
669 event_tt = icaltime_as_timet(t);
678 gmtime_r(&event_tt, &event_tm);
679 gmtime_r(&event_tt, &event_te);
682 localtime_r(&event_tt, &event_tm);
685 te = icalproperty_get_dtend(pe);
686 event_tte = icaltime_as_timet(te);
687 localtime_r(&event_tte, &event_te);
690 localtime_r(&event_tt, &event_te);
693 if (((event_tm.tm_year <= (year-1900))
694 && (event_tm.tm_mon <= (month-1))
695 && (event_tm.tm_mday <= day)
696 && (event_te.tm_year >= (year-1900))
697 && (event_te.tm_mon >= (month-1))
698 && (event_te.tm_mday >= day))
700 // are we in the start hour?
701 ((event_tm.tm_mday == day)
702 && (event_tm.tm_hour == hour)
704 // are we an all day event?
705 || ((hour<0)&&(t.is_date))
706 // does it span multible days and we're not at the start day?
708 && (event_tm.tm_mday < day)
709 && (event_te.tm_mday >= day))
712 p = icalcomponent_get_first_property(
714 ICAL_SUMMARY_PROPERTY);
718 wprintf("<table border=1 cellpadding=2><TR>"
719 "<td bgcolor=\"#CCCCCC\">"
723 wprintf("<font size=-1>"
724 "<a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d\">",
725 WC->disp_cal[i].cal_msgnum,
729 icalproperty_get_comment(p));
730 wprintf("</a></font><br />\n");
733 wprintf("</td></tr></table>");
746 * \brief view one day
747 * \param year the year
748 * \param month the month
749 * \param day the day we want to display
751 void calendar_day_view(int year, int month, int day) {
753 struct icaltimetype today, yesterday, tomorrow;
756 char daystart_str[16], dayend_str[16];
761 time_format = get_time_format_cached ();
762 get_preference("daystart", daystart_str, sizeof daystart_str);
763 if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
764 get_preference("dayend", dayend_str, sizeof dayend_str);
765 if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str);
768 /** Figure out the dates for "yesterday" and "tomorrow" links */
770 memset(&today, 0, sizeof(struct icaltimetype));
776 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
778 yesterday = icaltime_normalize(yesterday);
780 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
782 tomorrow = icaltime_normalize(tomorrow);
785 /** Outer table (to get the background color) */
786 wprintf("<div class=\"fix_scrollbar_bug\">"
787 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
788 "bgcolor=#204B78><tr><td>\n");
790 /** Inner table (the real one) */
791 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
792 "bgcolor=#204B78><tr>\n");
794 /** Innermost table (contains hours etc.) */
795 wprintf("<td width=80%%>"
796 "<table width=100%% border=0 cellpadding=1 cellspacing=1 "
797 "bgcolor=#204B78>\n");
799 /** Display events before 8:00 (hour=-1 is all-day events) */
801 "<td bgcolor=\"#CCCCDD\" valign=middle width=10%%></td>"
802 "<td bgcolor=\"#FFFFFF\" valign=top>");
803 for (hour = (-1); hour <= (daystart-1); ++hour) {
804 calendar_day_view_display_events(year, month, day, hour);
806 wprintf("</td></tr>\n");
808 /** Now the middle of the day... */
809 for (hour = daystart; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
810 wprintf("<tr height=30><td bgcolor=\"#CCCCDD\" align=middle "
811 "valign=middle width=10%%>");
812 wprintf("<a href=\"display_edit_event?msgnum=0"
813 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
814 year, month, day, hour
817 if (time_format == WC_TIMEFORMAT_24) {
818 wprintf("%2d:00</a> ", hour);
821 wprintf("%d:00%s</a> ",
822 (hour <= 12 ? hour : hour-12),
823 (hour < 12 ? "am" : "pm")
827 wprintf("</td><td bgcolor=\"#FFFFFF\" valign=top>");
829 /* put the data here, stupid */
830 calendar_day_view_display_events(year, month, day, hour);
832 wprintf("</td></tr>\n");
835 /** Display events after 5:00... */
837 "<td bgcolor=\"#CCCCDD\" valign=middle width=10%%></td>"
838 "<td bgcolor=\"#FFFFFF\" valign=top>");
839 for (hour = (dayend+1); hour <= 23; ++hour) {
840 calendar_day_view_display_events(year, month, day, hour);
842 wprintf("</td></tr>\n");
845 wprintf("</table>" /* end of innermost table */
849 wprintf("<td width=20%% valign=top>"); /* begin stuff-on-the-right */
852 /** Begin todays-date-with-left-and-right-arrows */
853 wprintf("<table border=0 width=100%% "
854 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
858 wprintf("<td align=center>");
859 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
860 yesterday.year, yesterday.month, yesterday.day);
861 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
865 memset(&d_tm, 0, sizeof d_tm);
866 d_tm.tm_year = year - 1900;
867 d_tm.tm_mon = month - 1;
869 wc_strftime(d_str, sizeof d_str,
871 "<font size=+2>%B</font><br />"
872 "<font size=+3>%d</font><br />"
873 "<font size=+2>%Y</font><br />"
877 wprintf("%s", d_str);
880 wprintf("<td align=center>");
881 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
882 tomorrow.year, tomorrow.month, tomorrow.day);
883 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
887 wprintf("</tr></table>\n");
888 /** End todays-date-with-left-and-right-arrows */
890 /** \todo In the future we might want to put a month-o-matic here */
892 wprintf("</font></center>\n");
894 wprintf("</td>"); /** end stuff-on-the-right */
898 wprintf("</tr></table>" /** end of inner table */
899 "</td></tr></table></div>" /** end of outer table */
907 * \brief Display today's events.
909 void calendar_summary_view(void) {
912 struct icaltimetype t;
917 int all_day_event = 0;
918 char timestring[SIZ];
920 if (WC->num_cal == 0) {
925 localtime_r(&now, &today_tm);
927 for (i=0; i<(WC->num_cal); ++i) {
928 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
929 ICAL_DTSTART_PROPERTY);
931 t = icalproperty_get_dtstart(p);
932 event_tt = icaltime_as_timet(t);
939 fmt_time(timestring, event_tt);
942 gmtime_r(&event_tt, &event_tm);
945 localtime_r(&event_tt, &event_tm);
948 if ( (event_tm.tm_year == today_tm.tm_year)
949 && (event_tm.tm_mon == today_tm.tm_mon)
950 && (event_tm.tm_mday == today_tm.tm_mday)
954 p = icalcomponent_get_first_property(
956 ICAL_SUMMARY_PROPERTY);
959 icalproperty_get_comment(p));
960 wprintf(" (%s)<br />\n", timestring);
965 free_calendar_buffer();
970 * \brief clean up ical memory
971 * \todo this could get troubel with future ical versions
973 void free_calendar_buffer(void) {
975 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
976 icalcomponent_free(WC->disp_cal[i].cal);
986 * \brief do the whole calendar page
987 * view any part of the calender. decide which way, etc.
989 void do_calendar_view(void) {
992 int year, month, day;
995 /** In case no date was specified, go with today */
997 localtime_r(&now, &tm);
998 year = tm.tm_year + 1900;
999 month = tm.tm_mon + 1;
1002 /** Now see if a date was specified */
1003 if (!IsEmptyStr(bstr("year"))) year = atoi(bstr("year"));
1004 if (!IsEmptyStr(bstr("month"))) month = atoi(bstr("month"));
1005 if (!IsEmptyStr(bstr("day"))) day = atoi(bstr("day"));
1007 /** How would you like that cooked? */
1008 if (!IsEmptyStr(bstr("calview"))) {
1009 strcpy(calview, bstr("calview"));
1012 strcpy(calview, "month");
1015 /** Display the selected view */
1016 if (!strcasecmp(calview, "day")) {
1017 calendar_day_view(year, month, day);
1019 else if (!strcasecmp(calview, "week")) {
1020 calendar_week_view(year, month, day);
1023 if (WC->wc_view == VIEW_CALBRIEF) {
1024 calendar_brief_month_view(year, month, day);
1027 calendar_month_view(year, month, day);
1031 /** Free the calendar stuff */
1032 free_calendar_buffer();
1038 * \brief get task due date
1039 * Helper function for do_tasks_view().
1040 * \param vtodo a task to get the due date
1041 * \return the date/time due.
1043 time_t get_task_due_date(icalcomponent *vtodo) {
1046 if (vtodo == NULL) {
1051 * If we're looking at a fully encapsulated VCALENDAR
1052 * rather than a VTODO component, recurse into the data
1053 * structure until we get a VTODO.
1055 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1056 return get_task_due_date(
1057 icalcomponent_get_first_component(
1058 vtodo, ICAL_VTODO_COMPONENT
1063 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1065 return(icaltime_as_timet(icalproperty_get_due(p)));
1074 * \brief Compare the due dates of two tasks (this is for sorting)
1075 * \param task1 first task to compare
1076 * \param task2 second task to compare
1078 int task_due_cmp(const void *task1, const void *task2) {
1082 t1 = get_task_due_date(((struct disp_cal *)task1)->cal);
1083 t2 = get_task_due_date(((struct disp_cal *)task2)->cal);
1085 if (t1 < t2) return(-1);
1086 if (t1 > t2) return(1);
1094 * \brief do the whole task view stuff
1096 void do_tasks_view(void) {
1103 wprintf("<div class=\"fix_scrollbar_bug\">"
1104 "<table class=\"calendar_view_background\">\n<tr>\n"
1106 wprintf(_("Name of task"));
1107 wprintf("</th><th>");
1108 wprintf(_("Date due"));
1109 wprintf("</th></tr>\n"
1112 /** Sort them if necessary */
1113 if (WC->num_cal > 1) {
1116 sizeof(struct disp_cal),
1121 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1124 wprintf("<tr bgcolor=\"#%s\"><td>",
1125 (bg ? "DDDDDD" : "FFFFFF")
1128 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1129 ICAL_SUMMARY_PROPERTY);
1130 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1131 WC->disp_cal[i].cal_msgnum );
1132 urlescputs(WC->wc_roomname);
1134 wprintf("<img align=middle "
1135 "src=\"static/taskmanag_16x.gif\" border=0> ");
1137 escputs((char *)icalproperty_get_comment(p));
1142 due = get_task_due_date(WC->disp_cal[i].cal);
1143 fmt_date(buf, due, 0);
1144 wprintf("<td><font");
1145 if (due < time(NULL)) {
1146 wprintf(" color=\"#FF0000\"");
1148 wprintf(">%s</font></td></tr>\n", buf);
1151 wprintf("</table></div>\n");
1153 /** Free the list */
1154 free_calendar_buffer();
1158 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */