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 show_event = thetime == Cal->start_day;
56 // lprintf(1,"Date: %d %d %d %d\n", thetime, Cal->start_day, day, thetime - Cal->start_day);
59 // are we in the range of the event?
60 show_event = (Cal->start_day <= thetime) &&
61 (Cal->end_day >= thetime);
63 // are we in the range of the event?
64 show_event = (Cal->start_day <= dst_day) &&
65 (Cal->end_day >= dst_day);
67 // are we not start or end day?
68 fill_day_event = (Cal->start_day < thetime) &&
69 (Cal->end_day > thetime);
73 p = icalcomponent_get_first_property(
75 ICAL_SUMMARY_PROPERTY);
79 wprintf("<table border=0 cellpadding=2><TR>"
80 "<td bgcolor=\"#CCCCDD\">"
84 wprintf("<font size=-1>"
85 "<a href=\"display_edit_event?"
86 "msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\""
88 WC->disp_cal[i].cal_msgnum,
95 wprintf("<i>%s</i> ", _("Summary:"));
96 escputs((char *)icalproperty_get_comment(p));
99 q = icalcomponent_get_first_property(
101 ICAL_LOCATION_PROPERTY);
103 wprintf("<i>%s</i> ", _("Location:"));
104 escputs((char *)icalproperty_get_comment(q));
109 * Only show start/end times if we're actually looking at the VEVENT
110 * component. Otherwise it shows bogus dates for e.g. timezones
112 if (icalcomponent_isa(Cal->cal) == ICAL_VEVENT_COMPONENT) {
114 q = icalcomponent_get_first_property(Cal->cal,
115 ICAL_DTSTART_PROPERTY);
117 t = icalproperty_get_dtstart(q);
122 memset(&d_tm, 0, sizeof d_tm);
123 d_tm.tm_year = t.year - 1900;
124 d_tm.tm_mon = t.month - 1;
125 d_tm.tm_mday = t.day;
126 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
127 wprintf("<i>%s</i> %s<br>",
131 tt = icaltime_as_timet(t);
132 fmt_date(buf, tt, 1);
133 wprintf("<i>%s</i> %s<br>",
134 _("Starting date/time:"), buf);
136 /* Embed the 'show end date/time' loop inside here so it
137 * only executes if this is NOT an all day event.
139 q = icalcomponent_get_first_property(Cal->cal,
140 ICAL_DTEND_PROPERTY);
142 t = icalproperty_get_dtend(q);
143 tt = icaltime_as_timet(t);
144 fmt_date(buf, tt, 1);
145 wprintf("<i>%s</i> %s<br>",
146 _("Ending date/time:"), buf);
154 q = icalcomponent_get_first_property(
156 ICAL_DESCRIPTION_PROPERTY);
158 wprintf("<i>%s</i> ", _("Notes:"));
159 escputs((char *)icalproperty_get_comment(q));
165 icalproperty_get_comment(p));
166 wprintf("</a></font><br />\n");
169 wprintf("</td></tr></table>");
182 * \brief Display one day of a whole month view of a calendar
183 * \param thetime the month we want to see
185 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
195 struct icaltimetype t;
196 int month, day, year;
197 int all_day_event = 0;
201 time_format = get_time_format_cached ();
203 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
204 else timeformat="%I:%M %p";
206 localtime_r(&thetime, &today_tm);
207 month = today_tm.tm_mon + 1;
208 day = today_tm.tm_mday;
209 year = today_tm.tm_year + 1900;
211 for (i=0; i<(WC->num_cal); ++i) {
212 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
213 ICAL_DTSTART_PROPERTY);
215 t = icalproperty_get_dtstart(p);
216 event_tt = icaltime_as_timet(t);
218 if (t.is_date) all_day_event = 1;
219 else all_day_event = 0;
222 gmtime_r(&event_tts, &event_tms);
225 localtime_r(&event_tts, &event_tms);
227 /** \todo epoch &! daymask */
228 if ((event_tms.tm_year == today_tm.tm_year)
229 && (event_tms.tm_mon == today_tm.tm_mon)
230 && (event_tms.tm_mday == today_tm.tm_mday)) {
236 p = icalcomponent_get_first_property(
238 ICAL_SUMMARY_PROPERTY);
239 e = icalcomponent_get_first_property(
241 ICAL_DTEND_PROPERTY);
242 if ((p != NULL) && (e != NULL)) {
245 t = icalproperty_get_dtend(e);
246 event_tte = icaltime_as_timet(t);
247 localtime_r(&event_tte, &event_tme);
248 difftime=(event_tte-event_tts)/60;
249 hours=(int)(difftime / 60);
250 minutes=difftime % 60;
251 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
253 "<a href=\"display_edit_event?msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\">",
257 WC->disp_cal[i].cal_msgnum,
265 icalproperty_get_comment(p));
266 /** \todo: allso ammitime format */
267 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
268 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
270 wprintf("</a></font></td>"
271 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
288 * \brief view one month. pretty view
289 * \param year the year
290 * \param month the month
291 * \param day the actual day we want to see
293 void calendar_month_view(int year, int month, int day) {
294 struct tm starting_tm;
298 time_t previous_month;
300 time_t colheader_time;
301 struct tm colheader_tm;
302 char colheader_label[32];
305 char weekstart_buf[16];
307 /* Determine what day to start.
309 get_preference("weekstart", weekstart_buf, sizeof weekstart_buf);
310 weekstart = atoi(weekstart_buf);
313 * Now back up to the 1st of the month...
315 memset(&starting_tm, 0, sizeof(struct tm));
317 starting_tm.tm_year = year - 1900;
318 starting_tm.tm_mon = month - 1;
319 starting_tm.tm_mday = day;
320 thetime = mktime(&starting_tm);
322 memcpy(&tm, &starting_tm, sizeof(struct tm));
323 while (tm.tm_mday != 1) {
324 thetime = thetime - (time_t)86400; /* go back 24 hours */
325 localtime_r(&thetime, &tm);
328 /** Determine previous and next months ... for links */
329 previous_month = thetime - (time_t)864000L; /* back 10 days */
330 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
332 /** Now back up until we're on the user's preferred start day */
333 localtime_r(&thetime, &tm);
334 while (tm.tm_wday != weekstart) {
335 thetime = thetime - (time_t)86400; /* go back 24 hours */
336 localtime_r(&thetime, &tm);
339 /** Outer table (to get the background color) */
340 wprintf("<div class=\"fix_scrollbar_bug\">"
341 "<table class=\"calendar\"> \n <tr><td>");
343 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
345 wprintf("<td align=center>");
347 localtime_r(&previous_month, &tm);
348 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
349 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
350 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
352 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
353 wprintf(" "
354 "<font size=+1 color=\"#FFFFFF\">"
357 " ", colheader_label, year);
359 localtime_r(&next_month, &tm);
360 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
361 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
362 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
364 wprintf("</td></tr></table>\n");
366 /** Inner table (the real one) */
367 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
368 "bgcolor=#204B78 id=\"inner_month\"><tr>");
369 colheader_time = thetime;
370 for (i=0; i<7; ++i) {
371 colheader_time = thetime + (i * 86400) ;
372 localtime_r(&colheader_time, &colheader_tm);
373 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
374 wprintf("<td align=center width=14%%>"
375 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
381 /** Now do 35 or 42 days */
382 for (i = 0; i < 42; ++i) {
383 localtime_r(&thetime, &tm);
385 if ((i < 35) || (chg_month == 0)) {
387 if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) {
394 /** Before displaying Sunday, start a new row */
399 wprintf("<td class=\"cal%s\"><div class=\"day\">",
400 ((tm.tm_mon != month-1) ? "out" :
401 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
404 if ((i==0) || (tm.tm_mday == 1)) {
405 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
406 wprintf("%s ", colheader_label);
408 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
415 /** put the data here, stupid */
416 calendar_month_view_display_events(thetime);
420 /** After displaying Saturday, end the row */
427 thetime += (time_t)86400; /** ahead 24 hours */
430 wprintf("</table>" /** end of inner table */
431 "</td></tr></table>" /** end of outer table */
435 * Initialize the bubble tooltips.
437 * Yes, this is as stupid as it looks. Instead of just making the call
438 * to btt_enableTooltips() straight away, we have to create a timer event
439 * and let it initialize as an event after 1 millisecond. This is to
440 * work around a bug in Internet Explorer that causes it to crash if we
441 * manipulate the innerHTML of various DOM nodes while the page is still
442 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
443 * for more information.
445 wprintf("<script type=\"text/javascript\">"
446 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
452 * \brief view one month. brief view
453 * \param year the year
454 * \param month the month
455 * \param day the actual day we want to see
457 void calendar_brief_month_view(int year, int month, int day) {
458 struct tm starting_tm;
462 time_t previous_month;
464 char month_label[32];
466 /** Determine what day to start.
467 * First, back up to the 1st of the month...
469 memset(&starting_tm, 0, sizeof(struct tm));
470 starting_tm.tm_year = year - 1900;
471 starting_tm.tm_mon = month - 1;
472 starting_tm.tm_mday = day;
473 thetime = mktime(&starting_tm);
475 memcpy(&tm, &starting_tm, sizeof(struct tm));
476 while (tm.tm_mday != 1) {
477 thetime = thetime - (time_t)86400; /* go back 24 hours */
478 localtime_r(&thetime, &tm);
481 /** Determine previous and next months ... for links */
482 previous_month = thetime - (time_t)864000L; /* back 10 days */
483 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
485 /** Now back up until we're on a Sunday */
486 localtime_r(&thetime, &tm);
487 while (tm.tm_wday != 0) {
488 thetime = thetime - (time_t)86400; /* go back 24 hours */
489 localtime_r(&thetime, &tm);
492 /** Outer table (to get the background color) */
493 wprintf("<div class=\"fix_scrollbar_bug\">"
494 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
495 "bgcolor=#204B78><TR><TD>\n");
497 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
499 wprintf("<td align=center>");
501 localtime_r(&previous_month, &tm);
502 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
503 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
504 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
506 wc_strftime(month_label, sizeof month_label, "%B", &tm);
507 wprintf(" "
508 "<font size=+1 color=\"#FFFFFF\">"
511 " ", month_label, year);
513 localtime_r(&next_month, &tm);
514 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
515 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
516 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
518 wprintf("</td></tr></table>\n");
520 /** Inner table (the real one) */
521 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
522 "bgcolor=#EEEECC><TR>");
524 wprintf("<tr><td colspan=\"100%\">\n");
526 /** Now do 35 days */
527 for (i = 0; i < 35; ++i) {
528 char weeknumber[255];
529 char weekday_name[32];
531 localtime_r(&thetime, &tm);
534 /** Before displaying Sunday, start a new CELL */
536 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
537 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
538 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
548 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
549 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
553 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
554 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
555 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
557 weekday_name,tm.tm_mday,
560 /** put the data of one day here, stupid */
561 calendar_month_view_brief_events(thetime, daycolor);
564 /** After displaying Saturday, end the row */
566 wprintf("</td></tr></table>\n");
569 thetime += (time_t)86400; /** ahead 24 hours */
572 wprintf("</table>" /** end of inner table */
573 "</td></tr></table>" /** end of outer table */
578 * \brief view one week
579 * this should view just one week, but it's not here yet.
580 * \todo ny implemented
581 * \param year the year
582 * \param month the month
583 * \param day the day which we want to see the week around
585 void calendar_week_view(int year, int month, int day) {
586 wprintf("<center><i>week view FIXME</i></center><br />\n");
591 * \brief display one day
592 * Display events for a particular hour of a particular day.
593 * (Specify hour < 0 to show "all day" events)
594 * \param year the year
595 * \param month the month
597 * \param hour the hour we want to start displaying
598 * \param inner a flag to display between daystart and dayend
599 * (Specify inner to 1 to show inner events)
600 * (Specify inner to 0 to show "all day events and events after dayend)
601 * \param dstart daystart
603 void calendar_day_view_display_events(time_t thetime, int year, int month,
605 int inner, int dstart) {
615 int all_day_event = 0;
616 struct wcsession *WCC;
617 struct disp_cal *Cal;
621 if (WCC->num_cal == 0) {
622 // \todo FIXME wprintf("<br /><br /><br />\n");
626 event_start = thetime + 60 * 60 * hour;
627 event_end = thetime + 60 * 60 * (hour + 1);
629 for (i=0; i<(WCC->num_cal); ++i) {
630 Cal = &WCC->disp_cal[i];
631 all_day_event = Cal->start_hour == -1;
634 if (! all_day_event && inner)
636 show_event = (thetime == Cal->start_day) &&
637 (event_start <= Cal->start_hour) &&
638 ((Cal->end_hour != -1)?
639 (Cal->end_hour < event_end) : 1);
644 show_event = !inner && (Cal->start_day == thetime);
647 p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
648 if ((show_event) && (p != NULL)) {
650 wprintf("<dd><a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
651 Cal->cal_msgnum,year, month, day, hour);
652 escputs((char *) icalproperty_get_comment(p));
653 wprintf("</a></dd>\n");
656 wprintf("<dd class=\"event\" "
657 "style=\"position: absolute; "
658 "top:%dpx; left:100px; "
660 (1 + (event_tm.tm_min / 2) + (event_te.tm_hour - hour) + (hour * 30) - (dstart * 30)),
661 (((event_te.tm_min - event_tm.tm_min) / 2) +(event_te.tm_hour - hour) * 30)
672 wprintf("<a href=\"display_edit_event?"
673 "msgnum=%ld&calview=day&year=%d"
674 "&month=%d&day=%d&hour=%d\""
676 WC->disp_cal[i].cal_msgnum,
677 year, month, day, hour
679 wprintf("<i>%s</i> ", _("Summary:"));
680 escputs((char *)icalproperty_get_comment(p));
683 l = icalcomponent_get_first_property(
685 ICAL_LOCATION_PROPERTY);
687 wprintf("<i>%s</i> ", _("Location:"));
688 escputs((char *)icalproperty_get_comment(l));
691 n = icalcomponent_get_first_property(
693 ICAL_DESCRIPTION_PROPERTY);
695 wprintf("<i>%s</i> ", _("Notes:"));
696 escputs((char *)icalproperty_get_comment(n));
701 icalproperty_get_comment(p));
702 wprintf("</a></dd>\n");
710 /* TODO: whats that? thierry, when do we need to show this?
711 wprintf("<a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
712 WC->disp_cal[i].cal_msgnum,
713 year, month, day, hour
716 icalproperty_get_comment(p));
717 wprintf("</a></dd>\n");
726 * \brief view one day
727 * \param year the year
728 * \param month the month
729 * \param day the day we want to display
731 void calendar_day_view(int year, int month, int day) {
733 struct icaltimetype today, yesterday, tomorrow;
736 char daystart_str[16], dayend_str[16];
742 time_format = get_time_format_cached ();
743 get_preference("daystart", daystart_str, sizeof daystart_str);
744 if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
745 get_preference("dayend", dayend_str, sizeof dayend_str);
746 if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str);
749 memset(&d_tm, 0, sizeof d_tm);
751 localtime_r(&WC->disp_cal[0].start_day, &d_tm);
753 d_tm.tm_year = year - 1900;
754 d_tm.tm_mon = month - 1;
756 today_t = mktime(&d_tm);
758 /** Figure out the dates for "yesterday" and "tomorrow" links */
760 memset(&today, 0, sizeof(struct icaltimetype));
766 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
768 yesterday = icaltime_normalize(yesterday);
770 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
772 tomorrow = icaltime_normalize(tomorrow);
774 wprintf("<div class=\"fix_scrollbar_bug\">");
776 /** Inner table (the real one) */
777 wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
779 /** Innermost cell (contains hours etc.) */
780 wprintf("<td class=\"middle_of_the_day\" >");
785 " position: absolute ; "
789 " clip: rect(0px 500px %dpx 0px);"
790 " clip: rect(0px, 500px, %dpx, 0px);"
792 (dayend - daystart) * 30,
793 (dayend - daystart) * 30
795 /** Now the middle of the day... */
796 for (hour = 0; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
797 if (hour >= daystart) {
798 wprintf("<dt><a href=\"display_edit_event?msgnum=0"
799 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
800 year, month, day, hour
803 if (time_format == WC_TIMEFORMAT_24) {
804 wprintf("%2d:00</a> ", hour);
807 wprintf("%d:00%s</a> ",
808 (hour <= 12 ? hour : hour-12),
809 (hour < 12 ? "am" : "pm")
816 /* put the data here, stupid */
817 calendar_day_view_display_events(today_t, year, month, day, hour, 1 , daystart);
822 wprintf("</td>"); /* end of innermost table */
824 /** Extra events on the middle */
825 wprintf("<td class=\"extra_events\">");
829 /** Display all-day events) */
830 wprintf("<dt>All day events</dt>");
831 calendar_day_view_display_events(today_t, year, month, day, -1, 0 , daystart);
833 /** Display events before daystart */
834 wprintf("<dt>Before day start</dt>");
835 for (hour = 0; hour <= (daystart-1); ++hour) {
836 calendar_day_view_display_events(today_t, year, month, day, hour, 0, daystart );
839 /** Display events after dayend... */
840 wprintf("<dt>After</dt>");
841 for (hour = (dayend+1); hour <= 23; ++hour) {
842 calendar_day_view_display_events(today_t, year, month, day, hour, 0, daystart );
847 wprintf("</td>"); /** end extra on the middle */
849 wprintf("<td width=20%% valign=top>"); /** begin stuff-on-the-right */
851 /** Begin todays-date-with-left-and-right-arrows */
852 wprintf("<table border=0 width=100%% "
853 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
857 wprintf("<td align=center>");
858 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
859 yesterday.year, yesterday.month, yesterday.day);
860 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
863 wc_strftime(d_str, sizeof d_str,
865 "<font size=+2>%B</font><br />"
866 "<font size=+3>%d</font><br />"
867 "<font size=+2>%Y</font><br />"
871 wprintf("%s", d_str);
874 wprintf("<td align=center>");
875 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
876 tomorrow.year, tomorrow.month, tomorrow.day);
877 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
881 wprintf("</tr></table>\n");
882 /** End todays-date-with-left-and-right-arrows */
884 /** \todo In the future we might want to put a month-o-matic here */
886 wprintf("</font></center>\n");
888 wprintf("</td></tr>"); /** end stuff-on-the-right */
890 wprintf("</table>" /** end of inner table */
893 wprintf("<script type=\"text/javascript\">"
894 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); "
901 * \brief Display today's events.
903 void calendar_summary_view(void) {
906 struct icaltimetype t;
911 int all_day_event = 0;
912 char timestring[SIZ];
914 if (WC->num_cal == 0) {
919 localtime_r(&now, &today_tm);
921 for (i=0; i<(WC->num_cal); ++i) {
922 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
923 ICAL_DTSTART_PROPERTY);
925 t = icalproperty_get_dtstart(p);
926 event_tt = icaltime_as_timet(t);
933 fmt_time(timestring, event_tt);
936 gmtime_r(&event_tt, &event_tm);
939 localtime_r(&event_tt, &event_tm);
942 if ( (event_tm.tm_year == today_tm.tm_year)
943 && (event_tm.tm_mon == today_tm.tm_mon)
944 && (event_tm.tm_mday == today_tm.tm_mday)
948 p = icalcomponent_get_first_property(
950 ICAL_SUMMARY_PROPERTY);
953 icalproperty_get_comment(p));
954 wprintf(" (%s)<br />\n", timestring);
959 free_calendar_buffer();
964 * \brief clean up ical memory
965 * \todo this could get troubel with future ical versions
967 void free_calendar_buffer(void) {
969 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
970 icalcomponent_free(WC->disp_cal[i].cal);
980 * \brief do the whole calendar page
981 * view any part of the calender. decide which way, etc.
983 void do_calendar_view(void) {
986 int year, month, day;
989 /** In case no date was specified, go with today */
991 localtime_r(&now, &tm);
992 year = tm.tm_year + 1900;
993 month = tm.tm_mon + 1;
996 /** Now see if a date was specified */
997 if (!IsEmptyStr(bstr("year"))) year = atoi(bstr("year"));
998 if (!IsEmptyStr(bstr("month"))) month = atoi(bstr("month"));
999 if (!IsEmptyStr(bstr("day"))) day = atoi(bstr("day"));
1001 /** How would you like that cooked? */
1002 if (!IsEmptyStr(bstr("calview"))) {
1003 strcpy(calview, bstr("calview"));
1006 strcpy(calview, "month");
1009 /** Display the selected view */
1010 if (!strcasecmp(calview, "day")) {
1011 calendar_day_view(year, month, day);
1013 else if (!strcasecmp(calview, "week")) {
1014 calendar_week_view(year, month, day);
1017 if (WC->wc_view == VIEW_CALBRIEF) {
1018 calendar_brief_month_view(year, month, day);
1021 calendar_month_view(year, month, day);
1025 /** Free the calendar stuff */
1026 free_calendar_buffer();
1032 * \brief get task due date
1033 * Helper function for do_tasks_view().
1034 * \param vtodo a task to get the due date
1035 * \return the date/time due.
1037 time_t get_task_due_date(icalcomponent *vtodo) {
1040 if (vtodo == NULL) {
1045 * If we're looking at a fully encapsulated VCALENDAR
1046 * rather than a VTODO component, recurse into the data
1047 * structure until we get a VTODO.
1049 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1050 return get_task_due_date(
1051 icalcomponent_get_first_component(
1052 vtodo, ICAL_VTODO_COMPONENT
1057 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1059 return(icaltime_as_timet(icalproperty_get_due(p)));
1068 * \brief Compare the due dates of two tasks (this is for sorting)
1069 * \param task1 first task to compare
1070 * \param task2 second task to compare
1072 int task_due_cmp(const void *task1, const void *task2) {
1076 t1 = get_task_due_date(((struct disp_cal *)task1)->cal);
1077 t2 = get_task_due_date(((struct disp_cal *)task2)->cal);
1079 if (t1 < t2) return(-1);
1080 if (t1 > t2) return(1);
1088 * \brief do the whole task view stuff
1090 void do_tasks_view(void) {
1097 wprintf("<div class=\"fix_scrollbar_bug\">"
1098 "<table class=\"calendar_view_background\">\n<tr>\n"
1100 wprintf(_("Name of task"));
1101 wprintf("</th><th>");
1102 wprintf(_("Date due"));
1103 wprintf("</th></tr>\n"
1106 /** Sort them if necessary */
1107 if (WC->num_cal > 1) {
1110 sizeof(struct disp_cal),
1115 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1118 wprintf("<tr bgcolor=\"#%s\"><td>",
1119 (bg ? "DDDDDD" : "FFFFFF")
1122 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1123 ICAL_SUMMARY_PROPERTY);
1124 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1125 WC->disp_cal[i].cal_msgnum );
1126 urlescputs(WC->wc_roomname);
1128 wprintf("<img align=middle "
1129 "src=\"static/taskmanag_16x.gif\" border=0> ");
1131 escputs((char *)icalproperty_get_comment(p));
1136 due = get_task_due_date(WC->disp_cal[i].cal);
1137 fmt_date(buf, due, 0);
1138 wprintf("<td><font");
1139 if (due < time(NULL)) {
1140 wprintf(" color=\"#FF0000\"");
1142 wprintf(">%s</font></td></tr>\n", buf);
1145 wprintf("</table></div>\n");
1147 /** Free the list */
1148 free_calendar_buffer();
1152 #else /* WEBCIT_WITH_CALENDAR_SERVICE */
1154 /**\brief stub for non-libical builds */
1155 void do_calendar_view(void) {
1156 wprintf("<center><i>");
1157 wprintf(_("The calendar view is not available."));
1158 wprintf("</i></center><br />\n");
1161 /**\brief stub for non-libical builds */
1162 void do_tasks_view(void) {
1163 wprintf("<center><I>");
1164 wprintf(_("The tasks view is not available."));
1165 wprintf("</i></center><br />\n");
1169 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */