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(int year, int month, int day)
23 icalproperty *p = NULL;
24 icalproperty *q = NULL;
25 struct icaltimetype t;
26 struct icaltimetype end_t;
27 struct icaltimetype today_start_t;
28 struct icaltimetype today_end_t;
29 int all_day_event = 0;
32 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
36 if (WCC->num_cal == 0) {
37 wprintf("<br /><br /><br />\n");
41 /* Create an imaginary event which spans the 24 hours of today. Any events which
42 * overlap with this one take place at least partially in this day.
44 memset(&today_start_t, 0, sizeof today_start_t);
45 today_start_t.year = year;
46 today_start_t.month = month;
47 today_start_t.day = day;
48 today_start_t.hour = 0;
49 today_start_t.minute = 0;
50 memset(&today_end_t, 0, sizeof today_end_t);
51 today_end_t.year = year;
52 today_end_t.month = month;
53 today_end_t.day = day;
54 today_end_t.hour = 23;
55 today_end_t.minute = 59;
57 /* Now loop through our list of events to see which ones occur today.
59 for (i=0; i<(WCC->num_cal); ++i) {
60 Cal = &WCC->disp_cal[i];
62 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
64 t = icalproperty_get_dtstart(q);
67 memset(&t, 0, sizeof t);
69 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
71 end_t = icalproperty_get_dtend(q);
74 memset(&end_t, 0, sizeof end_t);
76 if (t.is_date) all_day_event = 1;
80 show_event = ((t.year == year) && (t.month == month) && (t.day == day));
84 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
87 /* If we determined that this event occurs today, then display it.
90 p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
94 wprintf("<table border=0 cellpadding=2><TR>"
95 "<td bgcolor=\"#CCCCDD\">"
99 wprintf("<font size=-1>"
100 "<a href=\"display_edit_event?"
101 "msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\""
103 WC->disp_cal[i].cal_msgnum,
110 wprintf("<i>%s</i> ", _("Summary:"));
111 escputs((char *)icalproperty_get_comment(p));
114 q = icalcomponent_get_first_property(
116 ICAL_LOCATION_PROPERTY);
118 wprintf("<i>%s</i> ", _("Location:"));
119 escputs((char *)icalproperty_get_comment(q));
124 * Only show start/end times if we're actually looking at the VEVENT
125 * component. Otherwise it shows bogus dates for e.g. timezones
127 if (icalcomponent_isa(Cal->cal) == ICAL_VEVENT_COMPONENT) {
129 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
131 t = icalproperty_get_dtstart(q);
136 memset(&d_tm, 0, sizeof d_tm);
137 d_tm.tm_year = t.year - 1900;
138 d_tm.tm_mon = t.month - 1;
139 d_tm.tm_mday = t.day;
140 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
141 wprintf("<i>%s</i> %s<br>",
145 tt = icaltime_as_timet(t);
146 fmt_date(buf, tt, 1);
147 wprintf("<i>%s</i> %s<br>",
148 _("Starting date/time:"), buf);
150 /* Embed the 'show end date/time' loop inside here so it
151 * only executes if this is NOT an all day event.
153 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
155 t = icalproperty_get_dtend(q);
156 tt = icaltime_as_timet(t);
157 fmt_date(buf, tt, 1);
158 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
166 q = icalcomponent_get_first_property(Cal->cal, ICAL_DESCRIPTION_PROPERTY);
168 wprintf("<i>%s</i> ", _("Notes:"));
169 escputs((char *)icalproperty_get_comment(q));
175 icalproperty_get_comment(p));
176 wprintf("</a></font><br />\n");
179 wprintf("</td></tr></table>");
192 * \brief Display one day of a whole month view of a calendar
193 * \param thetime the month we want to see
195 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
205 struct icaltimetype t;
206 int month, day, year;
207 int all_day_event = 0;
211 time_format = get_time_format_cached ();
213 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
214 else timeformat="%I:%M %p";
216 localtime_r(&thetime, &today_tm);
217 month = today_tm.tm_mon + 1;
218 day = today_tm.tm_mday;
219 year = today_tm.tm_year + 1900;
221 for (i=0; i<(WC->num_cal); ++i) {
222 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
223 ICAL_DTSTART_PROPERTY);
225 t = icalproperty_get_dtstart(p);
226 event_tt = icaltime_as_timet(t);
228 if (t.is_date) all_day_event = 1;
229 else all_day_event = 0;
232 gmtime_r(&event_tts, &event_tms);
235 localtime_r(&event_tts, &event_tms);
237 /** \todo epoch &! daymask */
238 if ((event_tms.tm_year == today_tm.tm_year)
239 && (event_tms.tm_mon == today_tm.tm_mon)
240 && (event_tms.tm_mday == today_tm.tm_mday)) {
246 p = icalcomponent_get_first_property(
248 ICAL_SUMMARY_PROPERTY);
249 e = icalcomponent_get_first_property(
251 ICAL_DTEND_PROPERTY);
252 if ((p != NULL) && (e != NULL)) {
255 t = icalproperty_get_dtend(e);
256 event_tte = icaltime_as_timet(t);
257 localtime_r(&event_tte, &event_tme);
258 difftime=(event_tte-event_tts)/60;
259 hours=(int)(difftime / 60);
260 minutes=difftime % 60;
261 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
263 "<a href=\"display_edit_event?msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\">",
267 WC->disp_cal[i].cal_msgnum,
275 icalproperty_get_comment(p));
276 /** \todo: allso ammitime format */
277 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
278 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
280 wprintf("</a></font></td>"
281 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
298 * \brief view one month. pretty view
299 * \param year the year
300 * \param month the month
301 * \param day the actual day we want to see
303 void calendar_month_view(int year, int month, int day) {
304 struct tm starting_tm;
308 time_t previous_month;
310 time_t colheader_time;
311 struct tm colheader_tm;
312 char colheader_label[32];
315 char weekstart_buf[16];
317 /* Determine what day to start.
319 get_preference("weekstart", weekstart_buf, sizeof weekstart_buf);
320 weekstart = atoi(weekstart_buf);
323 * Now back up to the 1st of the month...
325 memset(&starting_tm, 0, sizeof(struct tm));
327 starting_tm.tm_year = year - 1900;
328 starting_tm.tm_mon = month - 1;
329 starting_tm.tm_mday = day;
330 thetime = mktime(&starting_tm);
332 memcpy(&tm, &starting_tm, sizeof(struct tm));
333 while (tm.tm_mday != 1) {
334 thetime = thetime - (time_t)86400; /* go back 24 hours */
335 localtime_r(&thetime, &tm);
338 /** Determine previous and next months ... for links */
339 previous_month = thetime - (time_t)864000L; /* back 10 days */
340 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
342 /** Now back up until we're on the user's preferred start day */
343 localtime_r(&thetime, &tm);
344 while (tm.tm_wday != weekstart) {
345 thetime = thetime - (time_t)86400; /* go back 24 hours */
346 localtime_r(&thetime, &tm);
349 /** Outer table (to get the background color) */
350 wprintf("<div class=\"fix_scrollbar_bug\">"
351 "<table class=\"calendar\"> \n <tr><td>");
353 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
355 wprintf("<td align=center>");
357 localtime_r(&previous_month, &tm);
358 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
359 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
360 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
362 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
363 wprintf(" "
364 "<font size=+1 color=\"#FFFFFF\">"
367 " ", colheader_label, year);
369 localtime_r(&next_month, &tm);
370 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
371 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
372 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
374 wprintf("</td></tr></table>\n");
376 /** Inner table (the real one) */
377 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
378 "bgcolor=#204B78 id=\"inner_month\"><tr>");
379 colheader_time = thetime;
380 for (i=0; i<7; ++i) {
381 colheader_time = thetime + (i * 86400) ;
382 localtime_r(&colheader_time, &colheader_tm);
383 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
384 wprintf("<td align=center width=14%%>"
385 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
391 /** Now do 35 or 42 days */
392 for (i = 0; i < 42; ++i) {
393 localtime_r(&thetime, &tm);
395 if ((i < 35) || (chg_month == 0)) {
397 if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) {
404 /** Before displaying Sunday, start a new row */
409 wprintf("<td class=\"cal%s\"><div class=\"day\">",
410 ((tm.tm_mon != month-1) ? "out" :
411 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
414 if ((i==0) || (tm.tm_mday == 1)) {
415 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
416 wprintf("%s ", colheader_label);
418 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
425 /** put the data here, stupid */
426 calendar_month_view_display_events(
434 /** After displaying Saturday, end the row */
441 thetime += (time_t)86400; /** ahead 24 hours */
444 wprintf("</table>" /** end of inner table */
445 "</td></tr></table>" /** end of outer table */
449 * Initialize the bubble tooltips.
451 * Yes, this is as stupid as it looks. Instead of just making the call
452 * to btt_enableTooltips() straight away, we have to create a timer event
453 * and let it initialize as an event after 1 millisecond. This is to
454 * work around a bug in Internet Explorer that causes it to crash if we
455 * manipulate the innerHTML of various DOM nodes while the page is still
456 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
457 * for more information.
459 wprintf("<script type=\"text/javascript\">"
460 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
466 * \brief view one month. brief view
467 * \param year the year
468 * \param month the month
469 * \param day the actual day we want to see
471 void calendar_brief_month_view(int year, int month, int day) {
472 struct tm starting_tm;
476 time_t previous_month;
478 char month_label[32];
480 /** Determine what day to start.
481 * First, back up to the 1st of the month...
483 memset(&starting_tm, 0, sizeof(struct tm));
484 starting_tm.tm_year = year - 1900;
485 starting_tm.tm_mon = month - 1;
486 starting_tm.tm_mday = day;
487 thetime = mktime(&starting_tm);
489 memcpy(&tm, &starting_tm, sizeof(struct tm));
490 while (tm.tm_mday != 1) {
491 thetime = thetime - (time_t)86400; /* go back 24 hours */
492 localtime_r(&thetime, &tm);
495 /** Determine previous and next months ... for links */
496 previous_month = thetime - (time_t)864000L; /* back 10 days */
497 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
499 /** Now back up until we're on a Sunday */
500 localtime_r(&thetime, &tm);
501 while (tm.tm_wday != 0) {
502 thetime = thetime - (time_t)86400; /* go back 24 hours */
503 localtime_r(&thetime, &tm);
506 /** Outer table (to get the background color) */
507 wprintf("<div class=\"fix_scrollbar_bug\">"
508 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
509 "bgcolor=#204B78><TR><TD>\n");
511 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
513 wprintf("<td align=center>");
515 localtime_r(&previous_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/prevdate_32x.gif\" border=0></A>\n");
520 wc_strftime(month_label, sizeof month_label, "%B", &tm);
521 wprintf(" "
522 "<font size=+1 color=\"#FFFFFF\">"
525 " ", month_label, year);
527 localtime_r(&next_month, &tm);
528 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
529 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
530 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
532 wprintf("</td></tr></table>\n");
534 /** Inner table (the real one) */
535 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
536 "bgcolor=#EEEECC><TR>");
538 wprintf("<tr><td colspan=\"100%\">\n");
540 /** Now do 35 days */
541 for (i = 0; i < 35; ++i) {
542 char weeknumber[255];
543 char weekday_name[32];
545 localtime_r(&thetime, &tm);
548 /** Before displaying Sunday, start a new CELL */
550 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
551 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
552 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
562 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
563 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
567 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
568 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
569 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
571 weekday_name,tm.tm_mday,
574 /** put the data of one day here, stupid */
575 calendar_month_view_brief_events(thetime, daycolor);
578 /** After displaying Saturday, end the row */
580 wprintf("</td></tr></table>\n");
583 thetime += (time_t)86400; /** ahead 24 hours */
586 wprintf("</table>" /** end of inner table */
587 "</td></tr></table>" /** end of outer table */
592 * \brief view one week
593 * this should view just one week, but it's not here yet.
594 * \todo ny implemented
595 * \param year the year
596 * \param month the month
597 * \param day the day which we want to see the week around
599 void calendar_week_view(int year, int month, int day) {
600 wprintf("<center><i>week view FIXME</i></center><br />\n");
605 * \brief display one day
606 * Display events for a particular hour of a particular day.
607 * (Specify hour < 0 to show "all day" events)
608 * \param year the year
609 * \param month the month
611 * \param hour the hour we want to start displaying
612 * \param dstart daystart
615 void calendar_day_view_display_events(time_t thetime, int year, int month,
617 int dstart, int dend) {
619 icalproperty *p = NULL;
620 icalproperty *q = NULL;
626 int all_day_event = 0;
627 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
628 struct disp_cal *Cal;
629 struct icaltimetype t;
630 struct icaltimetype end_t;
631 struct icaltimetype today_start_t;
632 struct icaltimetype today_end_t;
635 if (WCC->num_cal == 0) {
636 // \todo FIXME wprintf("<br /><br /><br />\n");
640 event_start = thetime + 60 * 60 * hour;
641 event_end = thetime + 60 * 60 * (hour + 1);
644 /* Create an imaginary event which spans the 24 hours of today. Any events which
645 * overlap with this one take place at least partially in this day.
647 memset(&today_start_t, 0, sizeof today_start_t);
648 today_start_t.year = year;
649 today_start_t.month = month;
650 today_start_t.day = day;
651 today_start_t.hour = 0;
652 today_start_t.minute = 0;
653 memset(&today_end_t, 0, sizeof today_end_t);
654 today_end_t.year = year;
655 today_end_t.month = month;
656 today_end_t.day = day;
657 today_end_t.hour = 23;
658 today_end_t.minute = 59;
661 /* Now loop through our list of events to see which ones occur today.
663 for (i=0; i<(WCC->num_cal); ++i) {
664 Cal = &WCC->disp_cal[i];
667 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
669 t = icalproperty_get_dtstart(q);
672 memset(&t, 0, sizeof t);
674 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
676 end_t = icalproperty_get_dtend(q);
679 memset(&end_t, 0, sizeof end_t);
681 if (t.is_date) all_day_event = 1;
685 show_event = ((t.year == year) && (t.month == month) && (t.day == day));
689 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
692 /* If we determined that this event occurs today, then display it.
694 p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
695 if ((show_event) && (p != NULL)) {
698 wprintf("<dd><a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
699 Cal->cal_msgnum, year, month, day, hour);
700 escputs((char *) icalproperty_get_comment(p));
701 wprintf("</a></dd>\n");
705 wprintf("<dd class=\"event\" "
706 "style=\"position: absolute; "
707 "top:%dpx; left:100px; "
709 (100 + (event_tm.tm_min / 2) + (event_te.tm_hour - hour) + (hour * 30) - (dstart * 30)),
710 (((event_te.tm_min - event_tm.tm_min) / 2) +(event_te.tm_hour - hour) * 30)
712 wprintf("<a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
713 Cal->cal_msgnum, year, month, day, hour);
714 escputs((char *) icalproperty_get_comment(p));
715 wprintf("</a></dd>\n");
722 * \brief view one day
723 * \param year the year
724 * \param month the month
725 * \param day the day we want to display
727 void calendar_day_view(int year, int month, int day) {
729 struct icaltimetype today, yesterday, tomorrow;
732 char daystart_str[16], dayend_str[16];
738 time_format = get_time_format_cached ();
739 get_preference("daystart", daystart_str, sizeof daystart_str);
740 if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
741 get_preference("dayend", dayend_str, sizeof dayend_str);
742 if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str);
745 memset(&d_tm, 0, sizeof d_tm);
746 d_tm.tm_year = year - 1900;
747 d_tm.tm_mon = month - 1;
749 today_t = mktime(&d_tm);
751 /** Figure out the dates for "yesterday" and "tomorrow" links */
753 memset(&today, 0, sizeof(struct icaltimetype));
759 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
761 yesterday = icaltime_normalize(yesterday);
763 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
765 tomorrow = icaltime_normalize(tomorrow);
767 wprintf("<div class=\"fix_scrollbar_bug\">");
769 /** Inner table (the real one) */
770 wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
772 /** Innermost cell (contains hours etc.) */
773 wprintf("<td class=\"events_of_the_day\" >");
774 wprintf("<dl class=\"events\" >");
775 /** Now the middle of the day... */
776 for (hour = 0; hour < 24; ++hour) { /* could do HEIGHT=xx */
777 wprintf("<dt class=\"hour%s\"><a href=\"display_edit_event?msgnum=0"
778 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
779 (hour < daystart ? "before" : (hour > dayend ? "after" : "")),
780 year, month, day, hour
783 if (time_format == WC_TIMEFORMAT_24) {
784 wprintf("%2d:00</a> ", hour);
787 wprintf("%d:00%s</a> ",
788 (hour <= 12 ? hour : hour-12),
789 (hour < 12 ? "am" : "pm")
796 /* put the data here, stupid */
797 calendar_day_view_display_events(today_t, year, month, day, hour, daystart, dayend);
802 wprintf("</td>"); /* end of innermost table */
804 /** Extra events on the middle */
805 wprintf("<td class=\"extra_events\">");
809 /** Display all-day events) */
810 wprintf("<dt>All day events</dt>");
811 calendar_day_view_display_events(today_t, year, month, day, -1, daystart, dayend);
815 wprintf("</td>"); /** end extra on the middle */
817 wprintf("<td width=20%% valign=top>"); /** begin stuff-on-the-right */
819 /** Begin todays-date-with-left-and-right-arrows */
820 wprintf("<table border=0 width=100%% "
821 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
825 wprintf("<td align=center>");
826 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
827 yesterday.year, yesterday.month, yesterday.day);
828 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
831 wc_strftime(d_str, sizeof d_str,
833 "<font size=+2>%B</font><br />"
834 "<font size=+3>%d</font><br />"
835 "<font size=+2>%Y</font><br />"
839 wprintf("%s", d_str);
842 wprintf("<td align=center>");
843 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
844 tomorrow.year, tomorrow.month, tomorrow.day);
845 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
849 wprintf("</tr></table>\n");
850 /** End todays-date-with-left-and-right-arrows */
852 /** \todo In the future we might want to put a month-o-matic here */
854 wprintf("</font></center>\n");
856 wprintf("</td></tr>"); /** end stuff-on-the-right */
858 wprintf("</table>" /** end of inner table */
861 wprintf("<script type=\"text/javascript\">"
862 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); "
869 * \brief Display today's events.
871 void calendar_summary_view(void) {
874 struct icaltimetype t;
879 int all_day_event = 0;
880 char timestring[SIZ];
882 if (WC->num_cal == 0) {
887 localtime_r(&now, &today_tm);
889 for (i=0; i<(WC->num_cal); ++i) {
890 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
891 ICAL_DTSTART_PROPERTY);
893 t = icalproperty_get_dtstart(p);
894 event_tt = icaltime_as_timet(t);
901 fmt_time(timestring, event_tt);
904 gmtime_r(&event_tt, &event_tm);
907 localtime_r(&event_tt, &event_tm);
910 if ( (event_tm.tm_year == today_tm.tm_year)
911 && (event_tm.tm_mon == today_tm.tm_mon)
912 && (event_tm.tm_mday == today_tm.tm_mday)
916 p = icalcomponent_get_first_property(
918 ICAL_SUMMARY_PROPERTY);
921 icalproperty_get_comment(p));
922 wprintf(" (%s)<br />\n", timestring);
927 free_calendar_buffer();
932 * \brief clean up ical memory
933 * \todo this could get troubel with future ical versions
935 void free_calendar_buffer(void) {
937 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
938 icalcomponent_free(WC->disp_cal[i].cal);
948 * \brief do the whole calendar page
949 * view any part of the calender. decide which way, etc.
951 void do_calendar_view(void) {
954 int year, month, day;
957 /** In case no date was specified, go with today */
959 localtime_r(&now, &tm);
960 year = tm.tm_year + 1900;
961 month = tm.tm_mon + 1;
964 /** Now see if a date was specified */
965 if (!IsEmptyStr(bstr("year"))) year = atoi(bstr("year"));
966 if (!IsEmptyStr(bstr("month"))) month = atoi(bstr("month"));
967 if (!IsEmptyStr(bstr("day"))) day = atoi(bstr("day"));
969 /** How would you like that cooked? */
970 if (!IsEmptyStr(bstr("calview"))) {
971 strcpy(calview, bstr("calview"));
974 strcpy(calview, "month");
977 /** Display the selected view */
978 if (!strcasecmp(calview, "day")) {
979 calendar_day_view(year, month, day);
981 else if (!strcasecmp(calview, "week")) {
982 calendar_week_view(year, month, day);
985 if (WC->wc_view == VIEW_CALBRIEF) {
986 calendar_brief_month_view(year, month, day);
989 calendar_month_view(year, month, day);
993 /** Free the calendar stuff */
994 free_calendar_buffer();
1000 * \brief get task due date
1001 * Helper function for do_tasks_view().
1002 * \param vtodo a task to get the due date
1003 * \return the date/time due.
1005 time_t get_task_due_date(icalcomponent *vtodo) {
1008 if (vtodo == NULL) {
1013 * If we're looking at a fully encapsulated VCALENDAR
1014 * rather than a VTODO component, recurse into the data
1015 * structure until we get a VTODO.
1017 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1018 return get_task_due_date(
1019 icalcomponent_get_first_component(
1020 vtodo, ICAL_VTODO_COMPONENT
1025 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1027 return(icaltime_as_timet(icalproperty_get_due(p)));
1036 * \brief Compare the due dates of two tasks (this is for sorting)
1037 * \param task1 first task to compare
1038 * \param task2 second task to compare
1040 int task_due_cmp(const void *task1, const void *task2) {
1044 t1 = get_task_due_date(((struct disp_cal *)task1)->cal);
1045 t2 = get_task_due_date(((struct disp_cal *)task2)->cal);
1047 if (t1 < t2) return(-1);
1048 if (t1 > t2) return(1);
1056 * \brief do the whole task view stuff
1058 void do_tasks_view(void) {
1065 wprintf("<div class=\"fix_scrollbar_bug\">"
1066 "<table class=\"calendar_view_background\">\n<tr>\n"
1068 wprintf(_("Name of task"));
1069 wprintf("</th><th>");
1070 wprintf(_("Date due"));
1071 wprintf("</th></tr>\n"
1074 /** Sort them if necessary */
1075 if (WC->num_cal > 1) {
1078 sizeof(struct disp_cal),
1083 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1086 wprintf("<tr bgcolor=\"#%s\"><td>",
1087 (bg ? "DDDDDD" : "FFFFFF")
1090 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1091 ICAL_SUMMARY_PROPERTY);
1092 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1093 WC->disp_cal[i].cal_msgnum );
1094 urlescputs(WC->wc_roomname);
1096 wprintf("<img align=middle "
1097 "src=\"static/taskmanag_16x.gif\" border=0> ");
1099 escputs((char *)icalproperty_get_comment(p));
1104 due = get_task_due_date(WC->disp_cal[i].cal);
1105 fmt_date(buf, due, 0);
1106 wprintf("<td><font");
1107 if (due < time(NULL)) {
1108 wprintf(" color=\"#FF0000\"");
1110 wprintf(">%s</font></td></tr>\n", buf);
1113 wprintf("</table></div>\n");
1115 /** Free the list */
1116 free_calendar_buffer();
1120 #else /* WEBCIT_WITH_CALENDAR_SERVICE */
1122 /**\brief stub for non-libical builds */
1123 void do_calendar_view(void) {
1124 wprintf("<center><i>");
1125 wprintf(_("The calendar view is not available."));
1126 wprintf("</i></center><br />\n");
1129 /**\brief stub for non-libical builds */
1130 void do_tasks_view(void) {
1131 wprintf("<center><I>");
1132 wprintf(_("The tasks view is not available."));
1133 wprintf("</i></center><br />\n");
1137 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */