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) {
42 icalproperty *p = NULL;
43 icalproperty *pe = NULL;
44 icalproperty *q = NULL;
45 struct icaltimetype t;
47 int all_day_event = 0;
48 int multi_day_event = 0;
53 if (WC->num_cal == 0) {
54 wprintf("<br /><br /><br />\n");
58 localtime_r(&thetime, &today_tm);
59 month = today_tm.tm_mon + 1;
60 day = today_tm.tm_mday;
61 year = today_tm.tm_year + 1900;
63 for (i=0; i<(WC->num_cal); ++i) {
64 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
65 ICAL_DTSTART_PROPERTY);
66 pe = icalcomponent_get_first_property(WC->disp_cal[i].cal,
69 t = icalproperty_get_dtstart(p);
70 event_tt = icaltime_as_timet(t);
72 if (t.is_date) all_day_event = 1;
73 else all_day_event = 0;
76 gmtime_r(&event_tt, &event_tm);
78 show_event = ((event_tm.tm_year <= today_tm.tm_year)
79 && (event_tm.tm_mon <= today_tm.tm_mon)
80 && (event_tm.tm_mday <= today_tm.tm_mday));
83 localtime_r(&event_tt, &event_tm);
87 t = icalproperty_get_dtend(pe);
88 event_tte = icaltime_as_timet(t);
90 gmtime_r(&event_tte, &event_ttm);
91 // are we in the range of the event?
92 show_event = ((event_tt <= thetime) &&
93 (event_tte >= thetime));
97 show_event = ((event_tm.tm_year <= today_tm.tm_year)
98 && (event_tm.tm_mon <= today_tm.tm_mon)
99 && (event_tm.tm_mday <= today_tm.tm_mday));
104 p = icalcomponent_get_first_property(
106 ICAL_SUMMARY_PROPERTY);
110 wprintf("<table border=0 cellpadding=2><TR>"
111 "<td bgcolor=\"#CCCCDD\">"
115 wprintf("<font size=-1>"
116 "<a href=\"display_edit_event?"
117 "msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\""
119 WC->disp_cal[i].cal_msgnum,
126 wprintf("<i>%s</i> ", _("Summary:"));
127 escputs((char *)icalproperty_get_comment(p));
130 q = icalcomponent_get_first_property(
132 ICAL_LOCATION_PROPERTY);
134 wprintf("<i>%s</i> ", _("Location:"));
135 escputs((char *)icalproperty_get_comment(q));
140 * Only show start/end times if we're actually looking at the VEVENT
141 * component. Otherwise it shows bogus dates for e.g. timezones
143 if (icalcomponent_isa(WC->disp_cal[i].cal) == ICAL_VEVENT_COMPONENT) {
145 q = icalcomponent_get_first_property(WC->disp_cal[i].cal,
146 ICAL_DTSTART_PROPERTY);
148 t = icalproperty_get_dtstart(q);
153 memset(&d_tm, 0, sizeof d_tm);
154 d_tm.tm_year = t.year - 1900;
155 d_tm.tm_mon = t.month - 1;
156 d_tm.tm_mday = t.day;
157 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
158 wprintf("<i>%s</i> %s<br>",
162 tt = icaltime_as_timet(t);
163 fmt_date(buf, tt, 1);
164 wprintf("<i>%s</i> %s<br>",
165 _("Starting date/time:"), buf);
167 /* Embed the 'show end date/time' loop inside here so it
168 * only executes if this is NOT an all day event.
170 q = icalcomponent_get_first_property(WC->disp_cal[i].cal,
171 ICAL_DTEND_PROPERTY);
173 t = icalproperty_get_dtend(q);
174 tt = icaltime_as_timet(t);
175 fmt_date(buf, tt, 1);
176 wprintf("<i>%s</i> %s<br>",
177 _("Ending date/time:"), buf);
185 q = icalcomponent_get_first_property(
187 ICAL_DESCRIPTION_PROPERTY);
189 wprintf("<i>%s</i> ", _("Notes:"));
190 escputs((char *)icalproperty_get_comment(q));
196 icalproperty_get_comment(p));
197 wprintf("</a></font><br />\n");
200 wprintf("</td></tr></table>");
214 * \brief Display one day of a whole month view of a calendar
215 * \param thetime the month we want to see
217 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
227 struct icaltimetype t;
228 int month, day, year;
229 int all_day_event = 0;
233 time_format = get_time_format_cached ();
235 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
236 else timeformat="%I:%M %p";
238 localtime_r(&thetime, &today_tm);
239 month = today_tm.tm_mon + 1;
240 day = today_tm.tm_mday;
241 year = today_tm.tm_year + 1900;
243 for (i=0; i<(WC->num_cal); ++i) {
244 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
245 ICAL_DTSTART_PROPERTY);
247 t = icalproperty_get_dtstart(p);
248 event_tt = icaltime_as_timet(t);
250 if (t.is_date) all_day_event = 1;
251 else all_day_event = 0;
254 gmtime_r(&event_tts, &event_tms);
257 localtime_r(&event_tts, &event_tms);
259 /** \todo epoch &! daymask */
260 if ((event_tms.tm_year == today_tm.tm_year)
261 && (event_tms.tm_mon == today_tm.tm_mon)
262 && (event_tms.tm_mday == today_tm.tm_mday)) {
268 p = icalcomponent_get_first_property(
270 ICAL_SUMMARY_PROPERTY);
271 e = icalcomponent_get_first_property(
273 ICAL_DTEND_PROPERTY);
274 if ((p != NULL) && (e != NULL)) {
277 t = icalproperty_get_dtend(e);
278 event_tte = icaltime_as_timet(t);
279 localtime_r(&event_tte, &event_tme);
280 difftime=(event_tte-event_tts)/60;
281 hours=(int)(difftime / 60);
282 minutes=difftime % 60;
283 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
285 "<a href=\"display_edit_event?msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\">",
289 WC->disp_cal[i].cal_msgnum,
297 icalproperty_get_comment(p));
298 /** \todo: allso ammitime format */
299 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
300 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
302 wprintf("</a></font></td>"
303 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
320 * \brief view one month. pretty view
321 * \param year the year
322 * \param month the month
323 * \param day the actual day we want to see
325 void calendar_month_view(int year, int month, int day) {
326 struct tm starting_tm;
330 time_t previous_month;
332 time_t colheader_time;
333 struct tm colheader_tm;
334 char colheader_label[32];
337 /** Determine what day to start.
338 * First, back up to the 1st of the month...
340 memset(&starting_tm, 0, sizeof(struct tm));
341 starting_tm.tm_year = year - 1900;
342 starting_tm.tm_mon = month - 1;
343 starting_tm.tm_mday = day;
344 thetime = mktime(&starting_tm);
346 memcpy(&tm, &starting_tm, sizeof(struct tm));
347 while (tm.tm_mday != 1) {
348 thetime = thetime - (time_t)86400; /* go back 24 hours */
349 localtime_r(&thetime, &tm);
352 /** Determine previous and next months ... for links */
353 previous_month = thetime - (time_t)864000L; /* back 10 days */
354 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
356 /** Now back up until we're on a Sunday */
357 localtime_r(&thetime, &tm);
358 while (tm.tm_wday != 0) {
359 thetime = thetime - (time_t)86400; /* go back 24 hours */
360 localtime_r(&thetime, &tm);
363 /** Outer table (to get the background color) */
364 wprintf("<div class=\"fix_scrollbar_bug\">"
365 "<table class=\"calendar\"> \n <tr><td>");
367 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
369 wprintf("<td align=center>");
371 localtime_r(&previous_month, &tm);
372 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
373 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
374 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
376 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
377 wprintf(" "
378 "<font size=+1 color=\"#FFFFFF\">"
381 " ", colheader_label, year);
383 localtime_r(&next_month, &tm);
384 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
385 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
386 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
388 wprintf("</td></tr></table>\n");
390 /** Inner table (the real one) */
391 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
392 "bgcolor=#204B78 id=\"inner_month\"><tr>");
393 colheader_time = thetime;
394 for (i=0; i<7; ++i) {
395 colheader_time = thetime + (i * 86400) ;
396 localtime_r(&colheader_time, &colheader_tm);
397 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
398 wprintf("<td align=center width=14%%>"
399 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
405 /** Now do 35 or 42 days */
406 for (i = 0; i < 42; ++i) {
407 localtime_r(&thetime, &tm);
409 if ((i < 35) || (chg_month == 0)) {
411 if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) {
418 /** Before displaying Sunday, start a new row */
423 wprintf("<td class=\"cal%s\"><div class=\"day\">",
424 ((tm.tm_mon != month-1) ? "out" :
425 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
428 if ((i==0) || (tm.tm_mday == 1)) {
429 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
430 wprintf("%s ", colheader_label);
432 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
439 /** put the data here, stupid */
440 calendar_month_view_display_events(thetime);
444 /** After displaying Saturday, end the row */
451 thetime += (time_t)86400; /** ahead 24 hours */
454 wprintf("</table>" /** end of inner table */
455 "</td></tr></table>" /** end of outer table */
459 * Initialize the bubble tooltips.
461 * Yes, this is as stupid as it looks. Instead of just making the call
462 * to btt_enableTooltips() straight away, we have to create a timer event
463 * and let it initialize as an event after 1 millisecond. This is to
464 * work around a bug in Internet Explorer that causes it to crash if we
465 * manipulate the innerHTML of various DOM nodes while the page is still
466 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
467 * for more information.
469 wprintf("<script type=\"text/javascript\">"
470 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
476 * \brief view one month. brief view
477 * \param year the year
478 * \param month the month
479 * \param day the actual day we want to see
481 void calendar_brief_month_view(int year, int month, int day) {
482 struct tm starting_tm;
486 time_t previous_month;
488 char month_label[32];
490 /** Determine what day to start.
491 * First, back up to the 1st of the month...
493 memset(&starting_tm, 0, sizeof(struct tm));
494 starting_tm.tm_year = year - 1900;
495 starting_tm.tm_mon = month - 1;
496 starting_tm.tm_mday = day;
497 thetime = mktime(&starting_tm);
499 memcpy(&tm, &starting_tm, sizeof(struct tm));
500 while (tm.tm_mday != 1) {
501 thetime = thetime - (time_t)86400; /* go back 24 hours */
502 localtime_r(&thetime, &tm);
505 /** Determine previous and next months ... for links */
506 previous_month = thetime - (time_t)864000L; /* back 10 days */
507 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
509 /** Now back up until we're on a Sunday */
510 localtime_r(&thetime, &tm);
511 while (tm.tm_wday != 0) {
512 thetime = thetime - (time_t)86400; /* go back 24 hours */
513 localtime_r(&thetime, &tm);
516 /** Outer table (to get the background color) */
517 wprintf("<div class=\"fix_scrollbar_bug\">"
518 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
519 "bgcolor=#204B78><TR><TD>\n");
521 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
523 wprintf("<td align=center>");
525 localtime_r(&previous_month, &tm);
526 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
527 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
528 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
530 wc_strftime(month_label, sizeof month_label, "%B", &tm);
531 wprintf(" "
532 "<font size=+1 color=\"#FFFFFF\">"
535 " ", month_label, year);
537 localtime_r(&next_month, &tm);
538 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
539 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
540 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
542 wprintf("</td></tr></table>\n");
544 /** Inner table (the real one) */
545 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
546 "bgcolor=#EEEECC><TR>");
548 wprintf("<tr><td colspan=\"100%\">\n");
550 /** Now do 35 days */
551 for (i = 0; i < 35; ++i) {
552 char weeknumber[255];
553 char weekday_name[32];
555 localtime_r(&thetime, &tm);
558 /** Before displaying Sunday, start a new CELL */
560 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
561 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
562 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
572 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
573 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
577 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
578 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
579 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
581 weekday_name,tm.tm_mday,
584 /** put the data of one day here, stupid */
585 calendar_month_view_brief_events(thetime, daycolor);
588 /** After displaying Saturday, end the row */
590 wprintf("</td></tr></table>\n");
593 thetime += (time_t)86400; /** ahead 24 hours */
596 wprintf("</table>" /** end of inner table */
597 "</td></tr></table>" /** end of outer table */
602 * \brief view one week
603 * this should view just one week, but it's not here yet.
604 * \todo ny implemented
605 * \param year the year
606 * \param month the month
607 * \param day the day which we want to see the week around
609 void calendar_week_view(int year, int month, int day) {
610 wprintf("<center><i>week view FIXME</i></center><br />\n");
615 * \brief display one day
616 * Display events for a particular hour of a particular day.
617 * (Specify hour < 0 to show "all day" events)
618 * \param year the year
619 * \param month the month
621 * \param hour the hour we want to start displaying?????
623 void calendar_day_view_display_events(int year, int month,
627 icalproperty *pe = NULL;
628 struct icaltimetype t;
629 struct icaltimetype te;
634 int all_day_event = 0;
636 if (WC->num_cal == 0) {
637 // \todo FIXME wprintf("<br /><br /><br />\n");
641 for (i=0; i<(WC->num_cal); ++i) {
642 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
643 ICAL_DTSTART_PROPERTY);
644 pe = icalcomponent_get_first_property(WC->disp_cal[i].cal,
645 ICAL_DTEND_PROPERTY);
647 t = icalproperty_get_dtstart(p);
648 event_tt = icaltime_as_timet(t);
657 gmtime_r(&event_tt, &event_tm);
658 gmtime_r(&event_tt, &event_te);
661 localtime_r(&event_tt, &event_tm);
664 te = icalproperty_get_dtend(pe);
665 event_tte = icaltime_as_timet(te);
666 localtime_r(&event_tte, &event_te);
669 localtime_r(&event_tt, &event_te);
672 if (((event_tm.tm_year <= (year-1900))
673 && (event_tm.tm_mon <= (month-1))
674 && (event_tm.tm_mday <= day)
675 && (event_te.tm_year >= (year-1900))
676 && (event_te.tm_mon >= (month-1))
677 && (event_te.tm_mday >= day))
679 // are we in the start hour?
680 ((event_tm.tm_mday == day)
681 && (event_tm.tm_hour == hour)
683 // are we an all day event?
684 || ((hour<0)&&(t.is_date))
685 // does it span multible days and we're not at the start day?
687 && (event_tm.tm_mday < day)
688 && (event_te.tm_mday >= day))
691 p = icalcomponent_get_first_property(
693 ICAL_SUMMARY_PROPERTY);
697 wprintf("<table border=1 cellpadding=2><TR>"
698 "<td bgcolor=\"#CCCCCC\">"
702 wprintf("<font size=-1>"
703 "<a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d\">",
704 WC->disp_cal[i].cal_msgnum,
708 icalproperty_get_comment(p));
709 wprintf("</a></font><br />\n");
712 wprintf("</td></tr></table>");
725 * \brief view one day
726 * \param year the year
727 * \param month the month
728 * \param day the day we want to display
730 void calendar_day_view(int year, int month, int day) {
732 struct icaltimetype today, yesterday, tomorrow;
735 char daystart_str[16], dayend_str[16];
740 time_format = get_time_format_cached ();
741 get_preference("daystart", daystart_str, sizeof daystart_str);
742 if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
743 get_preference("dayend", dayend_str, sizeof dayend_str);
744 if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str);
747 /** Figure out the dates for "yesterday" and "tomorrow" links */
749 memset(&today, 0, sizeof(struct icaltimetype));
755 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
757 yesterday = icaltime_normalize(yesterday);
759 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
761 tomorrow = icaltime_normalize(tomorrow);
764 /** Outer table (to get the background color) */
765 wprintf("<div class=\"fix_scrollbar_bug\">"
766 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
767 "bgcolor=#204B78><tr><td>\n");
769 /** Inner table (the real one) */
770 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
771 "bgcolor=#204B78><tr>\n");
773 /** Innermost table (contains hours etc.) */
774 wprintf("<td width=80%%>"
775 "<table width=100%% border=0 cellpadding=1 cellspacing=1 "
776 "bgcolor=#204B78>\n");
778 /** Display events before 8:00 (hour=-1 is all-day events) */
780 "<td bgcolor=\"#CCCCDD\" valign=middle width=10%%></td>"
781 "<td bgcolor=\"#FFFFFF\" valign=top>");
782 for (hour = (-1); hour <= (daystart-1); ++hour) {
783 calendar_day_view_display_events(year, month, day, hour);
785 wprintf("</td></tr>\n");
787 /** Now the middle of the day... */
788 for (hour = daystart; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
789 wprintf("<tr height=30><td bgcolor=\"#CCCCDD\" align=middle "
790 "valign=middle width=10%%>");
791 wprintf("<a href=\"display_edit_event?msgnum=0"
792 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
793 year, month, day, hour
796 if (time_format == WC_TIMEFORMAT_24) {
797 wprintf("%2d:00</a> ", hour);
800 wprintf("%d:00%s</a> ",
801 (hour <= 12 ? hour : hour-12),
802 (hour < 12 ? "am" : "pm")
806 wprintf("</td><td bgcolor=\"#FFFFFF\" valign=top>");
808 /* put the data here, stupid */
809 calendar_day_view_display_events(year, month, day, hour);
811 wprintf("</td></tr>\n");
814 /** Display events after 5:00... */
816 "<td bgcolor=\"#CCCCDD\" valign=middle width=10%%></td>"
817 "<td bgcolor=\"#FFFFFF\" valign=top>");
818 for (hour = (dayend+1); hour <= 23; ++hour) {
819 calendar_day_view_display_events(year, month, day, hour);
821 wprintf("</td></tr>\n");
824 wprintf("</table>" /* end of innermost table */
828 wprintf("<td width=20%% valign=top>"); /* begin stuff-on-the-right */
831 /** Begin todays-date-with-left-and-right-arrows */
832 wprintf("<table border=0 width=100%% "
833 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
837 wprintf("<td align=center>");
838 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
839 yesterday.year, yesterday.month, yesterday.day);
840 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
844 memset(&d_tm, 0, sizeof d_tm);
845 d_tm.tm_year = year - 1900;
846 d_tm.tm_mon = month - 1;
848 wc_strftime(d_str, sizeof d_str,
850 "<font size=+2>%B</font><br />"
851 "<font size=+3>%d</font><br />"
852 "<font size=+2>%Y</font><br />"
856 wprintf("%s", d_str);
859 wprintf("<td align=center>");
860 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
861 tomorrow.year, tomorrow.month, tomorrow.day);
862 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
866 wprintf("</tr></table>\n");
867 /** End todays-date-with-left-and-right-arrows */
869 /** \todo In the future we might want to put a month-o-matic here */
871 wprintf("</font></center>\n");
873 wprintf("</td>"); /** end stuff-on-the-right */
877 wprintf("</tr></table>" /** end of inner table */
878 "</td></tr></table></div>" /** end of outer table */
886 * \brief Display today's events.
888 void calendar_summary_view(void) {
891 struct icaltimetype t;
896 int all_day_event = 0;
897 char timestring[SIZ];
899 if (WC->num_cal == 0) {
904 localtime_r(&now, &today_tm);
906 for (i=0; i<(WC->num_cal); ++i) {
907 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
908 ICAL_DTSTART_PROPERTY);
910 t = icalproperty_get_dtstart(p);
911 event_tt = icaltime_as_timet(t);
918 fmt_time(timestring, event_tt);
921 gmtime_r(&event_tt, &event_tm);
924 localtime_r(&event_tt, &event_tm);
927 if ( (event_tm.tm_year == today_tm.tm_year)
928 && (event_tm.tm_mon == today_tm.tm_mon)
929 && (event_tm.tm_mday == today_tm.tm_mday)
933 p = icalcomponent_get_first_property(
935 ICAL_SUMMARY_PROPERTY);
938 icalproperty_get_comment(p));
939 wprintf(" (%s)<br />\n", timestring);
944 free_calendar_buffer();
949 * \brief clean up ical memory
950 * \todo this could get troubel with future ical versions
952 void free_calendar_buffer(void) {
954 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
955 icalcomponent_free(WC->disp_cal[i].cal);
965 * \brief do the whole calendar page
966 * view any part of the calender. decide which way, etc.
968 void do_calendar_view(void) {
971 int year, month, day;
974 /** In case no date was specified, go with today */
976 localtime_r(&now, &tm);
977 year = tm.tm_year + 1900;
978 month = tm.tm_mon + 1;
981 /** Now see if a date was specified */
982 if (!IsEmptyStr(bstr("year"))) year = atoi(bstr("year"));
983 if (!IsEmptyStr(bstr("month"))) month = atoi(bstr("month"));
984 if (!IsEmptyStr(bstr("day"))) day = atoi(bstr("day"));
986 /** How would you like that cooked? */
987 if (!IsEmptyStr(bstr("calview"))) {
988 strcpy(calview, bstr("calview"));
991 strcpy(calview, "month");
994 /** Display the selected view */
995 if (!strcasecmp(calview, "day")) {
996 calendar_day_view(year, month, day);
998 else if (!strcasecmp(calview, "week")) {
999 calendar_week_view(year, month, day);
1002 if (WC->wc_view == VIEW_CALBRIEF) {
1003 calendar_brief_month_view(year, month, day);
1006 calendar_month_view(year, month, day);
1010 /** Free the calendar stuff */
1011 free_calendar_buffer();
1017 * \brief get task due date
1018 * Helper function for do_tasks_view().
1019 * \param vtodo a task to get the due date
1020 * \return the date/time due.
1022 time_t get_task_due_date(icalcomponent *vtodo) {
1025 if (vtodo == NULL) {
1030 * If we're looking at a fully encapsulated VCALENDAR
1031 * rather than a VTODO component, recurse into the data
1032 * structure until we get a VTODO.
1034 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1035 return get_task_due_date(
1036 icalcomponent_get_first_component(
1037 vtodo, ICAL_VTODO_COMPONENT
1042 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1044 return(icaltime_as_timet(icalproperty_get_due(p)));
1053 * \brief Compare the due dates of two tasks (this is for sorting)
1054 * \param task1 first task to compare
1055 * \param task2 second task to compare
1057 int task_due_cmp(const void *task1, const void *task2) {
1061 t1 = get_task_due_date(((struct disp_cal *)task1)->cal);
1062 t2 = get_task_due_date(((struct disp_cal *)task2)->cal);
1064 if (t1 < t2) return(-1);
1065 if (t1 > t2) return(1);
1073 * \brief do the whole task view stuff
1075 void do_tasks_view(void) {
1082 wprintf("<div class=\"fix_scrollbar_bug\">"
1083 "<table class=\"calendar_view_background\">\n<tr>\n"
1085 wprintf(_("Name of task"));
1086 wprintf("</th><th>");
1087 wprintf(_("Date due"));
1088 wprintf("</th></tr>\n"
1091 /** Sort them if necessary */
1092 if (WC->num_cal > 1) {
1095 sizeof(struct disp_cal),
1100 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1103 wprintf("<tr bgcolor=\"#%s\"><td>",
1104 (bg ? "DDDDDD" : "FFFFFF")
1107 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1108 ICAL_SUMMARY_PROPERTY);
1109 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1110 WC->disp_cal[i].cal_msgnum );
1111 urlescputs(WC->wc_roomname);
1113 wprintf("<img align=middle "
1114 "src=\"static/taskmanag_16x.gif\" border=0> ");
1116 escputs((char *)icalproperty_get_comment(p));
1121 due = get_task_due_date(WC->disp_cal[i].cal);
1122 fmt_date(buf, due, 0);
1123 wprintf("<td><font");
1124 if (due < time(NULL)) {
1125 wprintf(" color=\"#FF0000\"");
1127 wprintf(">%s</font></td></tr>\n", buf);
1130 wprintf("</table></div>\n");
1132 /** Free the list */
1133 free_calendar_buffer();
1137 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */