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];
330 /** Determine what day to start.
331 * First, back up to the 1st of the month...
333 memset(&starting_tm, 0, sizeof(struct tm));
334 starting_tm.tm_year = year - 1900;
335 starting_tm.tm_mon = month - 1;
336 starting_tm.tm_mday = day;
337 thetime = mktime(&starting_tm);
339 memcpy(&tm, &starting_tm, sizeof(struct tm));
340 while (tm.tm_mday != 1) {
341 thetime = thetime - (time_t)86400; /* go back 24 hours */
342 localtime_r(&thetime, &tm);
345 /** Determine previous and next months ... for links */
346 previous_month = thetime - (time_t)864000L; /* back 10 days */
347 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
349 /** Now back up until we're on a Sunday */
350 localtime_r(&thetime, &tm);
351 while (tm.tm_wday != 0) {
352 thetime = thetime - (time_t)86400; /* go back 24 hours */
353 localtime_r(&thetime, &tm);
356 /** Outer table (to get the background color) */
357 wprintf("<div class=\"fix_scrollbar_bug\">"
358 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
359 "bgcolor=#204B78><TR><TD>\n");
361 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
363 wprintf("<td align=center>");
365 localtime_r(&previous_month, &tm);
366 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
367 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
368 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
370 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
371 wprintf(" "
372 "<font size=+1 color=\"#FFFFFF\">"
375 " ", colheader_label, year);
377 localtime_r(&next_month, &tm);
378 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
379 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
380 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
382 wprintf("</td></tr></table>\n");
384 /** Inner table (the real one) */
385 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
386 "bgcolor=#204B78 id=\"inner_month\"><tr>");
387 colheader_time = thetime;
388 for (i=0; i<7; ++i) {
389 colheader_time = thetime + (i * 86400) ;
390 localtime_r(&colheader_time, &colheader_tm);
391 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
392 wprintf("<td align=center width=14%%>"
393 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
399 /** Now do 35 or 42 days */
400 for (i = 0; i < 42; ++i) {
401 localtime_r(&thetime, &tm);
403 if ((i < 35) || (chg_month == 0)) {
405 if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) {
412 /** Before displaying Sunday, start a new row */
417 wprintf("<td bgcolor=\"#%s\" width=14%% height=60 align=left valign=top><b>",
418 ((tm.tm_mon != month-1) ? "DDDDDD" :
419 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
422 if ((i==0) || (tm.tm_mday == 1)) {
423 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
424 wprintf("%s ", colheader_label);
426 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
433 /** put the data here, stupid */
434 calendar_month_view_display_events(thetime);
438 /** After displaying Saturday, end the row */
445 thetime += (time_t)86400; /** ahead 24 hours */
448 wprintf("</table>" /** end of inner table */
449 "</td></tr></table>" /** end of outer table */
453 * Initialize the bubble tooltips.
455 * Yes, this is as stupid as it looks. Instead of just making the call
456 * to btt_enableTooltips() straight away, we have to create a timer event
457 * and let it initialize as an event after 1 millisecond. This is to
458 * work around a bug in Internet Explorer that causes it to crash if we
459 * manipulate the innerHTML of various DOM nodes while the page is still
460 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
461 * for more information.
463 wprintf("<script type=\"text/javascript\">"
464 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
470 * \brief view one month. brief view
471 * \param year the year
472 * \param month the month
473 * \param day the actual day we want to see
475 void calendar_brief_month_view(int year, int month, int day) {
476 struct tm starting_tm;
480 time_t previous_month;
482 char month_label[32];
484 /** Determine what day to start.
485 * First, back up to the 1st of the month...
487 memset(&starting_tm, 0, sizeof(struct tm));
488 starting_tm.tm_year = year - 1900;
489 starting_tm.tm_mon = month - 1;
490 starting_tm.tm_mday = day;
491 thetime = mktime(&starting_tm);
493 memcpy(&tm, &starting_tm, sizeof(struct tm));
494 while (tm.tm_mday != 1) {
495 thetime = thetime - (time_t)86400; /* go back 24 hours */
496 localtime_r(&thetime, &tm);
499 /** Determine previous and next months ... for links */
500 previous_month = thetime - (time_t)864000L; /* back 10 days */
501 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
503 /** Now back up until we're on a Sunday */
504 localtime_r(&thetime, &tm);
505 while (tm.tm_wday != 0) {
506 thetime = thetime - (time_t)86400; /* go back 24 hours */
507 localtime_r(&thetime, &tm);
510 /** Outer table (to get the background color) */
511 wprintf("<div class=\"fix_scrollbar_bug\">"
512 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
513 "bgcolor=#204B78><TR><TD>\n");
515 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
517 wprintf("<td align=center>");
519 localtime_r(&previous_month, &tm);
520 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
521 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
522 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
524 wc_strftime(month_label, sizeof month_label, "%B", &tm);
525 wprintf(" "
526 "<font size=+1 color=\"#FFFFFF\">"
529 " ", month_label, year);
531 localtime_r(&next_month, &tm);
532 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
533 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
534 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
536 wprintf("</td></tr></table>\n");
538 /** Inner table (the real one) */
539 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
540 "bgcolor=#EEEECC><TR>");
542 wprintf("<tr><td colspan=\"100%\">\n");
544 /** Now do 35 days */
545 for (i = 0; i < 35; ++i) {
546 char weeknumber[255];
547 char weekday_name[32];
549 localtime_r(&thetime, &tm);
552 /** Before displaying Sunday, start a new CELL */
554 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
555 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
556 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
566 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
567 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
571 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
572 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
573 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
575 weekday_name,tm.tm_mday,
578 /** put the data of one day here, stupid */
579 calendar_month_view_brief_events(thetime, daycolor);
582 /** After displaying Saturday, end the row */
584 wprintf("</td></tr></table>\n");
587 thetime += (time_t)86400; /** ahead 24 hours */
590 wprintf("</table>" /** end of inner table */
591 "</td></tr></table>" /** end of outer table */
596 * \brief view one week
597 * this should view just one week, but it's not here yet.
598 * \todo ny implemented
599 * \param year the year
600 * \param month the month
601 * \param day the day which we want to see the week around
603 void calendar_week_view(int year, int month, int day) {
604 wprintf("<center><i>week view FIXME</i></center><br />\n");
609 * \brief display one day
610 * Display events for a particular hour of a particular day.
611 * (Specify hour < 0 to show "all day" events)
612 * \param year the year
613 * \param month the month
615 * \param hour the hour we want to start displaying?????
617 void calendar_day_view_display_events(int year, int month,
621 icalproperty *pe = NULL;
622 struct icaltimetype t;
623 struct icaltimetype te;
628 int all_day_event = 0;
630 if (WC->num_cal == 0) {
631 // \todo FIXME wprintf("<br /><br /><br />\n");
635 for (i=0; i<(WC->num_cal); ++i) {
636 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
637 ICAL_DTSTART_PROPERTY);
638 pe = icalcomponent_get_first_property(WC->disp_cal[i].cal,
639 ICAL_DTEND_PROPERTY);
641 t = icalproperty_get_dtstart(p);
642 event_tt = icaltime_as_timet(t);
651 gmtime_r(&event_tt, &event_tm);
652 gmtime_r(&event_tt, &event_te);
655 localtime_r(&event_tt, &event_tm);
658 te = icalproperty_get_dtend(pe);
659 event_tte = icaltime_as_timet(te);
660 localtime_r(&event_tte, &event_te);
663 localtime_r(&event_tt, &event_te);
666 if (((event_tm.tm_year <= (year-1900))
667 && (event_tm.tm_mon <= (month-1))
668 && (event_tm.tm_mday <= day)
669 && (event_te.tm_year >= (year-1900))
670 && (event_te.tm_mon >= (month-1))
671 && (event_te.tm_mday >= day))
673 // are we in the start hour?
674 ((event_tm.tm_mday == day)
675 && (event_tm.tm_hour == hour)
677 // are we an all day event?
678 || ((hour<0)&&(t.is_date))
679 // does it span multible days and we're not at the start day?
681 && (event_tm.tm_mday < day)
682 && (event_te.tm_mday >= day))
685 p = icalcomponent_get_first_property(
687 ICAL_SUMMARY_PROPERTY);
691 wprintf("<table border=1 cellpadding=2><TR>"
692 "<td bgcolor=\"#CCCCCC\">"
696 wprintf("<font size=-1>"
697 "<a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d\">",
698 WC->disp_cal[i].cal_msgnum,
702 icalproperty_get_comment(p));
703 wprintf("</a></font><br />\n");
706 wprintf("</td></tr></table>");
719 * \brief view one day
720 * \param year the year
721 * \param month the month
722 * \param day the day we want to display
724 void calendar_day_view(int year, int month, int day) {
726 struct icaltimetype today, yesterday, tomorrow;
729 char daystart_str[16], dayend_str[16];
734 time_format = get_time_format_cached ();
735 get_preference("daystart", daystart_str, sizeof daystart_str);
736 if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
737 get_preference("dayend", dayend_str, sizeof dayend_str);
738 if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str);
741 /** Figure out the dates for "yesterday" and "tomorrow" links */
743 memset(&today, 0, sizeof(struct icaltimetype));
749 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
751 yesterday = icaltime_normalize(yesterday);
753 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
755 tomorrow = icaltime_normalize(tomorrow);
758 /** Outer table (to get the background color) */
759 wprintf("<div class=\"fix_scrollbar_bug\">"
760 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
761 "bgcolor=#204B78><tr><td>\n");
763 /** Inner table (the real one) */
764 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
765 "bgcolor=#204B78><tr>\n");
767 /** Innermost table (contains hours etc.) */
768 wprintf("<td width=80%%>"
769 "<table width=100%% border=0 cellpadding=1 cellspacing=1 "
770 "bgcolor=#204B78>\n");
772 /** Display events before 8:00 (hour=-1 is all-day events) */
774 "<td bgcolor=\"#CCCCDD\" valign=middle width=10%%></td>"
775 "<td bgcolor=\"#FFFFFF\" valign=top>");
776 for (hour = (-1); hour <= (daystart-1); ++hour) {
777 calendar_day_view_display_events(year, month, day, hour);
779 wprintf("</td></tr>\n");
781 /** Now the middle of the day... */
782 for (hour = daystart; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
783 wprintf("<tr height=30><td bgcolor=\"#CCCCDD\" align=middle "
784 "valign=middle width=10%%>");
785 wprintf("<a href=\"display_edit_event?msgnum=0"
786 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
787 year, month, day, hour
790 if (time_format == WC_TIMEFORMAT_24) {
791 wprintf("%2d:00</a> ", hour);
794 wprintf("%d:00%s</a> ",
795 (hour <= 12 ? hour : hour-12),
796 (hour < 12 ? "am" : "pm")
800 wprintf("</td><td bgcolor=\"#FFFFFF\" valign=top>");
802 /* put the data here, stupid */
803 calendar_day_view_display_events(year, month, day, hour);
805 wprintf("</td></tr>\n");
808 /** Display events after 5:00... */
810 "<td bgcolor=\"#CCCCDD\" valign=middle width=10%%></td>"
811 "<td bgcolor=\"#FFFFFF\" valign=top>");
812 for (hour = (dayend+1); hour <= 23; ++hour) {
813 calendar_day_view_display_events(year, month, day, hour);
815 wprintf("</td></tr>\n");
818 wprintf("</table>" /* end of innermost table */
822 wprintf("<td width=20%% valign=top>"); /* begin stuff-on-the-right */
825 /** Begin todays-date-with-left-and-right-arrows */
826 wprintf("<table border=0 width=100%% "
827 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
831 wprintf("<td align=center>");
832 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
833 yesterday.year, yesterday.month, yesterday.day);
834 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
838 memset(&d_tm, 0, sizeof d_tm);
839 d_tm.tm_year = year - 1900;
840 d_tm.tm_mon = month - 1;
842 wc_strftime(d_str, sizeof d_str,
844 "<font size=+2>%B</font><br />"
845 "<font size=+3>%d</font><br />"
846 "<font size=+2>%Y</font><br />"
850 wprintf("%s", d_str);
853 wprintf("<td align=center>");
854 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
855 tomorrow.year, tomorrow.month, tomorrow.day);
856 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
860 wprintf("</tr></table>\n");
861 /** End todays-date-with-left-and-right-arrows */
863 /** \todo In the future we might want to put a month-o-matic here */
865 wprintf("</font></center>\n");
867 wprintf("</td>"); /** end stuff-on-the-right */
871 wprintf("</tr></table>" /** end of inner table */
872 "</td></tr></table></div>" /** end of outer table */
880 * \brief Display today's events.
882 void calendar_summary_view(void) {
885 struct icaltimetype t;
890 int all_day_event = 0;
891 char timestring[SIZ];
893 if (WC->num_cal == 0) {
898 localtime_r(&now, &today_tm);
900 for (i=0; i<(WC->num_cal); ++i) {
901 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
902 ICAL_DTSTART_PROPERTY);
904 t = icalproperty_get_dtstart(p);
905 event_tt = icaltime_as_timet(t);
912 fmt_time(timestring, event_tt);
915 gmtime_r(&event_tt, &event_tm);
918 localtime_r(&event_tt, &event_tm);
921 if ( (event_tm.tm_year == today_tm.tm_year)
922 && (event_tm.tm_mon == today_tm.tm_mon)
923 && (event_tm.tm_mday == today_tm.tm_mday)
927 p = icalcomponent_get_first_property(
929 ICAL_SUMMARY_PROPERTY);
932 icalproperty_get_comment(p));
933 wprintf(" (%s)<br />\n", timestring);
938 free_calendar_buffer();
943 * \brief clean up ical memory
944 * \todo this could get troubel with future ical versions
946 void free_calendar_buffer(void) {
948 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
949 icalcomponent_free(WC->disp_cal[i].cal);
959 * \brief do the whole calendar page
960 * view any part of the calender. decide which way, etc.
962 void do_calendar_view(void) {
965 int year, month, day;
968 /** In case no date was specified, go with today */
970 localtime_r(&now, &tm);
971 year = tm.tm_year + 1900;
972 month = tm.tm_mon + 1;
975 /** Now see if a date was specified */
976 if (!IsEmptyStr(bstr("year"))) year = atoi(bstr("year"));
977 if (!IsEmptyStr(bstr("month"))) month = atoi(bstr("month"));
978 if (!IsEmptyStr(bstr("day"))) day = atoi(bstr("day"));
980 /** How would you like that cooked? */
981 if (!IsEmptyStr(bstr("calview"))) {
982 strcpy(calview, bstr("calview"));
985 strcpy(calview, "month");
988 /** Display the selected view */
989 if (!strcasecmp(calview, "day")) {
990 calendar_day_view(year, month, day);
992 else if (!strcasecmp(calview, "week")) {
993 calendar_week_view(year, month, day);
996 if (WC->wc_view == VIEW_CALBRIEF) {
997 calendar_brief_month_view(year, month, day);
1000 calendar_month_view(year, month, day);
1004 /** Free the calendar stuff */
1005 free_calendar_buffer();
1011 * \brief get task due date
1012 * Helper function for do_tasks_view().
1013 * \param vtodo a task to get the due date
1014 * \return the date/time due.
1016 time_t get_task_due_date(icalcomponent *vtodo) {
1019 if (vtodo == NULL) {
1024 * If we're looking at a fully encapsulated VCALENDAR
1025 * rather than a VTODO component, recurse into the data
1026 * structure until we get a VTODO.
1028 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1029 return get_task_due_date(
1030 icalcomponent_get_first_component(
1031 vtodo, ICAL_VTODO_COMPONENT
1036 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1038 return(icaltime_as_timet(icalproperty_get_due(p)));
1047 * \brief Compare the due dates of two tasks (this is for sorting)
1048 * \param task1 first task to compare
1049 * \param task2 second task to compare
1051 int task_due_cmp(const void *task1, const void *task2) {
1055 t1 = get_task_due_date(((struct disp_cal *)task1)->cal);
1056 t2 = get_task_due_date(((struct disp_cal *)task2)->cal);
1058 if (t1 < t2) return(-1);
1059 if (t1 > t2) return(1);
1067 * \brief do the whole task view stuff
1069 void do_tasks_view(void) {
1076 wprintf("<div class=\"fix_scrollbar_bug\">"
1077 "<table class=\"calendar_view_background\">\n<tr>\n"
1079 wprintf(_("Name of task"));
1080 wprintf("</th><th>");
1081 wprintf(_("Date due"));
1082 wprintf("</th></tr>\n"
1085 /** Sort them if necessary */
1086 if (WC->num_cal > 1) {
1089 sizeof(struct disp_cal),
1094 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1097 wprintf("<tr bgcolor=\"#%s\"><td>",
1098 (bg ? "DDDDDD" : "FFFFFF")
1101 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1102 ICAL_SUMMARY_PROPERTY);
1103 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1104 WC->disp_cal[i].cal_msgnum );
1105 urlescputs(WC->wc_roomname);
1107 wprintf("<img align=middle "
1108 "src=\"static/taskmanag_16x.gif\" border=0> ");
1110 escputs((char *)icalproperty_get_comment(p));
1115 due = get_task_due_date(WC->disp_cal[i].cal);
1116 fmt_date(buf, due, 0);
1117 wprintf("<td><font");
1118 if (due < time(NULL)) {
1119 wprintf(" color=\"#FF0000\"");
1121 wprintf(">%s</font></td></tr>\n", buf);
1124 wprintf("</table></div>\n");
1126 /** Free the list */
1127 free_calendar_buffer();
1131 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */