5 * \defgroup CalHtmlHandles Handles the HTML display of calendar items.
10 #include "webserver.h"
12 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
14 /****************************************************************************/
17 * \brief Display one day of a whole month view of a calendar
18 * \param thetime the month we want to see
20 void calendar_month_view_display_events(time_t thetime) {
23 icalproperty *p = NULL;
24 icalproperty *q = NULL;
25 struct icaltimetype t;
27 int all_day_event = 0;
28 int multi_day_event = 0;
29 int fill_day_event = 0;
33 struct wcsession *WCC;
38 if (WCC->num_cal == 0) {
39 wprintf("<br /><br /><br />\n");
43 localtime_r(&thetime, &today_tm);
44 month = today_tm.tm_mon + 1;
45 day = today_tm.tm_mday;
46 year = today_tm.tm_year + 1900;
48 for (i=0; i<(WCC->num_cal); ++i) {
52 Cal = &WCC->disp_cal[i];
53 all_day_event = Cal->start_hour == -1;
54 show_event = thetime == Cal->start_day;
55 if (Cal->multi_day_event) {
57 // are we in the range of the event?
58 show_event = (Cal->start_day <= thetime) &&
59 (Cal->end_day >= thetime);
61 // are we not start or end day?
62 fill_day_event = (Cal->start_day < thetime) &&
63 (Cal->end_day > thetime);
67 p = icalcomponent_get_first_property(
69 ICAL_SUMMARY_PROPERTY);
73 wprintf("<table border=0 cellpadding=2><TR>"
74 "<td bgcolor=\"#CCCCDD\">"
78 wprintf("<font size=-1>"
79 "<a href=\"display_edit_event?"
80 "msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\""
82 WC->disp_cal[i].cal_msgnum,
89 wprintf("<i>%s</i> ", _("Summary:"));
90 escputs((char *)icalproperty_get_comment(p));
93 q = icalcomponent_get_first_property(
95 ICAL_LOCATION_PROPERTY);
97 wprintf("<i>%s</i> ", _("Location:"));
98 escputs((char *)icalproperty_get_comment(q));
103 * Only show start/end times if we're actually looking at the VEVENT
104 * component. Otherwise it shows bogus dates for e.g. timezones
106 if (icalcomponent_isa(Cal->cal) == ICAL_VEVENT_COMPONENT) {
108 q = icalcomponent_get_first_property(Cal->cal,
109 ICAL_DTSTART_PROPERTY);
111 t = icalproperty_get_dtstart(q);
116 memset(&d_tm, 0, sizeof d_tm);
117 d_tm.tm_year = t.year - 1900;
118 d_tm.tm_mon = t.month - 1;
119 d_tm.tm_mday = t.day;
120 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
121 wprintf("<i>%s</i> %s<br>",
125 tt = icaltime_as_timet(t);
126 fmt_date(buf, tt, 1);
127 wprintf("<i>%s</i> %s<br>",
128 _("Starting date/time:"), buf);
130 /* Embed the 'show end date/time' loop inside here so it
131 * only executes if this is NOT an all day event.
133 q = icalcomponent_get_first_property(Cal->cal,
134 ICAL_DTEND_PROPERTY);
136 t = icalproperty_get_dtend(q);
137 tt = icaltime_as_timet(t);
138 fmt_date(buf, tt, 1);
139 wprintf("<i>%s</i> %s<br>",
140 _("Ending date/time:"), buf);
148 q = icalcomponent_get_first_property(
150 ICAL_DESCRIPTION_PROPERTY);
152 wprintf("<i>%s</i> ", _("Notes:"));
153 escputs((char *)icalproperty_get_comment(q));
159 icalproperty_get_comment(p));
160 wprintf("</a></font><br />\n");
163 wprintf("</td></tr></table>");
176 * \brief Display one day of a whole month view of a calendar
177 * \param thetime the month we want to see
179 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
189 struct icaltimetype t;
190 int month, day, year;
191 int all_day_event = 0;
195 time_format = get_time_format_cached ();
197 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
198 else timeformat="%I:%M %p";
200 localtime_r(&thetime, &today_tm);
201 month = today_tm.tm_mon + 1;
202 day = today_tm.tm_mday;
203 year = today_tm.tm_year + 1900;
205 for (i=0; i<(WC->num_cal); ++i) {
206 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
207 ICAL_DTSTART_PROPERTY);
209 t = icalproperty_get_dtstart(p);
210 event_tt = icaltime_as_timet(t);
212 if (t.is_date) all_day_event = 1;
213 else all_day_event = 0;
216 gmtime_r(&event_tts, &event_tms);
219 localtime_r(&event_tts, &event_tms);
221 /** \todo epoch &! daymask */
222 if ((event_tms.tm_year == today_tm.tm_year)
223 && (event_tms.tm_mon == today_tm.tm_mon)
224 && (event_tms.tm_mday == today_tm.tm_mday)) {
230 p = icalcomponent_get_first_property(
232 ICAL_SUMMARY_PROPERTY);
233 e = icalcomponent_get_first_property(
235 ICAL_DTEND_PROPERTY);
236 if ((p != NULL) && (e != NULL)) {
239 t = icalproperty_get_dtend(e);
240 event_tte = icaltime_as_timet(t);
241 localtime_r(&event_tte, &event_tme);
242 difftime=(event_tte-event_tts)/60;
243 hours=(int)(difftime / 60);
244 minutes=difftime % 60;
245 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
247 "<a href=\"display_edit_event?msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\">",
251 WC->disp_cal[i].cal_msgnum,
259 icalproperty_get_comment(p));
260 /** \todo: allso ammitime format */
261 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
262 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
264 wprintf("</a></font></td>"
265 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
282 * \brief view one month. pretty view
283 * \param year the year
284 * \param month the month
285 * \param day the actual day we want to see
287 void calendar_month_view(int year, int month, int day) {
288 struct tm starting_tm;
292 time_t previous_month;
294 time_t colheader_time;
295 struct tm colheader_tm;
296 char colheader_label[32];
299 /** Determine what day to start.
300 * First, back up to the 1st of the month...
302 memset(&starting_tm, 0, sizeof(struct tm));
304 localtime_r(&WC->disp_cal[0].start_day, &starting_tm);
306 starting_tm.tm_year = year - 1900;
307 starting_tm.tm_mon = month - 1;
308 starting_tm.tm_mday = day;
309 thetime = mktime(&starting_tm);
311 memcpy(&tm, &starting_tm, sizeof(struct tm));
312 while (tm.tm_mday != 1) {
313 thetime = thetime - (time_t)86400; /* go back 24 hours */
314 localtime_r(&thetime, &tm);
317 /** Determine previous and next months ... for links */
318 previous_month = thetime - (time_t)864000L; /* back 10 days */
319 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
321 /** Now back up until we're on a Sunday */
322 localtime_r(&thetime, &tm);
323 while (tm.tm_wday != 0) {
324 thetime = thetime - (time_t)86400; /* go back 24 hours */
325 localtime_r(&thetime, &tm);
328 /** Outer table (to get the background color) */
329 wprintf("<div class=\"fix_scrollbar_bug\">"
330 "<table class=\"calendar\"> \n <tr><td>");
332 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
334 wprintf("<td align=center>");
336 localtime_r(&previous_month, &tm);
337 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
338 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
339 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
341 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
342 wprintf(" "
343 "<font size=+1 color=\"#FFFFFF\">"
346 " ", colheader_label, year);
348 localtime_r(&next_month, &tm);
349 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
350 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
351 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
353 wprintf("</td></tr></table>\n");
355 /** Inner table (the real one) */
356 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
357 "bgcolor=#204B78 id=\"inner_month\"><tr>");
358 colheader_time = thetime;
359 for (i=0; i<7; ++i) {
360 colheader_time = thetime + (i * 86400) ;
361 localtime_r(&colheader_time, &colheader_tm);
362 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
363 wprintf("<td align=center width=14%%>"
364 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
370 /** Now do 35 or 42 days */
371 for (i = 0; i < 42; ++i) {
372 localtime_r(&thetime, &tm);
374 if ((i < 35) || (chg_month == 0)) {
376 if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) {
383 /** Before displaying Sunday, start a new row */
388 wprintf("<td class=\"cal%s\"><div class=\"day\">",
389 ((tm.tm_mon != month-1) ? "out" :
390 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
393 if ((i==0) || (tm.tm_mday == 1)) {
394 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
395 wprintf("%s ", colheader_label);
397 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
404 /** put the data here, stupid */
405 calendar_month_view_display_events(thetime);
409 /** After displaying Saturday, end the row */
416 thetime += (time_t)86400; /** ahead 24 hours */
419 wprintf("</table>" /** end of inner table */
420 "</td></tr></table>" /** end of outer table */
424 * Initialize the bubble tooltips.
426 * Yes, this is as stupid as it looks. Instead of just making the call
427 * to btt_enableTooltips() straight away, we have to create a timer event
428 * and let it initialize as an event after 1 millisecond. This is to
429 * work around a bug in Internet Explorer that causes it to crash if we
430 * manipulate the innerHTML of various DOM nodes while the page is still
431 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
432 * for more information.
434 wprintf("<script type=\"text/javascript\">"
435 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
441 * \brief view one month. brief view
442 * \param year the year
443 * \param month the month
444 * \param day the actual day we want to see
446 void calendar_brief_month_view(int year, int month, int day) {
447 struct tm starting_tm;
451 time_t previous_month;
453 char month_label[32];
455 /** Determine what day to start.
456 * First, back up to the 1st of the month...
458 memset(&starting_tm, 0, sizeof(struct tm));
459 starting_tm.tm_year = year - 1900;
460 starting_tm.tm_mon = month - 1;
461 starting_tm.tm_mday = day;
462 thetime = mktime(&starting_tm);
464 memcpy(&tm, &starting_tm, sizeof(struct tm));
465 while (tm.tm_mday != 1) {
466 thetime = thetime - (time_t)86400; /* go back 24 hours */
467 localtime_r(&thetime, &tm);
470 /** Determine previous and next months ... for links */
471 previous_month = thetime - (time_t)864000L; /* back 10 days */
472 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
474 /** Now back up until we're on a Sunday */
475 localtime_r(&thetime, &tm);
476 while (tm.tm_wday != 0) {
477 thetime = thetime - (time_t)86400; /* go back 24 hours */
478 localtime_r(&thetime, &tm);
481 /** Outer table (to get the background color) */
482 wprintf("<div class=\"fix_scrollbar_bug\">"
483 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
484 "bgcolor=#204B78><TR><TD>\n");
486 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
488 wprintf("<td align=center>");
490 localtime_r(&previous_month, &tm);
491 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
492 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
493 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
495 wc_strftime(month_label, sizeof month_label, "%B", &tm);
496 wprintf(" "
497 "<font size=+1 color=\"#FFFFFF\">"
500 " ", month_label, year);
502 localtime_r(&next_month, &tm);
503 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
504 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
505 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
507 wprintf("</td></tr></table>\n");
509 /** Inner table (the real one) */
510 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
511 "bgcolor=#EEEECC><TR>");
513 wprintf("<tr><td colspan=\"100%\">\n");
515 /** Now do 35 days */
516 for (i = 0; i < 35; ++i) {
517 char weeknumber[255];
518 char weekday_name[32];
520 localtime_r(&thetime, &tm);
523 /** Before displaying Sunday, start a new CELL */
525 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
526 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
527 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
537 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
538 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
542 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
543 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
544 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
546 weekday_name,tm.tm_mday,
549 /** put the data of one day here, stupid */
550 calendar_month_view_brief_events(thetime, daycolor);
553 /** After displaying Saturday, end the row */
555 wprintf("</td></tr></table>\n");
558 thetime += (time_t)86400; /** ahead 24 hours */
561 wprintf("</table>" /** end of inner table */
562 "</td></tr></table>" /** end of outer table */
567 * \brief view one week
568 * this should view just one week, but it's not here yet.
569 * \todo ny implemented
570 * \param year the year
571 * \param month the month
572 * \param day the day which we want to see the week around
574 void calendar_week_view(int year, int month, int day) {
575 wprintf("<center><i>week view FIXME</i></center><br />\n");
580 * \brief display one day
581 * Display events for a particular hour of a particular day.
582 * (Specify hour < 0 to show "all day" events)
583 * \param year the year
584 * \param month the month
586 * \param hour the hour we want to start displaying
587 * \param inner a flag to display between daystart and dayend
588 * (Specify inner to 1 to show inner events)
589 * (Specify inner to 0 to show "all day events and events after dayend)
590 * \param dstart daystart
592 void calendar_day_view_display_events(time_t thetime, int year, int month,
594 int inner, int dstart) {
604 int all_day_event = 0;
605 struct wcsession *WCC;
606 struct disp_cal *Cal;
610 if (WCC->num_cal == 0) {
611 // \todo FIXME wprintf("<br /><br /><br />\n");
615 event_start = thetime + 60 * 60 * hour;
616 event_end = thetime + 60 * 60 * (hour + 1);
618 for (i=0; i<(WCC->num_cal); ++i) {
619 Cal = &WCC->disp_cal[i];
620 all_day_event = Cal->start_hour == -1;
623 if (! all_day_event && inner)
625 show_event = (thetime == Cal->start_day) &&
626 (event_start <= Cal->start_hour) &&
627 ((Cal->end_hour != -1)?
628 (Cal->end_hour < event_end) : 1);
633 show_event = !inner && (Cal->start_day == thetime);
636 p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
637 if ((show_event) && (p != NULL)) {
639 wprintf("<dd><a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
640 Cal->cal_msgnum,year, month, day, hour);
641 escputs((char *) icalproperty_get_comment(p));
642 wprintf("</a></dd>\n");
645 wprintf("<dd class=\"event\" "
646 "style=\"position: absolute; "
647 "top:%dpx; left:100px; "
649 (1 + (event_tm.tm_min / 2) + (event_te.tm_hour - hour) + (hour * 30) - (dstart * 30)),
650 (((event_te.tm_min - event_tm.tm_min) / 2) +(event_te.tm_hour - hour) * 30)
661 wprintf("<a href=\"display_edit_event?"
662 "msgnum=%ld&calview=day&year=%d"
663 "&month=%d&day=%d&hour=%d\""
665 WC->disp_cal[i].cal_msgnum,
666 year, month, day, hour
668 wprintf("<i>%s</i> ", _("Summary:"));
669 escputs((char *)icalproperty_get_comment(p));
672 l = icalcomponent_get_first_property(
674 ICAL_LOCATION_PROPERTY);
676 wprintf("<i>%s</i> ", _("Location:"));
677 escputs((char *)icalproperty_get_comment(l));
680 n = icalcomponent_get_first_property(
682 ICAL_DESCRIPTION_PROPERTY);
684 wprintf("<i>%s</i> ", _("Notes:"));
685 escputs((char *)icalproperty_get_comment(n));
690 icalproperty_get_comment(p));
691 wprintf("</a></dd>\n");
699 /* TODO: whats that? thierry, when do we need to show this?
700 wprintf("<a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
701 WC->disp_cal[i].cal_msgnum,
702 year, month, day, hour
705 icalproperty_get_comment(p));
706 wprintf("</a></dd>\n");
715 * \brief view one day
716 * \param year the year
717 * \param month the month
718 * \param day the day we want to display
720 void calendar_day_view(int year, int month, int day) {
722 struct icaltimetype today, yesterday, tomorrow;
725 char daystart_str[16], dayend_str[16];
731 time_format = get_time_format_cached ();
732 get_preference("daystart", daystart_str, sizeof daystart_str);
733 if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
734 get_preference("dayend", dayend_str, sizeof dayend_str);
735 if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str);
738 memset(&d_tm, 0, sizeof d_tm);
740 localtime_r(&WC->disp_cal[0].start_day, &d_tm);
742 d_tm.tm_year = year - 1900;
743 d_tm.tm_mon = month - 1;
745 today_t = mktime(&d_tm);
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);
763 wprintf("<div class=\"fix_scrollbar_bug\">");
765 /** Inner table (the real one) */
766 wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
768 /** Innermost cell (contains hours etc.) */
769 wprintf("<td class=\"middle_of_the_day\" >");
774 " position: absolute ; "
778 " clip: rect(0px 500px %dpx 0px);"
779 " clip: rect(0px, 500px, %dpx, 0px);"
781 (dayend - daystart) * 30,
782 (dayend - daystart) * 30
784 /** Now the middle of the day... */
785 for (hour = 0; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
786 if (hour >= daystart) {
787 wprintf("<dt><a href=\"display_edit_event?msgnum=0"
788 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
789 year, month, day, hour
792 if (time_format == WC_TIMEFORMAT_24) {
793 wprintf("%2d:00</a> ", hour);
796 wprintf("%d:00%s</a> ",
797 (hour <= 12 ? hour : hour-12),
798 (hour < 12 ? "am" : "pm")
805 /* put the data here, stupid */
806 calendar_day_view_display_events(today_t, year, month, day, hour, 1 , daystart);
811 wprintf("</td>"); /* end of innermost table */
813 /** Extra events on the middle */
814 wprintf("<td class=\"extra_events\">");
818 /** Display all-day events) */
819 wprintf("<dt>All day events</dt>");
820 calendar_day_view_display_events(today_t, year, month, day, -1, 0 , daystart);
822 /** Display events before daystart */
823 wprintf("<dt>Before day start</dt>");
824 for (hour = 0; hour <= (daystart-1); ++hour) {
825 calendar_day_view_display_events(today_t, year, month, day, hour, 0, daystart );
828 /** Display events after dayend... */
829 wprintf("<dt>After</dt>");
830 for (hour = (dayend+1); hour <= 23; ++hour) {
831 calendar_day_view_display_events(today_t, year, month, day, hour, 0, daystart );
836 wprintf("</td>"); /** end extra on the middle */
838 wprintf("<td width=20%% valign=top>"); /** begin stuff-on-the-right */
840 /** Begin todays-date-with-left-and-right-arrows */
841 wprintf("<table border=0 width=100%% "
842 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
846 wprintf("<td align=center>");
847 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
848 yesterday.year, yesterday.month, yesterday.day);
849 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
852 wc_strftime(d_str, sizeof d_str,
854 "<font size=+2>%B</font><br />"
855 "<font size=+3>%d</font><br />"
856 "<font size=+2>%Y</font><br />"
860 wprintf("%s", d_str);
863 wprintf("<td align=center>");
864 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
865 tomorrow.year, tomorrow.month, tomorrow.day);
866 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
870 wprintf("</tr></table>\n");
871 /** End todays-date-with-left-and-right-arrows */
873 /** \todo In the future we might want to put a month-o-matic here */
875 wprintf("</font></center>\n");
877 wprintf("</td></tr>"); /** end stuff-on-the-right */
879 wprintf("</table>" /** end of inner table */
882 wprintf("<script type=\"text/javascript\">"
883 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); "
890 * \brief Display today's events.
892 void calendar_summary_view(void) {
895 struct icaltimetype t;
900 int all_day_event = 0;
901 char timestring[SIZ];
903 if (WC->num_cal == 0) {
908 localtime_r(&now, &today_tm);
910 for (i=0; i<(WC->num_cal); ++i) {
911 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
912 ICAL_DTSTART_PROPERTY);
914 t = icalproperty_get_dtstart(p);
915 event_tt = icaltime_as_timet(t);
922 fmt_time(timestring, event_tt);
925 gmtime_r(&event_tt, &event_tm);
928 localtime_r(&event_tt, &event_tm);
931 if ( (event_tm.tm_year == today_tm.tm_year)
932 && (event_tm.tm_mon == today_tm.tm_mon)
933 && (event_tm.tm_mday == today_tm.tm_mday)
937 p = icalcomponent_get_first_property(
939 ICAL_SUMMARY_PROPERTY);
942 icalproperty_get_comment(p));
943 wprintf(" (%s)<br />\n", timestring);
948 free_calendar_buffer();
953 * \brief clean up ical memory
954 * \todo this could get troubel with future ical versions
956 void free_calendar_buffer(void) {
958 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
959 icalcomponent_free(WC->disp_cal[i].cal);
969 * \brief do the whole calendar page
970 * view any part of the calender. decide which way, etc.
972 void do_calendar_view(void) {
975 int year, month, day;
978 /** In case no date was specified, go with today */
980 localtime_r(&now, &tm);
981 year = tm.tm_year + 1900;
982 month = tm.tm_mon + 1;
985 /** Now see if a date was specified */
986 if (!IsEmptyStr(bstr("year"))) year = atoi(bstr("year"));
987 if (!IsEmptyStr(bstr("month"))) month = atoi(bstr("month"));
988 if (!IsEmptyStr(bstr("day"))) day = atoi(bstr("day"));
990 /** How would you like that cooked? */
991 if (!IsEmptyStr(bstr("calview"))) {
992 strcpy(calview, bstr("calview"));
995 strcpy(calview, "month");
998 /** Display the selected view */
999 if (!strcasecmp(calview, "day")) {
1000 calendar_day_view(year, month, day);
1002 else if (!strcasecmp(calview, "week")) {
1003 calendar_week_view(year, month, day);
1006 if (WC->wc_view == VIEW_CALBRIEF) {
1007 calendar_brief_month_view(year, month, day);
1010 calendar_month_view(year, month, day);
1014 /** Free the calendar stuff */
1015 free_calendar_buffer();
1021 * \brief get task due date
1022 * Helper function for do_tasks_view().
1023 * \param vtodo a task to get the due date
1024 * \return the date/time due.
1026 time_t get_task_due_date(icalcomponent *vtodo) {
1029 if (vtodo == NULL) {
1034 * If we're looking at a fully encapsulated VCALENDAR
1035 * rather than a VTODO component, recurse into the data
1036 * structure until we get a VTODO.
1038 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1039 return get_task_due_date(
1040 icalcomponent_get_first_component(
1041 vtodo, ICAL_VTODO_COMPONENT
1046 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1048 return(icaltime_as_timet(icalproperty_get_due(p)));
1057 * \brief Compare the due dates of two tasks (this is for sorting)
1058 * \param task1 first task to compare
1059 * \param task2 second task to compare
1061 int task_due_cmp(const void *task1, const void *task2) {
1065 t1 = get_task_due_date(((struct disp_cal *)task1)->cal);
1066 t2 = get_task_due_date(((struct disp_cal *)task2)->cal);
1068 if (t1 < t2) return(-1);
1069 if (t1 > t2) return(1);
1077 * \brief do the whole task view stuff
1079 void do_tasks_view(void) {
1086 wprintf("<div class=\"fix_scrollbar_bug\">"
1087 "<table class=\"calendar_view_background\">\n<tr>\n"
1089 wprintf(_("Name of task"));
1090 wprintf("</th><th>");
1091 wprintf(_("Date due"));
1092 wprintf("</th></tr>\n"
1095 /** Sort them if necessary */
1096 if (WC->num_cal > 1) {
1099 sizeof(struct disp_cal),
1104 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1107 wprintf("<tr bgcolor=\"#%s\"><td>",
1108 (bg ? "DDDDDD" : "FFFFFF")
1111 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1112 ICAL_SUMMARY_PROPERTY);
1113 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1114 WC->disp_cal[i].cal_msgnum );
1115 urlescputs(WC->wc_roomname);
1117 wprintf("<img align=middle "
1118 "src=\"static/taskmanag_16x.gif\" border=0> ");
1120 escputs((char *)icalproperty_get_comment(p));
1125 due = get_task_due_date(WC->disp_cal[i].cal);
1126 fmt_date(buf, due, 0);
1127 wprintf("<td><font");
1128 if (due < time(NULL)) {
1129 wprintf(" color=\"#FF0000\"");
1131 wprintf(">%s</font></td></tr>\n", buf);
1134 wprintf("</table></div>\n");
1136 /** Free the list */
1137 free_calendar_buffer();
1141 #else /* WEBCIT_WITH_CALENDAR_SERVICE */
1143 /**\brief stub for non-libical builds */
1144 void do_calendar_view(void) {
1145 wprintf("<center><i>");
1146 wprintf(_("The calendar view is not available."));
1147 wprintf("</i></center><br />\n");
1150 /**\brief stub for non-libical builds */
1151 void do_tasks_view(void) {
1152 wprintf("<center><I>");
1153 wprintf(_("The tasks view is not available."));
1154 wprintf("</i></center><br />\n");
1158 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */