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 time_t event_tt_stripped;
27 icalproperty *p = NULL;
28 icalproperty *pe = NULL;
29 icalproperty *q = NULL;
30 struct icaltimetype t;
32 int all_day_event = 0;
33 int multi_day_event = 0;
34 int fill_day_event = 0;
39 if (WC->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;
49 for (i=0; i<(WC->num_cal); ++i) {
52 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
53 ICAL_DTSTART_PROPERTY);
54 pe = icalcomponent_get_first_property(WC->disp_cal[i].cal,
57 t = icalproperty_get_dtstart(p);
58 event_tt = icaltime_as_timet(t);
59 if (t.is_date) all_day_event = 1;
60 else all_day_event = 0;
63 gmtime_r(&event_tt, &event_tm);
68 event_tt_stripped = mktime (&event_tm);
69 show_event = thetime == event_tt_stripped;
72 localtime_r(&event_tt, &event_tm);
73 // we're not interested in the hours.
74 // we just want the date for easy comparison.
77 event_tt_stripped = mktime (&event_tm);
78 if (pe != NULL) // do we have a span?
81 time_t event_end_stripped;
83 t = icalproperty_get_dtend(pe);
84 event_tte = icaltime_as_timet(t);
85 gmtime_r(&event_tte, &event_ttm);
88 event_ttm.tm_hour = 0;
89 event_end_stripped = mktime(&event_ttm);
91 // do we span ore than one day?
92 multi_day_event = event_tt_stripped != event_end_stripped;
94 // are we in the range of the event?
95 show_event = ((event_tt_stripped <= thetime) &&
96 (event_end_stripped >= thetime));
98 // are we not start or end day?
99 fill_day_event = ((event_tt_stripped < thetime) &&
100 (event_end_stripped > thetime));
104 show_event = event_tt_stripped == thetime;
109 p = icalcomponent_get_first_property(
111 ICAL_SUMMARY_PROPERTY);
115 wprintf("<table border=0 cellpadding=2><TR>"
116 "<td bgcolor=\"#CCCCDD\">"
120 wprintf("<font size=-1>"
121 "<a href=\"display_edit_event?"
122 "msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\""
124 WC->disp_cal[i].cal_msgnum,
131 wprintf("<i>%s</i> ", _("Summary:"));
132 escputs((char *)icalproperty_get_comment(p));
135 q = icalcomponent_get_first_property(
137 ICAL_LOCATION_PROPERTY);
139 wprintf("<i>%s</i> ", _("Location:"));
140 escputs((char *)icalproperty_get_comment(q));
145 * Only show start/end times if we're actually looking at the VEVENT
146 * component. Otherwise it shows bogus dates for e.g. timezones
148 if (icalcomponent_isa(WC->disp_cal[i].cal) == ICAL_VEVENT_COMPONENT) {
150 q = icalcomponent_get_first_property(WC->disp_cal[i].cal,
151 ICAL_DTSTART_PROPERTY);
153 t = icalproperty_get_dtstart(q);
158 memset(&d_tm, 0, sizeof d_tm);
159 d_tm.tm_year = t.year - 1900;
160 d_tm.tm_mon = t.month - 1;
161 d_tm.tm_mday = t.day;
162 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
163 wprintf("<i>%s</i> %s<br>",
167 tt = icaltime_as_timet(t);
168 fmt_date(buf, tt, 1);
169 wprintf("<i>%s</i> %s<br>",
170 _("Starting date/time:"), buf);
172 /* Embed the 'show end date/time' loop inside here so it
173 * only executes if this is NOT an all day event.
175 q = icalcomponent_get_first_property(WC->disp_cal[i].cal,
176 ICAL_DTEND_PROPERTY);
178 t = icalproperty_get_dtend(q);
179 tt = icaltime_as_timet(t);
180 fmt_date(buf, tt, 1);
181 wprintf("<i>%s</i> %s<br>",
182 _("Ending date/time:"), buf);
190 q = icalcomponent_get_first_property(
192 ICAL_DESCRIPTION_PROPERTY);
194 wprintf("<i>%s</i> ", _("Notes:"));
195 escputs((char *)icalproperty_get_comment(q));
201 icalproperty_get_comment(p));
202 wprintf("</a></font><br />\n");
205 wprintf("</td></tr></table>");
219 * \brief Display one day of a whole month view of a calendar
220 * \param thetime the month we want to see
222 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
232 struct icaltimetype t;
233 int month, day, year;
234 int all_day_event = 0;
238 time_format = get_time_format_cached ();
240 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
241 else timeformat="%I:%M %p";
243 localtime_r(&thetime, &today_tm);
244 month = today_tm.tm_mon + 1;
245 day = today_tm.tm_mday;
246 year = today_tm.tm_year + 1900;
248 for (i=0; i<(WC->num_cal); ++i) {
249 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
250 ICAL_DTSTART_PROPERTY);
252 t = icalproperty_get_dtstart(p);
253 event_tt = icaltime_as_timet(t);
255 if (t.is_date) all_day_event = 1;
256 else all_day_event = 0;
259 gmtime_r(&event_tts, &event_tms);
262 localtime_r(&event_tts, &event_tms);
264 /** \todo epoch &! daymask */
265 if ((event_tms.tm_year == today_tm.tm_year)
266 && (event_tms.tm_mon == today_tm.tm_mon)
267 && (event_tms.tm_mday == today_tm.tm_mday)) {
273 p = icalcomponent_get_first_property(
275 ICAL_SUMMARY_PROPERTY);
276 e = icalcomponent_get_first_property(
278 ICAL_DTEND_PROPERTY);
279 if ((p != NULL) && (e != NULL)) {
282 t = icalproperty_get_dtend(e);
283 event_tte = icaltime_as_timet(t);
284 localtime_r(&event_tte, &event_tme);
285 difftime=(event_tte-event_tts)/60;
286 hours=(int)(difftime / 60);
287 minutes=difftime % 60;
288 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
290 "<a href=\"display_edit_event?msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\">",
294 WC->disp_cal[i].cal_msgnum,
302 icalproperty_get_comment(p));
303 /** \todo: allso ammitime format */
304 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
305 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
307 wprintf("</a></font></td>"
308 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
325 * \brief view one month. pretty view
326 * \param year the year
327 * \param month the month
328 * \param day the actual day we want to see
330 void calendar_month_view(int year, int month, int day) {
331 struct tm starting_tm;
335 time_t previous_month;
337 time_t colheader_time;
338 struct tm colheader_tm;
339 char colheader_label[32];
342 /** Determine what day to start.
343 * First, back up to the 1st of the month...
345 memset(&starting_tm, 0, sizeof(struct tm));
346 starting_tm.tm_year = year - 1900;
347 starting_tm.tm_mon = month - 1;
348 starting_tm.tm_mday = day;
349 thetime = mktime(&starting_tm);
351 memcpy(&tm, &starting_tm, sizeof(struct tm));
352 while (tm.tm_mday != 1) {
353 thetime = thetime - (time_t)86400; /* go back 24 hours */
354 localtime_r(&thetime, &tm);
357 /** Determine previous and next months ... for links */
358 previous_month = thetime - (time_t)864000L; /* back 10 days */
359 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
361 /** Now back up until we're on a Sunday */
362 localtime_r(&thetime, &tm);
363 while (tm.tm_wday != 0) {
364 thetime = thetime - (time_t)86400; /* go back 24 hours */
365 localtime_r(&thetime, &tm);
368 /** Outer table (to get the background color) */
369 wprintf("<div class=\"fix_scrollbar_bug\">"
370 "<table class=\"calendar\"> \n <tr><td>");
372 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
374 wprintf("<td align=center>");
376 localtime_r(&previous_month, &tm);
377 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
378 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
379 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
381 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
382 wprintf(" "
383 "<font size=+1 color=\"#FFFFFF\">"
386 " ", colheader_label, year);
388 localtime_r(&next_month, &tm);
389 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
390 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
391 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
393 wprintf("</td></tr></table>\n");
395 /** Inner table (the real one) */
396 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
397 "bgcolor=#204B78 id=\"inner_month\"><tr>");
398 colheader_time = thetime;
399 for (i=0; i<7; ++i) {
400 colheader_time = thetime + (i * 86400) ;
401 localtime_r(&colheader_time, &colheader_tm);
402 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
403 wprintf("<td align=center width=14%%>"
404 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
410 /** Now do 35 or 42 days */
411 for (i = 0; i < 42; ++i) {
412 localtime_r(&thetime, &tm);
414 if ((i < 35) || (chg_month == 0)) {
416 if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) {
423 /** Before displaying Sunday, start a new row */
428 wprintf("<td class=\"cal%s\"><div class=\"day\">",
429 ((tm.tm_mon != month-1) ? "out" :
430 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
433 if ((i==0) || (tm.tm_mday == 1)) {
434 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
435 wprintf("%s ", colheader_label);
437 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
444 /** put the data here, stupid */
445 calendar_month_view_display_events(thetime);
449 /** After displaying Saturday, end the row */
456 thetime += (time_t)86400; /** ahead 24 hours */
459 wprintf("</table>" /** end of inner table */
460 "</td></tr></table>" /** end of outer table */
464 * Initialize the bubble tooltips.
466 * Yes, this is as stupid as it looks. Instead of just making the call
467 * to btt_enableTooltips() straight away, we have to create a timer event
468 * and let it initialize as an event after 1 millisecond. This is to
469 * work around a bug in Internet Explorer that causes it to crash if we
470 * manipulate the innerHTML of various DOM nodes while the page is still
471 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
472 * for more information.
474 wprintf("<script type=\"text/javascript\">"
475 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
481 * \brief view one month. brief view
482 * \param year the year
483 * \param month the month
484 * \param day the actual day we want to see
486 void calendar_brief_month_view(int year, int month, int day) {
487 struct tm starting_tm;
491 time_t previous_month;
493 char month_label[32];
495 /** Determine what day to start.
496 * First, back up to the 1st of the month...
498 memset(&starting_tm, 0, sizeof(struct tm));
499 starting_tm.tm_year = year - 1900;
500 starting_tm.tm_mon = month - 1;
501 starting_tm.tm_mday = day;
502 thetime = mktime(&starting_tm);
504 memcpy(&tm, &starting_tm, sizeof(struct tm));
505 while (tm.tm_mday != 1) {
506 thetime = thetime - (time_t)86400; /* go back 24 hours */
507 localtime_r(&thetime, &tm);
510 /** Determine previous and next months ... for links */
511 previous_month = thetime - (time_t)864000L; /* back 10 days */
512 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
514 /** Now back up until we're on a Sunday */
515 localtime_r(&thetime, &tm);
516 while (tm.tm_wday != 0) {
517 thetime = thetime - (time_t)86400; /* go back 24 hours */
518 localtime_r(&thetime, &tm);
521 /** Outer table (to get the background color) */
522 wprintf("<div class=\"fix_scrollbar_bug\">"
523 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
524 "bgcolor=#204B78><TR><TD>\n");
526 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
528 wprintf("<td align=center>");
530 localtime_r(&previous_month, &tm);
531 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
532 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
533 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
535 wc_strftime(month_label, sizeof month_label, "%B", &tm);
536 wprintf(" "
537 "<font size=+1 color=\"#FFFFFF\">"
540 " ", month_label, year);
542 localtime_r(&next_month, &tm);
543 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
544 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
545 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
547 wprintf("</td></tr></table>\n");
549 /** Inner table (the real one) */
550 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
551 "bgcolor=#EEEECC><TR>");
553 wprintf("<tr><td colspan=\"100%\">\n");
555 /** Now do 35 days */
556 for (i = 0; i < 35; ++i) {
557 char weeknumber[255];
558 char weekday_name[32];
560 localtime_r(&thetime, &tm);
563 /** Before displaying Sunday, start a new CELL */
565 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
566 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
567 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
577 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
578 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
582 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
583 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
584 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
586 weekday_name,tm.tm_mday,
589 /** put the data of one day here, stupid */
590 calendar_month_view_brief_events(thetime, daycolor);
593 /** After displaying Saturday, end the row */
595 wprintf("</td></tr></table>\n");
598 thetime += (time_t)86400; /** ahead 24 hours */
601 wprintf("</table>" /** end of inner table */
602 "</td></tr></table>" /** end of outer table */
607 * \brief view one week
608 * this should view just one week, but it's not here yet.
609 * \todo ny implemented
610 * \param year the year
611 * \param month the month
612 * \param day the day which we want to see the week around
614 void calendar_week_view(int year, int month, int day) {
615 wprintf("<center><i>week view FIXME</i></center><br />\n");
620 * \brief display one day
621 * Display events for a particular hour of a particular day.
622 * (Specify hour < 0 to show "all day" events)
623 * \param year the year
624 * \param month the month
626 * \param hour the hour we want to start displaying
627 * \param inner a flag to display between daystart and dayend
628 * (Specify inner to 1 to show inner events)
629 * (Specify inner to 0 to show "all day events and events after dayend)
630 * \param dstart daystart
632 void calendar_day_view_display_events(int year, int month,
634 int inner, int dstart) {
639 icalproperty *pe = NULL;
640 struct icaltimetype t;
641 struct icaltimetype te;
646 int all_day_event = 0;
648 if (WC->num_cal == 0) {
649 // \todo FIXME wprintf("<br /><br /><br />\n");
653 for (i=0; i<(WC->num_cal); ++i) {
654 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
655 ICAL_DTSTART_PROPERTY);
656 pe = icalcomponent_get_first_property(WC->disp_cal[i].cal,
657 ICAL_DTEND_PROPERTY);
659 t = icalproperty_get_dtstart(p);
660 event_tt = icaltime_as_timet(t);
669 gmtime_r(&event_tt, &event_tm);
670 gmtime_r(&event_tt, &event_te);
673 localtime_r(&event_tt, &event_tm);
676 te = icalproperty_get_dtend(pe);
677 event_tte = icaltime_as_timet(te);
678 localtime_r(&event_tte, &event_te);
681 localtime_r(&event_tt, &event_te);
684 if (((event_tm.tm_year <= (year-1900))
685 && (event_tm.tm_mon <= (month-1))
686 && (event_tm.tm_mday <= day)
687 && (event_te.tm_year >= (year-1900))
688 && (event_te.tm_mon >= (month-1))
689 && (event_te.tm_mday >= day))
691 // are we in the start hour?
692 ((event_tm.tm_mday == day)
693 && (event_tm.tm_hour == hour)
695 // are we an all day event?
696 || ((hour<0)&&(t.is_date))
697 // does it span multible days and we're not at the start day?
699 && (event_tm.tm_mday < day)
700 && (event_te.tm_mday >= day))
703 p = icalcomponent_get_first_property(
705 ICAL_SUMMARY_PROPERTY);
709 wprintf("<dd><a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
710 WC->disp_cal[i].cal_msgnum,
711 year, month, day, hour
714 icalproperty_get_comment(p));
715 wprintf("</a></dd>\n");
719 wprintf("<dd class=\"event\" "
720 "style=\"position: absolute; "
721 "top:%dpx; left:100px; "
723 (1 + (event_tm.tm_min / 2) + (event_te.tm_hour - hour) + (hour * 30) - (dstart * 30)),
724 (((event_te.tm_min - event_tm.tm_min) / 2) +(event_te.tm_hour - hour) * 30)
730 wprintf("<a href=\"display_edit_event?"
731 "msgnum=%ld&calview=day&year=%d"
732 "&month=%d&day=%d&hour=%d\""
734 WC->disp_cal[i].cal_msgnum,
735 year, month, day, hour
737 wprintf("<i>%s</i> ", _("Summary:"));
738 escputs((char *)icalproperty_get_comment(p));
741 l = icalcomponent_get_first_property(
743 ICAL_LOCATION_PROPERTY);
745 wprintf("<i>%s</i> ", _("Location:"));
746 escputs((char *)icalproperty_get_comment(l));
749 n = icalcomponent_get_first_property(
751 ICAL_DESCRIPTION_PROPERTY);
753 wprintf("<i>%s</i> ", _("Notes:"));
754 escputs((char *)icalproperty_get_comment(n));
759 icalproperty_get_comment(p));
760 wprintf("</a></dd>\n");
773 * \brief view one day
774 * \param year the year
775 * \param month the month
776 * \param day the day we want to display
778 void calendar_day_view(int year, int month, int day) {
780 struct icaltimetype today, yesterday, tomorrow;
783 char daystart_str[16], dayend_str[16];
788 time_format = get_time_format_cached ();
789 get_preference("daystart", daystart_str, sizeof daystart_str);
790 if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
791 get_preference("dayend", dayend_str, sizeof dayend_str);
792 if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str);
795 /** Figure out the dates for "yesterday" and "tomorrow" links */
797 memset(&today, 0, sizeof(struct icaltimetype));
803 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
805 yesterday = icaltime_normalize(yesterday);
807 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
809 tomorrow = icaltime_normalize(tomorrow);
811 wprintf("<div class=\"fix_scrollbar_bug\">");
813 /** Inner table (the real one) */
814 wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
816 /** Innermost cell (contains hours etc.) */
817 wprintf("<td class=\"middle_of_the_day\" >");
822 " position: absolute ; "
826 " clip: rect(0px 500px %dpx 0px);"
827 " clip: rect(0px, 500px, %dpx, 0px);"
829 (dayend - daystart) * 30,
830 (dayend - daystart) * 30
832 /** Now the middle of the day... */
833 for (hour = 0; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
834 if (hour >= daystart) {
835 wprintf("<dt><a href=\"display_edit_event?msgnum=0"
836 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
837 year, month, day, hour
840 if (time_format == WC_TIMEFORMAT_24) {
841 wprintf("%2d:00</a> ", hour);
844 wprintf("%d:00%s</a> ",
845 (hour <= 12 ? hour : hour-12),
846 (hour < 12 ? "am" : "pm")
853 /* put the data here, stupid */
854 calendar_day_view_display_events(year, month, day, hour, 1 , daystart);
859 wprintf("</td>"); /* end of innermost table */
861 /** Extra events on the middle */
862 wprintf("<td class=\"extra_events\">");
866 /** Display all-day events) */
867 wprintf("<dt>All day events</dt>");
868 calendar_day_view_display_events(year, month, day, -1, 0 , daystart);
870 /** Display events before daystart */
871 wprintf("<dt>Before day start</dt>");
872 for (hour = 0; hour <= (daystart-1); ++hour) {
873 calendar_day_view_display_events(year, month, day, hour, 0, daystart );
876 /** Display events after dayend... */
877 wprintf("<dt>After</dt>");
878 for (hour = (dayend+1); hour <= 23; ++hour) {
879 calendar_day_view_display_events(year, month, day, hour, 0, daystart );
884 wprintf("</td>"); /** end extra on the middle */
886 wprintf("<td width=20%% valign=top>"); /** begin stuff-on-the-right */
888 /** Begin todays-date-with-left-and-right-arrows */
889 wprintf("<table border=0 width=100%% "
890 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
894 wprintf("<td align=center>");
895 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
896 yesterday.year, yesterday.month, yesterday.day);
897 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
901 memset(&d_tm, 0, sizeof d_tm);
902 d_tm.tm_year = year - 1900;
903 d_tm.tm_mon = month - 1;
905 wc_strftime(d_str, sizeof d_str,
907 "<font size=+2>%B</font><br />"
908 "<font size=+3>%d</font><br />"
909 "<font size=+2>%Y</font><br />"
913 wprintf("%s", d_str);
916 wprintf("<td align=center>");
917 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
918 tomorrow.year, tomorrow.month, tomorrow.day);
919 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
923 wprintf("</tr></table>\n");
924 /** End todays-date-with-left-and-right-arrows */
926 /** \todo In the future we might want to put a month-o-matic here */
928 wprintf("</font></center>\n");
930 wprintf("</td></tr>"); /** end stuff-on-the-right */
932 wprintf("</table>" /** end of inner table */
935 wprintf("<script type=\"text/javascript\">"
936 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); "
943 * \brief Display today's events.
945 void calendar_summary_view(void) {
948 struct icaltimetype t;
953 int all_day_event = 0;
954 char timestring[SIZ];
956 if (WC->num_cal == 0) {
961 localtime_r(&now, &today_tm);
963 for (i=0; i<(WC->num_cal); ++i) {
964 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
965 ICAL_DTSTART_PROPERTY);
967 t = icalproperty_get_dtstart(p);
968 event_tt = icaltime_as_timet(t);
975 fmt_time(timestring, event_tt);
978 gmtime_r(&event_tt, &event_tm);
981 localtime_r(&event_tt, &event_tm);
984 if ( (event_tm.tm_year == today_tm.tm_year)
985 && (event_tm.tm_mon == today_tm.tm_mon)
986 && (event_tm.tm_mday == today_tm.tm_mday)
990 p = icalcomponent_get_first_property(
992 ICAL_SUMMARY_PROPERTY);
995 icalproperty_get_comment(p));
996 wprintf(" (%s)<br />\n", timestring);
1001 free_calendar_buffer();
1006 * \brief clean up ical memory
1007 * \todo this could get troubel with future ical versions
1009 void free_calendar_buffer(void) {
1011 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1012 icalcomponent_free(WC->disp_cal[i].cal);
1016 WC->disp_cal = NULL;
1022 * \brief do the whole calendar page
1023 * view any part of the calender. decide which way, etc.
1025 void do_calendar_view(void) {
1028 int year, month, day;
1031 /** In case no date was specified, go with today */
1033 localtime_r(&now, &tm);
1034 year = tm.tm_year + 1900;
1035 month = tm.tm_mon + 1;
1038 /** Now see if a date was specified */
1039 if (!IsEmptyStr(bstr("year"))) year = atoi(bstr("year"));
1040 if (!IsEmptyStr(bstr("month"))) month = atoi(bstr("month"));
1041 if (!IsEmptyStr(bstr("day"))) day = atoi(bstr("day"));
1043 /** How would you like that cooked? */
1044 if (!IsEmptyStr(bstr("calview"))) {
1045 strcpy(calview, bstr("calview"));
1048 strcpy(calview, "month");
1051 /** Display the selected view */
1052 if (!strcasecmp(calview, "day")) {
1053 calendar_day_view(year, month, day);
1055 else if (!strcasecmp(calview, "week")) {
1056 calendar_week_view(year, month, day);
1059 if (WC->wc_view == VIEW_CALBRIEF) {
1060 calendar_brief_month_view(year, month, day);
1063 calendar_month_view(year, month, day);
1067 /** Free the calendar stuff */
1068 free_calendar_buffer();
1074 * \brief get task due date
1075 * Helper function for do_tasks_view().
1076 * \param vtodo a task to get the due date
1077 * \return the date/time due.
1079 time_t get_task_due_date(icalcomponent *vtodo) {
1082 if (vtodo == NULL) {
1087 * If we're looking at a fully encapsulated VCALENDAR
1088 * rather than a VTODO component, recurse into the data
1089 * structure until we get a VTODO.
1091 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1092 return get_task_due_date(
1093 icalcomponent_get_first_component(
1094 vtodo, ICAL_VTODO_COMPONENT
1099 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1101 return(icaltime_as_timet(icalproperty_get_due(p)));
1110 * \brief Compare the due dates of two tasks (this is for sorting)
1111 * \param task1 first task to compare
1112 * \param task2 second task to compare
1114 int task_due_cmp(const void *task1, const void *task2) {
1118 t1 = get_task_due_date(((struct disp_cal *)task1)->cal);
1119 t2 = get_task_due_date(((struct disp_cal *)task2)->cal);
1121 if (t1 < t2) return(-1);
1122 if (t1 > t2) return(1);
1130 * \brief do the whole task view stuff
1132 void do_tasks_view(void) {
1139 wprintf("<div class=\"fix_scrollbar_bug\">"
1140 "<table class=\"calendar_view_background\">\n<tr>\n"
1142 wprintf(_("Name of task"));
1143 wprintf("</th><th>");
1144 wprintf(_("Date due"));
1145 wprintf("</th></tr>\n"
1148 /** Sort them if necessary */
1149 if (WC->num_cal > 1) {
1152 sizeof(struct disp_cal),
1157 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1160 wprintf("<tr bgcolor=\"#%s\"><td>",
1161 (bg ? "DDDDDD" : "FFFFFF")
1164 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1165 ICAL_SUMMARY_PROPERTY);
1166 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1167 WC->disp_cal[i].cal_msgnum );
1168 urlescputs(WC->wc_roomname);
1170 wprintf("<img align=middle "
1171 "src=\"static/taskmanag_16x.gif\" border=0> ");
1173 escputs((char *)icalproperty_get_comment(p));
1178 due = get_task_due_date(WC->disp_cal[i].cal);
1179 fmt_date(buf, due, 0);
1180 wprintf("<td><font");
1181 if (due < time(NULL)) {
1182 wprintf(" color=\"#FF0000\"");
1184 wprintf(">%s</font></td></tr>\n", buf);
1187 wprintf("</table></div>\n");
1189 /** Free the list */
1190 free_calendar_buffer();
1194 #else /* WEBCIT_WITH_CALENDAR_SERVICE */
1196 /**\brief stub for non-libical builds */
1197 void do_calendar_view(void) {
1198 wprintf("<center><i>");
1199 wprintf(_("The calendar view is not available."));
1200 wprintf("</i></center><br />\n");
1203 /**\brief stub for non-libical builds */
1204 void do_tasks_view(void) {
1205 wprintf("<center><I>");
1206 wprintf(_("The tasks view is not available."));
1207 wprintf("</i></center><br />\n");
1211 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */