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;
223 char calhourformat[16];
226 get_preference("calhourformat", calhourformat, sizeof calhourformat);
227 if (!strcasecmp(calhourformat, "24")) timeformat="%k:%M";
228 else timeformat="%I:%M %p";
230 localtime_r(&thetime, &today_tm);
231 month = today_tm.tm_mon + 1;
232 day = today_tm.tm_mday;
233 year = today_tm.tm_year + 1900;
235 for (i=0; i<(WC->num_cal); ++i) {
236 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
237 ICAL_DTSTART_PROPERTY);
239 t = icalproperty_get_dtstart(p);
240 event_tt = icaltime_as_timet(t);
242 if (t.is_date) all_day_event = 1;
243 else all_day_event = 0;
246 gmtime_r(&event_tts, &event_tms);
249 localtime_r(&event_tts, &event_tms);
251 /** \todo epoch &! daymask */
252 if ((event_tms.tm_year == today_tm.tm_year)
253 && (event_tms.tm_mon == today_tm.tm_mon)
254 && (event_tms.tm_mday == today_tm.tm_mday)) {
260 p = icalcomponent_get_first_property(
262 ICAL_SUMMARY_PROPERTY);
263 e = icalcomponent_get_first_property(
265 ICAL_DTEND_PROPERTY);
266 if ((p != NULL) && (e != NULL)) {
269 t = icalproperty_get_dtend(e);
270 event_tte = icaltime_as_timet(t);
271 localtime_r(&event_tte, &event_tme);
272 difftime=(event_tte-event_tts)/60;
273 hours=(int)(difftime / 60);
274 minutes=difftime % 60;
275 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
277 "<a href=\"display_edit_event?msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\">",
281 WC->disp_cal[i].cal_msgnum,
289 icalproperty_get_comment(p));
290 /** \todo: allso ammitime format */
291 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
292 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
294 wprintf("</a></font></td>"
295 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
312 * \brief view one month. pretty view
313 * \param year the year
314 * \param month the month
315 * \param day the actual day we want to see
317 void calendar_month_view(int year, int month, int day) {
318 struct tm starting_tm;
322 time_t previous_month;
324 time_t colheader_time;
325 struct tm colheader_tm;
326 char colheader_label[32];
328 /** Determine what day to start.
329 * First, back up to the 1st of the month...
331 memset(&starting_tm, 0, sizeof(struct tm));
332 starting_tm.tm_year = year - 1900;
333 starting_tm.tm_mon = month - 1;
334 starting_tm.tm_mday = day;
335 thetime = mktime(&starting_tm);
337 memcpy(&tm, &starting_tm, sizeof(struct tm));
338 while (tm.tm_mday != 1) {
339 thetime = thetime - (time_t)86400; /* go back 24 hours */
340 localtime_r(&thetime, &tm);
343 /** Determine previous and next months ... for links */
344 previous_month = thetime - (time_t)864000L; /* back 10 days */
345 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
347 /** Now back up until we're on a Sunday */
348 localtime_r(&thetime, &tm);
349 while (tm.tm_wday != 0) {
350 thetime = thetime - (time_t)86400; /* go back 24 hours */
351 localtime_r(&thetime, &tm);
354 /** Outer table (to get the background color) */
355 wprintf("<div class=\"fix_scrollbar_bug\">"
356 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
357 "bgcolor=#204B78><TR><TD>\n");
359 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
361 wprintf("<td align=center>");
363 localtime_r(&previous_month, &tm);
364 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
365 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
366 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
368 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
369 wprintf(" "
370 "<font size=+1 color=\"#FFFFFF\">"
373 " ", colheader_label, year);
375 localtime_r(&next_month, &tm);
376 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
377 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
378 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
380 wprintf("</td></tr></table>\n");
382 /** Inner table (the real one) */
383 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
384 "bgcolor=#204B78 id=\"inner_month\"><tr>");
385 colheader_time = thetime;
386 for (i=0; i<7; ++i) {
387 colheader_time = thetime + (i * 86400) ;
388 localtime_r(&colheader_time, &colheader_tm);
389 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
390 wprintf("<td align=center width=14%%>"
391 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
396 /** Now do 35 days */
397 for (i = 0; i < 35; ++i) {
398 localtime_r(&thetime, &tm);
400 /** Before displaying Sunday, start a new row */
405 wprintf("<td bgcolor=\"#%s\" width=14%% height=60 align=left valign=top><b>",
406 ((tm.tm_mon != month-1) ? "DDDDDD" :
407 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
410 if ((i==0) || (tm.tm_mday == 1)) {
411 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
412 wprintf("%s ", colheader_label);
414 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
421 /** put the data here, stupid */
422 calendar_month_view_display_events(thetime);
426 /** After displaying Saturday, end the row */
431 thetime += (time_t)86400; /** ahead 24 hours */
434 wprintf("</table>" /** end of inner table */
435 "</td></tr></table>" /** end of outer table */
439 * Initialize the bubble tooltips.
441 * Yes, this is as stupid as it looks. Instead of just making the call
442 * to btt_enableTooltips() straight away, we have to create a timer event
443 * and let it initialize as an event after 1 millisecond. This is to
444 * work around a bug in Internet Explorer that causes it to crash if we
445 * manipulate the innerHTML of various DOM nodes while the page is still
446 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
447 * for more information.
449 wprintf("<script type=\"text/javascript\">"
450 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
456 * \brief view one month. brief view
457 * \param year the year
458 * \param month the month
459 * \param day the actual day we want to see
461 void calendar_brief_month_view(int year, int month, int day) {
462 struct tm starting_tm;
466 time_t previous_month;
468 char month_label[32];
470 /** Determine what day to start.
471 * First, back up to the 1st of the month...
473 memset(&starting_tm, 0, sizeof(struct tm));
474 starting_tm.tm_year = year - 1900;
475 starting_tm.tm_mon = month - 1;
476 starting_tm.tm_mday = day;
477 thetime = mktime(&starting_tm);
479 memcpy(&tm, &starting_tm, sizeof(struct tm));
480 while (tm.tm_mday != 1) {
481 thetime = thetime - (time_t)86400; /* go back 24 hours */
482 localtime_r(&thetime, &tm);
485 /** Determine previous and next months ... for links */
486 previous_month = thetime - (time_t)864000L; /* back 10 days */
487 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
489 /** Now back up until we're on a Sunday */
490 localtime_r(&thetime, &tm);
491 while (tm.tm_wday != 0) {
492 thetime = thetime - (time_t)86400; /* go back 24 hours */
493 localtime_r(&thetime, &tm);
496 /** Outer table (to get the background color) */
497 wprintf("<div class=\"fix_scrollbar_bug\">"
498 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
499 "bgcolor=#204B78><TR><TD>\n");
501 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
503 wprintf("<td align=center>");
505 localtime_r(&previous_month, &tm);
506 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
507 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
508 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
510 wc_strftime(month_label, sizeof month_label, "%B", &tm);
511 wprintf(" "
512 "<font size=+1 color=\"#FFFFFF\">"
515 " ", month_label, year);
517 localtime_r(&next_month, &tm);
518 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
519 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
520 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
522 wprintf("</td></tr></table>\n");
524 /** Inner table (the real one) */
525 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
526 "bgcolor=#EEEECC><TR>");
528 wprintf("<tr><td colspan=\"100%\">\n");
530 /** Now do 35 days */
531 for (i = 0; i < 35; ++i) {
532 char weeknumber[255];
533 char weekday_name[32];
535 localtime_r(&thetime, &tm);
538 /** Before displaying Sunday, start a new CELL */
540 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
541 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
542 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
552 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
553 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
557 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
558 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
559 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
561 weekday_name,tm.tm_mday,
564 /** put the data of one day here, stupid */
565 calendar_month_view_brief_events(thetime, daycolor);
568 /** After displaying Saturday, end the row */
570 wprintf("</td></tr></table>\n");
573 thetime += (time_t)86400; /** ahead 24 hours */
576 wprintf("</table>" /** end of inner table */
577 "</td></tr></table>" /** end of outer table */
582 * \brief view one week
583 * this should view just one week, but it's not here yet.
584 * \todo ny implemented
585 * \param year the year
586 * \param month the month
587 * \param day the day which we want to see the week around
589 void calendar_week_view(int year, int month, int day) {
590 wprintf("<center><i>week view FIXME</i></center><br />\n");
595 * \brief display one day
596 * Display events for a particular hour of a particular day.
597 * (Specify hour < 0 to show "all day" events)
598 * \param year the year
599 * \param month the month
601 * \param hour the hour we want to start displaying?????
603 void calendar_day_view_display_events(int year, int month,
607 icalproperty *pe = NULL;
608 struct icaltimetype t;
609 struct icaltimetype te;
614 int all_day_event = 0;
616 if (WC->num_cal == 0) {
617 // \todo FIXME wprintf("<br /><br /><br />\n");
621 for (i=0; i<(WC->num_cal); ++i) {
622 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
623 ICAL_DTSTART_PROPERTY);
624 pe = icalcomponent_get_first_property(WC->disp_cal[i].cal,
625 ICAL_DTEND_PROPERTY);
627 t = icalproperty_get_dtstart(p);
628 event_tt = icaltime_as_timet(t);
637 gmtime_r(&event_tt, &event_tm);
638 gmtime_r(&event_tt, &event_te);
641 localtime_r(&event_tt, &event_tm);
644 te = icalproperty_get_dtend(pe);
645 event_tte = icaltime_as_timet(te);
646 localtime_r(&event_tte, &event_te);
649 localtime_r(&event_tt, &event_te);
652 if (((event_tm.tm_year <= (year-1900))
653 && (event_tm.tm_mon <= (month-1))
654 && (event_tm.tm_mday <= day)
655 && (event_te.tm_year >= (year-1900))
656 && (event_te.tm_mon >= (month-1))
657 && (event_te.tm_mday >= day))
659 // are we in the start hour?
660 ((event_tm.tm_mday == day)
661 && (event_tm.tm_hour == hour)
663 // are we an all day event?
664 || ((hour<0)&&(t.is_date))
665 // does it span multible days and we're not at the start day?
667 && (event_tm.tm_mday < day)
668 && (event_te.tm_mday >= day))
671 p = icalcomponent_get_first_property(
673 ICAL_SUMMARY_PROPERTY);
677 wprintf("<table border=1 cellpadding=2><TR>"
678 "<td bgcolor=\"#CCCCCC\">"
682 wprintf("<font size=-1>"
683 "<a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d\">",
684 WC->disp_cal[i].cal_msgnum,
688 icalproperty_get_comment(p));
689 wprintf("</a></font><br />\n");
692 wprintf("</td></tr></table>");
705 * \brief view one day
706 * \param year the year
707 * \param month the month
708 * \param day the day we want to display
710 void calendar_day_view(int year, int month, int day) {
712 struct icaltimetype today, yesterday, tomorrow;
713 char calhourformat[16];
716 char daystart_str[16], dayend_str[16];
720 get_preference("calhourformat", calhourformat, sizeof calhourformat);
721 get_preference("daystart", daystart_str, sizeof daystart_str);
722 if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
723 get_preference("dayend", dayend_str, sizeof dayend_str);
724 if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str);
727 /** Figure out the dates for "yesterday" and "tomorrow" links */
729 memset(&today, 0, sizeof(struct icaltimetype));
735 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
737 yesterday = icaltime_normalize(yesterday);
739 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
741 tomorrow = icaltime_normalize(tomorrow);
744 /** Outer table (to get the background color) */
745 wprintf("<div class=\"fix_scrollbar_bug\">"
746 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
747 "bgcolor=#204B78><tr><td>\n");
749 /** Inner table (the real one) */
750 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
751 "bgcolor=#204B78><tr>\n");
753 /** Innermost table (contains hours etc.) */
754 wprintf("<td width=80%%>"
755 "<table width=100%% border=0 cellpadding=1 cellspacing=1 "
756 "bgcolor=#204B78>\n");
758 /** Display events before 8:00 (hour=-1 is all-day events) */
760 "<td bgcolor=\"#CCCCDD\" valign=middle width=10%%></td>"
761 "<td bgcolor=\"#FFFFFF\" valign=top>");
762 for (hour = (-1); hour <= (daystart-1); ++hour) {
763 calendar_day_view_display_events(year, month, day, hour);
765 wprintf("</td></tr>\n");
767 /** Now the middle of the day... */
768 for (hour = daystart; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
769 wprintf("<tr height=30><td bgcolor=\"#CCCCDD\" align=middle "
770 "valign=middle width=10%%>");
771 wprintf("<a href=\"display_edit_event?msgnum=0"
772 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
773 year, month, day, hour
776 if (!strcasecmp(calhourformat, "24")) {
777 wprintf("%2d:00</a> ", hour);
780 wprintf("%d:00%s</a> ",
781 (hour <= 12 ? hour : hour-12),
782 (hour < 12 ? "am" : "pm")
786 wprintf("</td><td bgcolor=\"#FFFFFF\" valign=top>");
788 /* put the data here, stupid */
789 calendar_day_view_display_events(year, month, day, hour);
791 wprintf("</td></tr>\n");
794 /** Display events after 5:00... */
796 "<td bgcolor=\"#CCCCDD\" valign=middle width=10%%></td>"
797 "<td bgcolor=\"#FFFFFF\" valign=top>");
798 for (hour = (dayend+1); hour <= 23; ++hour) {
799 calendar_day_view_display_events(year, month, day, hour);
801 wprintf("</td></tr>\n");
804 wprintf("</table>" /* end of innermost table */
808 wprintf("<td width=20%% valign=top>"); /* begin stuff-on-the-right */
811 /** Begin todays-date-with-left-and-right-arrows */
812 wprintf("<table border=0 width=100%% "
813 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
817 wprintf("<td align=center>");
818 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
819 yesterday.year, yesterday.month, yesterday.day);
820 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
824 memset(&d_tm, 0, sizeof d_tm);
825 d_tm.tm_year = year - 1900;
826 d_tm.tm_mon = month - 1;
828 wc_strftime(d_str, sizeof d_str,
830 "<font size=+2>%B</font><br />"
831 "<font size=+3>%d</font><br />"
832 "<font size=+2>%Y</font><br />"
836 wprintf("%s", d_str);
839 wprintf("<td align=center>");
840 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
841 tomorrow.year, tomorrow.month, tomorrow.day);
842 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
846 wprintf("</tr></table>\n");
847 /** End todays-date-with-left-and-right-arrows */
849 /** \todo In the future we might want to put a month-o-matic here */
851 wprintf("</font></center>\n");
853 wprintf("</td>"); /** end stuff-on-the-right */
857 wprintf("</tr></table>" /** end of inner table */
858 "</td></tr></table></div>" /** end of outer table */
866 * \brief Display today's events.
868 void calendar_summary_view(void) {
871 struct icaltimetype t;
876 int all_day_event = 0;
877 char timestring[SIZ];
879 if (WC->num_cal == 0) {
884 localtime_r(&now, &today_tm);
886 for (i=0; i<(WC->num_cal); ++i) {
887 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
888 ICAL_DTSTART_PROPERTY);
890 t = icalproperty_get_dtstart(p);
891 event_tt = icaltime_as_timet(t);
898 fmt_time(timestring, event_tt);
901 gmtime_r(&event_tt, &event_tm);
904 localtime_r(&event_tt, &event_tm);
907 if ( (event_tm.tm_year == today_tm.tm_year)
908 && (event_tm.tm_mon == today_tm.tm_mon)
909 && (event_tm.tm_mday == today_tm.tm_mday)
913 p = icalcomponent_get_first_property(
915 ICAL_SUMMARY_PROPERTY);
918 icalproperty_get_comment(p));
919 wprintf(" (%s)<br />\n", timestring);
924 free_calendar_buffer();
929 * \brief clean up ical memory
930 * \todo this could get troubel with future ical versions
932 void free_calendar_buffer(void) {
934 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
935 icalcomponent_free(WC->disp_cal[i].cal);
945 * \brief do the whole calendar page
946 * view any part of the calender. decide which way, etc.
948 void do_calendar_view(void) {
951 int year, month, day;
954 /** In case no date was specified, go with today */
956 localtime_r(&now, &tm);
957 year = tm.tm_year + 1900;
958 month = tm.tm_mon + 1;
961 /** Now see if a date was specified */
962 if (!IsEmptyStr(bstr("year"))) year = atoi(bstr("year"));
963 if (!IsEmptyStr(bstr("month"))) month = atoi(bstr("month"));
964 if (!IsEmptyStr(bstr("day"))) day = atoi(bstr("day"));
966 /** How would you like that cooked? */
967 if (!IsEmptyStr(bstr("calview"))) {
968 strcpy(calview, bstr("calview"));
971 strcpy(calview, "month");
974 /** Display the selected view */
975 if (!strcasecmp(calview, "day")) {
976 calendar_day_view(year, month, day);
978 else if (!strcasecmp(calview, "week")) {
979 calendar_week_view(year, month, day);
982 if (WC->wc_view == VIEW_CALBRIEF) {
983 calendar_brief_month_view(year, month, day);
986 calendar_month_view(year, month, day);
990 /** Free the calendar stuff */
991 free_calendar_buffer();
997 * \brief get task due date
998 * Helper function for do_tasks_view().
999 * \param vtodo a task to get the due date
1000 * \return the date/time due.
1002 time_t get_task_due_date(icalcomponent *vtodo) {
1005 if (vtodo == NULL) {
1010 * If we're looking at a fully encapsulated VCALENDAR
1011 * rather than a VTODO component, recurse into the data
1012 * structure until we get a VTODO.
1014 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1015 return get_task_due_date(
1016 icalcomponent_get_first_component(
1017 vtodo, ICAL_VTODO_COMPONENT
1022 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1024 return(icaltime_as_timet(icalproperty_get_due(p)));
1033 * \brief Compare the due dates of two tasks (this is for sorting)
1034 * \param task1 first task to compare
1035 * \param task2 second task to compare
1037 int task_due_cmp(const void *task1, const void *task2) {
1041 t1 = get_task_due_date(((struct disp_cal *)task1)->cal);
1042 t2 = get_task_due_date(((struct disp_cal *)task2)->cal);
1044 if (t1 < t2) return(-1);
1045 if (t1 > t2) return(1);
1053 * \brief do the whole task view stuff
1055 void do_tasks_view(void) {
1062 wprintf("<div class=\"fix_scrollbar_bug\">"
1063 "<table class=\"calendar_view_background\">\n<tr>\n"
1065 wprintf(_("Name of task"));
1066 wprintf("</th><th>");
1067 wprintf(_("Date due"));
1068 wprintf("</th></tr>\n"
1071 /** Sort them if necessary */
1072 if (WC->num_cal > 1) {
1075 sizeof(struct disp_cal),
1080 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1083 wprintf("<tr bgcolor=\"#%s\"><td>",
1084 (bg ? "DDDDDD" : "FFFFFF")
1087 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1088 ICAL_SUMMARY_PROPERTY);
1089 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1090 WC->disp_cal[i].cal_msgnum );
1091 urlescputs(WC->wc_roomname);
1093 wprintf("<img align=middle "
1094 "src=\"static/taskmanag_16x.gif\" border=0> ");
1096 escputs((char *)icalproperty_get_comment(p));
1101 due = get_task_due_date(WC->disp_cal[i].cal);
1102 fmt_date(buf, due, 0);
1103 wprintf("<td><font");
1104 if (due < time(NULL)) {
1105 wprintf(" color=\"#FF0000\"");
1107 wprintf(">%s</font></td></tr>\n", buf);
1110 wprintf("</table></div>\n");
1112 /** Free the list */
1113 free_calendar_buffer();
1117 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */