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;
34 struct wcsession *WCC;
39 if (WCC->num_cal == 0) {
40 wprintf("<br /><br /><br />\n");
44 localtime_r(&thetime, &today_tm);
45 month = today_tm.tm_mon + 1;
46 day = today_tm.tm_mday;
47 year = today_tm.tm_year + 1900;
48 dst_day = thetime - 3600;
49 for (i=0; i<(WCC->num_cal); ++i) {
53 Cal = &WCC->disp_cal[i];
54 all_day_event = Cal->start_hour == -1;
55 // lprintf(1,"Date: %d %d %d %d\n", thetime, Cal->start_day, day, thetime - Cal->start_day);
58 // are we in the range of the event?
59 show_event = (Cal->start_day <= thetime) &&
60 (Cal->end_day >= thetime);
62 // are we in the range of the event?
63 show_event = (Cal->start_day <= dst_day) &&
64 (Cal->end_day >= dst_day);
66 // are we not start or end day?
67 fill_day_event = (Cal->start_day < thetime) &&
68 (Cal->end_day > thetime);
72 show_event = (thetime == Cal->start_day) || (dst_day == Cal->start_day);
75 p = icalcomponent_get_first_property(
77 ICAL_SUMMARY_PROPERTY);
81 wprintf("<table border=0 cellpadding=2><TR>"
82 "<td bgcolor=\"#CCCCDD\">"
86 wprintf("<font size=-1>"
87 "<a href=\"display_edit_event?"
88 "msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\""
90 WC->disp_cal[i].cal_msgnum,
97 wprintf("<i>%s</i> ", _("Summary:"));
98 escputs((char *)icalproperty_get_comment(p));
101 q = icalcomponent_get_first_property(
103 ICAL_LOCATION_PROPERTY);
105 wprintf("<i>%s</i> ", _("Location:"));
106 escputs((char *)icalproperty_get_comment(q));
111 * Only show start/end times if we're actually looking at the VEVENT
112 * component. Otherwise it shows bogus dates for e.g. timezones
114 if (icalcomponent_isa(Cal->cal) == ICAL_VEVENT_COMPONENT) {
116 q = icalcomponent_get_first_property(Cal->cal,
117 ICAL_DTSTART_PROPERTY);
119 t = icalproperty_get_dtstart(q);
124 memset(&d_tm, 0, sizeof d_tm);
125 d_tm.tm_year = t.year - 1900;
126 d_tm.tm_mon = t.month - 1;
127 d_tm.tm_mday = t.day;
128 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
129 wprintf("<i>%s</i> %s<br>",
133 tt = icaltime_as_timet(t);
134 fmt_date(buf, tt, 1);
135 wprintf("<i>%s</i> %s<br>",
136 _("Starting date/time:"), buf);
138 /* Embed the 'show end date/time' loop inside here so it
139 * only executes if this is NOT an all day event.
141 q = icalcomponent_get_first_property(Cal->cal,
142 ICAL_DTEND_PROPERTY);
144 t = icalproperty_get_dtend(q);
145 tt = icaltime_as_timet(t);
146 fmt_date(buf, tt, 1);
147 wprintf("<i>%s</i> %s<br>",
148 _("Ending date/time:"), buf);
156 q = icalcomponent_get_first_property(
158 ICAL_DESCRIPTION_PROPERTY);
160 wprintf("<i>%s</i> ", _("Notes:"));
161 escputs((char *)icalproperty_get_comment(q));
167 icalproperty_get_comment(p));
168 wprintf("</a></font><br />\n");
171 wprintf("</td></tr></table>");
184 * \brief Display one day of a whole month view of a calendar
185 * \param thetime the month we want to see
187 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
197 struct icaltimetype t;
198 int month, day, year;
199 int all_day_event = 0;
203 time_format = get_time_format_cached ();
205 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
206 else timeformat="%I:%M %p";
208 localtime_r(&thetime, &today_tm);
209 month = today_tm.tm_mon + 1;
210 day = today_tm.tm_mday;
211 year = today_tm.tm_year + 1900;
213 for (i=0; i<(WC->num_cal); ++i) {
214 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
215 ICAL_DTSTART_PROPERTY);
217 t = icalproperty_get_dtstart(p);
218 event_tt = icaltime_as_timet(t);
220 if (t.is_date) all_day_event = 1;
221 else all_day_event = 0;
224 gmtime_r(&event_tts, &event_tms);
227 localtime_r(&event_tts, &event_tms);
229 /** \todo epoch &! daymask */
230 if ((event_tms.tm_year == today_tm.tm_year)
231 && (event_tms.tm_mon == today_tm.tm_mon)
232 && (event_tms.tm_mday == today_tm.tm_mday)) {
238 p = icalcomponent_get_first_property(
240 ICAL_SUMMARY_PROPERTY);
241 e = icalcomponent_get_first_property(
243 ICAL_DTEND_PROPERTY);
244 if ((p != NULL) && (e != NULL)) {
247 t = icalproperty_get_dtend(e);
248 event_tte = icaltime_as_timet(t);
249 localtime_r(&event_tte, &event_tme);
250 difftime=(event_tte-event_tts)/60;
251 hours=(int)(difftime / 60);
252 minutes=difftime % 60;
253 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
255 "<a href=\"display_edit_event?msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\">",
259 WC->disp_cal[i].cal_msgnum,
267 icalproperty_get_comment(p));
268 /** \todo: allso ammitime format */
269 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
270 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
272 wprintf("</a></font></td>"
273 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
290 * \brief view one month. pretty view
291 * \param year the year
292 * \param month the month
293 * \param day the actual day we want to see
295 void calendar_month_view(int year, int month, int day) {
296 struct tm starting_tm;
300 time_t previous_month;
302 time_t colheader_time;
303 struct tm colheader_tm;
304 char colheader_label[32];
307 char weekstart_buf[16];
309 /* Determine what day to start.
311 get_preference("weekstart", weekstart_buf, sizeof weekstart_buf);
312 weekstart = atoi(weekstart_buf);
315 * Now back up to the 1st of the month...
317 memset(&starting_tm, 0, sizeof(struct tm));
319 starting_tm.tm_year = year - 1900;
320 starting_tm.tm_mon = month - 1;
321 starting_tm.tm_mday = day;
322 thetime = mktime(&starting_tm);
324 memcpy(&tm, &starting_tm, sizeof(struct tm));
325 while (tm.tm_mday != 1) {
326 thetime = thetime - (time_t)86400; /* go back 24 hours */
327 localtime_r(&thetime, &tm);
330 /** Determine previous and next months ... for links */
331 previous_month = thetime - (time_t)864000L; /* back 10 days */
332 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
334 /** Now back up until we're on the user's preferred start day */
335 localtime_r(&thetime, &tm);
336 while (tm.tm_wday != weekstart) {
337 thetime = thetime - (time_t)86400; /* go back 24 hours */
338 localtime_r(&thetime, &tm);
341 /** Outer table (to get the background color) */
342 wprintf("<div class=\"fix_scrollbar_bug\">"
343 "<table class=\"calendar\"> \n <tr><td>");
345 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
347 wprintf("<td align=center>");
349 localtime_r(&previous_month, &tm);
350 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
351 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
352 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
354 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
355 wprintf(" "
356 "<font size=+1 color=\"#FFFFFF\">"
359 " ", colheader_label, year);
361 localtime_r(&next_month, &tm);
362 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
363 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
364 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
366 wprintf("</td></tr></table>\n");
368 /** Inner table (the real one) */
369 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
370 "bgcolor=#204B78 id=\"inner_month\"><tr>");
371 colheader_time = thetime;
372 for (i=0; i<7; ++i) {
373 colheader_time = thetime + (i * 86400) ;
374 localtime_r(&colheader_time, &colheader_tm);
375 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
376 wprintf("<td align=center width=14%%>"
377 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
383 /** Now do 35 or 42 days */
384 for (i = 0; i < 42; ++i) {
385 localtime_r(&thetime, &tm);
387 if ((i < 35) || (chg_month == 0)) {
389 if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) {
396 /** Before displaying Sunday, start a new row */
401 wprintf("<td class=\"cal%s\"><div class=\"day\">",
402 ((tm.tm_mon != month-1) ? "out" :
403 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
406 if ((i==0) || (tm.tm_mday == 1)) {
407 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
408 wprintf("%s ", colheader_label);
410 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
417 /** put the data here, stupid */
418 calendar_month_view_display_events(thetime);
422 /** After displaying Saturday, end the row */
429 thetime += (time_t)86400; /** ahead 24 hours */
432 wprintf("</table>" /** end of inner table */
433 "</td></tr></table>" /** end of outer table */
437 * Initialize the bubble tooltips.
439 * Yes, this is as stupid as it looks. Instead of just making the call
440 * to btt_enableTooltips() straight away, we have to create a timer event
441 * and let it initialize as an event after 1 millisecond. This is to
442 * work around a bug in Internet Explorer that causes it to crash if we
443 * manipulate the innerHTML of various DOM nodes while the page is still
444 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
445 * for more information.
447 wprintf("<script type=\"text/javascript\">"
448 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
454 * \brief view one month. brief view
455 * \param year the year
456 * \param month the month
457 * \param day the actual day we want to see
459 void calendar_brief_month_view(int year, int month, int day) {
460 struct tm starting_tm;
464 time_t previous_month;
466 char month_label[32];
468 /** Determine what day to start.
469 * First, back up to the 1st of the month...
471 memset(&starting_tm, 0, sizeof(struct tm));
472 starting_tm.tm_year = year - 1900;
473 starting_tm.tm_mon = month - 1;
474 starting_tm.tm_mday = day;
475 thetime = mktime(&starting_tm);
477 memcpy(&tm, &starting_tm, sizeof(struct tm));
478 while (tm.tm_mday != 1) {
479 thetime = thetime - (time_t)86400; /* go back 24 hours */
480 localtime_r(&thetime, &tm);
483 /** Determine previous and next months ... for links */
484 previous_month = thetime - (time_t)864000L; /* back 10 days */
485 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
487 /** Now back up until we're on a Sunday */
488 localtime_r(&thetime, &tm);
489 while (tm.tm_wday != 0) {
490 thetime = thetime - (time_t)86400; /* go back 24 hours */
491 localtime_r(&thetime, &tm);
494 /** Outer table (to get the background color) */
495 wprintf("<div class=\"fix_scrollbar_bug\">"
496 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
497 "bgcolor=#204B78><TR><TD>\n");
499 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
501 wprintf("<td align=center>");
503 localtime_r(&previous_month, &tm);
504 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
505 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
506 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
508 wc_strftime(month_label, sizeof month_label, "%B", &tm);
509 wprintf(" "
510 "<font size=+1 color=\"#FFFFFF\">"
513 " ", month_label, year);
515 localtime_r(&next_month, &tm);
516 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
517 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
518 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
520 wprintf("</td></tr></table>\n");
522 /** Inner table (the real one) */
523 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
524 "bgcolor=#EEEECC><TR>");
526 wprintf("<tr><td colspan=\"100%\">\n");
528 /** Now do 35 days */
529 for (i = 0; i < 35; ++i) {
530 char weeknumber[255];
531 char weekday_name[32];
533 localtime_r(&thetime, &tm);
536 /** Before displaying Sunday, start a new CELL */
538 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
539 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
540 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
550 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
551 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
555 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
556 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
557 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
559 weekday_name,tm.tm_mday,
562 /** put the data of one day here, stupid */
563 calendar_month_view_brief_events(thetime, daycolor);
566 /** After displaying Saturday, end the row */
568 wprintf("</td></tr></table>\n");
571 thetime += (time_t)86400; /** ahead 24 hours */
574 wprintf("</table>" /** end of inner table */
575 "</td></tr></table>" /** end of outer table */
580 * \brief view one week
581 * this should view just one week, but it's not here yet.
582 * \todo ny implemented
583 * \param year the year
584 * \param month the month
585 * \param day the day which we want to see the week around
587 void calendar_week_view(int year, int month, int day) {
588 wprintf("<center><i>week view FIXME</i></center><br />\n");
593 * \brief display one day
594 * Display events for a particular hour of a particular day.
595 * (Specify hour < 0 to show "all day" events)
596 * \param year the year
597 * \param month the month
599 * \param hour the hour we want to start displaying
600 * \param inner a flag to display between daystart and dayend
601 * (Specify inner to 1 to show inner events)
602 * (Specify inner to 0 to show "all day events and events after dayend)
603 * \param dstart daystart
605 void calendar_day_view_display_events(time_t thetime, int year, int month,
607 int inner, int dstart) {
617 int all_day_event = 0;
618 struct wcsession *WCC;
619 struct disp_cal *Cal;
623 if (WCC->num_cal == 0) {
624 // \todo FIXME wprintf("<br /><br /><br />\n");
628 event_start = thetime + 60 * 60 * hour;
629 event_end = thetime + 60 * 60 * (hour + 1);
631 for (i=0; i<(WCC->num_cal); ++i) {
632 Cal = &WCC->disp_cal[i];
633 all_day_event = Cal->start_hour == -1;
636 if (! all_day_event && inner)
638 show_event = (thetime == Cal->start_day) &&
639 (event_start <= Cal->start_hour) &&
640 ((Cal->end_hour != -1)?
641 (Cal->end_hour < event_end) : 1);
646 show_event = !inner && (Cal->start_day == thetime);
649 p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
650 if ((show_event) && (p != NULL)) {
652 wprintf("<dd><a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
653 Cal->cal_msgnum,year, month, day, hour);
654 escputs((char *) icalproperty_get_comment(p));
655 wprintf("</a></dd>\n");
658 wprintf("<dd class=\"event\" "
659 "style=\"position: absolute; "
660 "top:%dpx; left:100px; "
662 (1 + (event_tm.tm_min / 2) + (event_te.tm_hour - hour) + (hour * 30) - (dstart * 30)),
663 (((event_te.tm_min - event_tm.tm_min) / 2) +(event_te.tm_hour - hour) * 30)
674 wprintf("<a href=\"display_edit_event?"
675 "msgnum=%ld&calview=day&year=%d"
676 "&month=%d&day=%d&hour=%d\""
678 WC->disp_cal[i].cal_msgnum,
679 year, month, day, hour
681 wprintf("<i>%s</i> ", _("Summary:"));
682 escputs((char *)icalproperty_get_comment(p));
685 l = icalcomponent_get_first_property(
687 ICAL_LOCATION_PROPERTY);
689 wprintf("<i>%s</i> ", _("Location:"));
690 escputs((char *)icalproperty_get_comment(l));
693 n = icalcomponent_get_first_property(
695 ICAL_DESCRIPTION_PROPERTY);
697 wprintf("<i>%s</i> ", _("Notes:"));
698 escputs((char *)icalproperty_get_comment(n));
703 icalproperty_get_comment(p));
704 wprintf("</a></dd>\n");
712 /* TODO: whats that? thierry, when do we need to show this?
713 wprintf("<a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
714 WC->disp_cal[i].cal_msgnum,
715 year, month, day, hour
718 icalproperty_get_comment(p));
719 wprintf("</a></dd>\n");
728 * \brief view one day
729 * \param year the year
730 * \param month the month
731 * \param day the day we want to display
733 void calendar_day_view(int year, int month, int day) {
735 struct icaltimetype today, yesterday, tomorrow;
738 char daystart_str[16], dayend_str[16];
744 time_format = get_time_format_cached ();
745 get_preference("daystart", daystart_str, sizeof daystart_str);
746 if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
747 get_preference("dayend", dayend_str, sizeof dayend_str);
748 if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str);
751 memset(&d_tm, 0, sizeof d_tm);
753 localtime_r(&WC->disp_cal[0].start_day, &d_tm);
755 d_tm.tm_year = year - 1900;
756 d_tm.tm_mon = month - 1;
758 today_t = mktime(&d_tm);
760 /** Figure out the dates for "yesterday" and "tomorrow" links */
762 memset(&today, 0, sizeof(struct icaltimetype));
768 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
770 yesterday = icaltime_normalize(yesterday);
772 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
774 tomorrow = icaltime_normalize(tomorrow);
776 wprintf("<div class=\"fix_scrollbar_bug\">");
778 /** Inner table (the real one) */
779 wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
781 /** Innermost cell (contains hours etc.) */
782 wprintf("<td class=\"middle_of_the_day\" >");
787 " position: absolute ; "
791 " clip: rect(0px 500px %dpx 0px);"
792 " clip: rect(0px, 500px, %dpx, 0px);"
794 (dayend - daystart) * 30,
795 (dayend - daystart) * 30
797 /** Now the middle of the day... */
798 for (hour = 0; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
799 if (hour >= daystart) {
800 wprintf("<dt><a href=\"display_edit_event?msgnum=0"
801 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
802 year, month, day, hour
805 if (time_format == WC_TIMEFORMAT_24) {
806 wprintf("%2d:00</a> ", hour);
809 wprintf("%d:00%s</a> ",
810 (hour <= 12 ? hour : hour-12),
811 (hour < 12 ? "am" : "pm")
818 /* put the data here, stupid */
819 calendar_day_view_display_events(today_t, year, month, day, hour, 1 , daystart);
824 wprintf("</td>"); /* end of innermost table */
826 /** Extra events on the middle */
827 wprintf("<td class=\"extra_events\">");
831 /** Display all-day events) */
832 wprintf("<dt>All day events</dt>");
833 calendar_day_view_display_events(today_t, year, month, day, -1, 0 , daystart);
835 /** Display events before daystart */
836 wprintf("<dt>Before day start</dt>");
837 for (hour = 0; hour <= (daystart-1); ++hour) {
838 calendar_day_view_display_events(today_t, year, month, day, hour, 0, daystart );
841 /** Display events after dayend... */
842 wprintf("<dt>After</dt>");
843 for (hour = (dayend+1); hour <= 23; ++hour) {
844 calendar_day_view_display_events(today_t, year, month, day, hour, 0, daystart );
849 wprintf("</td>"); /** end extra on the middle */
851 wprintf("<td width=20%% valign=top>"); /** begin stuff-on-the-right */
853 /** Begin todays-date-with-left-and-right-arrows */
854 wprintf("<table border=0 width=100%% "
855 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
859 wprintf("<td align=center>");
860 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
861 yesterday.year, yesterday.month, yesterday.day);
862 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
865 wc_strftime(d_str, sizeof d_str,
867 "<font size=+2>%B</font><br />"
868 "<font size=+3>%d</font><br />"
869 "<font size=+2>%Y</font><br />"
873 wprintf("%s", d_str);
876 wprintf("<td align=center>");
877 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
878 tomorrow.year, tomorrow.month, tomorrow.day);
879 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
883 wprintf("</tr></table>\n");
884 /** End todays-date-with-left-and-right-arrows */
886 /** \todo In the future we might want to put a month-o-matic here */
888 wprintf("</font></center>\n");
890 wprintf("</td></tr>"); /** end stuff-on-the-right */
892 wprintf("</table>" /** end of inner table */
895 wprintf("<script type=\"text/javascript\">"
896 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); "
903 * \brief Display today's events.
905 void calendar_summary_view(void) {
908 struct icaltimetype t;
913 int all_day_event = 0;
914 char timestring[SIZ];
916 if (WC->num_cal == 0) {
921 localtime_r(&now, &today_tm);
923 for (i=0; i<(WC->num_cal); ++i) {
924 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
925 ICAL_DTSTART_PROPERTY);
927 t = icalproperty_get_dtstart(p);
928 event_tt = icaltime_as_timet(t);
935 fmt_time(timestring, event_tt);
938 gmtime_r(&event_tt, &event_tm);
941 localtime_r(&event_tt, &event_tm);
944 if ( (event_tm.tm_year == today_tm.tm_year)
945 && (event_tm.tm_mon == today_tm.tm_mon)
946 && (event_tm.tm_mday == today_tm.tm_mday)
950 p = icalcomponent_get_first_property(
952 ICAL_SUMMARY_PROPERTY);
955 icalproperty_get_comment(p));
956 wprintf(" (%s)<br />\n", timestring);
961 free_calendar_buffer();
966 * \brief clean up ical memory
967 * \todo this could get troubel with future ical versions
969 void free_calendar_buffer(void) {
971 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
972 icalcomponent_free(WC->disp_cal[i].cal);
982 * \brief do the whole calendar page
983 * view any part of the calender. decide which way, etc.
985 void do_calendar_view(void) {
988 int year, month, day;
991 /** In case no date was specified, go with today */
993 localtime_r(&now, &tm);
994 year = tm.tm_year + 1900;
995 month = tm.tm_mon + 1;
998 /** Now see if a date was specified */
999 if (!IsEmptyStr(bstr("year"))) year = atoi(bstr("year"));
1000 if (!IsEmptyStr(bstr("month"))) month = atoi(bstr("month"));
1001 if (!IsEmptyStr(bstr("day"))) day = atoi(bstr("day"));
1003 /** How would you like that cooked? */
1004 if (!IsEmptyStr(bstr("calview"))) {
1005 strcpy(calview, bstr("calview"));
1008 strcpy(calview, "month");
1011 /** Display the selected view */
1012 if (!strcasecmp(calview, "day")) {
1013 calendar_day_view(year, month, day);
1015 else if (!strcasecmp(calview, "week")) {
1016 calendar_week_view(year, month, day);
1019 if (WC->wc_view == VIEW_CALBRIEF) {
1020 calendar_brief_month_view(year, month, day);
1023 calendar_month_view(year, month, day);
1027 /** Free the calendar stuff */
1028 free_calendar_buffer();
1034 * \brief get task due date
1035 * Helper function for do_tasks_view().
1036 * \param vtodo a task to get the due date
1037 * \return the date/time due.
1039 time_t get_task_due_date(icalcomponent *vtodo) {
1042 if (vtodo == NULL) {
1047 * If we're looking at a fully encapsulated VCALENDAR
1048 * rather than a VTODO component, recurse into the data
1049 * structure until we get a VTODO.
1051 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1052 return get_task_due_date(
1053 icalcomponent_get_first_component(
1054 vtodo, ICAL_VTODO_COMPONENT
1059 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1061 return(icaltime_as_timet(icalproperty_get_due(p)));
1070 * \brief Compare the due dates of two tasks (this is for sorting)
1071 * \param task1 first task to compare
1072 * \param task2 second task to compare
1074 int task_due_cmp(const void *task1, const void *task2) {
1078 t1 = get_task_due_date(((struct disp_cal *)task1)->cal);
1079 t2 = get_task_due_date(((struct disp_cal *)task2)->cal);
1081 if (t1 < t2) return(-1);
1082 if (t1 > t2) return(1);
1090 * \brief do the whole task view stuff
1092 void do_tasks_view(void) {
1099 wprintf("<div class=\"fix_scrollbar_bug\">"
1100 "<table class=\"calendar_view_background\">\n<tr>\n"
1102 wprintf(_("Name of task"));
1103 wprintf("</th><th>");
1104 wprintf(_("Date due"));
1105 wprintf("</th></tr>\n"
1108 /** Sort them if necessary */
1109 if (WC->num_cal > 1) {
1112 sizeof(struct disp_cal),
1117 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1120 wprintf("<tr bgcolor=\"#%s\"><td>",
1121 (bg ? "DDDDDD" : "FFFFFF")
1124 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1125 ICAL_SUMMARY_PROPERTY);
1126 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1127 WC->disp_cal[i].cal_msgnum );
1128 urlescputs(WC->wc_roomname);
1130 wprintf("<img align=middle "
1131 "src=\"static/taskmanag_16x.gif\" border=0> ");
1133 escputs((char *)icalproperty_get_comment(p));
1138 due = get_task_due_date(WC->disp_cal[i].cal);
1139 fmt_date(buf, due, 0);
1140 wprintf("<td><font");
1141 if (due < time(NULL)) {
1142 wprintf(" color=\"#FF0000\"");
1144 wprintf(">%s</font></td></tr>\n", buf);
1147 wprintf("</table></div>\n");
1149 /** Free the list */
1150 free_calendar_buffer();
1154 #else /* WEBCIT_WITH_CALENDAR_SERVICE */
1156 /**\brief stub for non-libical builds */
1157 void do_calendar_view(void) {
1158 wprintf("<center><i>");
1159 wprintf(_("The calendar view is not available."));
1160 wprintf("</i></center><br />\n");
1163 /**\brief stub for non-libical builds */
1164 void do_tasks_view(void) {
1165 wprintf("<center><I>");
1166 wprintf(_("The tasks view is not available."));
1167 wprintf("</i></center><br />\n");
1171 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */