5 * \defgroup CalHtmlHandles Handles the HTML display of calendar items.
10 #include "webserver.h"
12 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
14 /****************************************************************************/
19 void embeddable_mini_calendar(int year, int month, char *urlformat)
21 struct tm starting_tm;
25 time_t previous_month;
27 time_t colheader_time;
28 struct tm colheader_tm;
29 char colheader_label[32];
31 char weekstart_buf[16];
35 snprintf(div_id, sizeof div_id, "mini_calendar_%d", rand() );
37 /* Determine what day to start.
39 get_preference("weekstart", weekstart_buf, sizeof weekstart_buf);
40 weekstart = atoi(weekstart_buf);
43 * Now back up to the 1st of the month...
45 memset(&starting_tm, 0, sizeof(struct tm));
47 starting_tm.tm_year = year - 1900;
48 starting_tm.tm_mon = month - 1;
49 starting_tm.tm_mday = 1;
50 thetime = mktime(&starting_tm);
52 memcpy(&tm, &starting_tm, sizeof(struct tm));
53 while (tm.tm_mday != 1) {
54 thetime = thetime - (time_t)86400; /* go back 24 hours */
55 localtime_r(&thetime, &tm);
58 /** Determine previous and next months ... for links */
59 previous_month = thetime - (time_t)864000L; /* back 10 days */
60 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
62 /** Now back up until we're on the user's preferred start day */
63 localtime_r(&thetime, &tm);
64 while (tm.tm_wday != weekstart) {
65 thetime = thetime - (time_t)86400; /* go back 24 hours */
66 localtime_r(&thetime, &tm);
69 wprintf("<div class=\"mini_calendar\" id=\"%s\">\n", div_id);
71 localtime_r(&previous_month, &tm);
73 wprintf("<a href=\"javascript:minical_previous_month();\">«</a>");
76 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
77 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
78 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
81 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
82 wprintf(" "
83 "<span class=\"mini_calendar_month_label\">"
86 " ", colheader_label, year);
89 wprintf("<a href=\"javascript:minical_next_month();\">»</a>");
91 localtime_r(&next_month, &tm);
92 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
93 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
94 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
97 wprintf("<table border=0 cellpadding=1 cellspacing=1 class=\"mini_calendar_days\">"
99 colheader_time = thetime;
100 for (i=0; i<7; ++i) {
101 colheader_time = thetime + (i * 86400) ;
102 localtime_r(&colheader_time, &colheader_tm);
103 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
104 wprintf("<th>%c</th>", colheader_label[0]);
110 /** Now do 35 or 42 days */
111 for (i = 0; i < 42; ++i) {
112 localtime_r(&thetime, &tm);
116 /** Before displaying Sunday, start a new row */
121 if (tm.tm_mon == month-1) {
122 snprintf(url, sizeof url, urlformat,
123 tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday);
124 wprintf("<td><a href=\"%s\">%d</a></td>", url, tm.tm_mday);
127 wprintf("<td> </td>");
130 /** After displaying one week, end the row */
137 thetime += (time_t)86400; /** ahead 24 hours */
140 wprintf("</table>" /** end of inner table */
146 * \brief Display one day of a whole month view of a calendar
147 * \param thetime the month we want to see
149 void calendar_month_view_display_events(int year, int month, int day)
152 icalproperty *p = NULL;
153 icalproperty *q = NULL;
154 struct icaltimetype t;
155 struct icaltimetype end_t;
156 struct icaltimetype today_start_t;
157 struct icaltimetype today_end_t;
158 struct tm starting_tm;
160 int all_day_event = 0;
163 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
164 struct disp_cal *Cal;
167 if (WCC->num_cal == 0) {
168 wprintf("<br /><br /><br />\n");
172 /* Create an imaginary event which spans the 24 hours of today. Any events which
173 * overlap with this one take place at least partially in this day. We have to
174 * convert it from a struct tm in order to make it UTC.
176 memset(&starting_tm, 0, sizeof(struct tm));
177 starting_tm.tm_year = year - 1900;
178 starting_tm.tm_mon = month - 1;
179 starting_tm.tm_mday = day;
180 starting_tm.tm_hour = 0;
181 starting_tm.tm_min = 0;
182 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
183 today_start_t.is_utc = 1;
185 memset(&ending_tm, 0, sizeof(struct tm));
186 ending_tm.tm_year = year - 1900;
187 ending_tm.tm_mon = month - 1;
188 ending_tm.tm_mday = day;
189 ending_tm.tm_hour = 23;
190 ending_tm.tm_min = 59;
191 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
192 today_end_t.is_utc = 1;
194 /* Now loop through our list of events to see which ones occur today.
196 for (i=0; i<(WCC->num_cal); ++i) {
197 Cal = &WCC->disp_cal[i];
199 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
201 t = icalproperty_get_dtstart(q);
204 memset(&t, 0, sizeof t);
206 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
208 end_t = icalproperty_get_dtend(q);
211 memset(&end_t, 0, sizeof end_t);
213 if (t.is_date) all_day_event = 1;
217 show_event = ((t.year == year) && (t.month == month) && (t.day == day));
221 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
224 /* If we determined that this event occurs today, then display it.
227 p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
231 wprintf("<table border=0 cellpadding=2><TR>"
232 "<td bgcolor=\"#CCCCDD\">"
236 wprintf("<font size=-1>"
237 "<a href=\"display_edit_event?"
238 "msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\""
240 WC->disp_cal[i].cal_msgnum,
247 wprintf("<i>%s</i> ", _("Summary:"));
248 escputs((char *)icalproperty_get_comment(p));
251 q = icalcomponent_get_first_property(
253 ICAL_LOCATION_PROPERTY);
255 wprintf("<i>%s</i> ", _("Location:"));
256 escputs((char *)icalproperty_get_comment(q));
261 * Only show start/end times if we're actually looking at the VEVENT
262 * component. Otherwise it shows bogus dates for e.g. timezones
264 if (icalcomponent_isa(Cal->cal) == ICAL_VEVENT_COMPONENT) {
266 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
268 t = icalproperty_get_dtstart(q);
273 memset(&d_tm, 0, sizeof d_tm);
274 d_tm.tm_year = t.year - 1900;
275 d_tm.tm_mon = t.month - 1;
276 d_tm.tm_mday = t.day;
277 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
278 wprintf("<i>%s</i> %s<br>",
282 tt = icaltime_as_timet(t);
283 fmt_date(buf, tt, 1);
284 wprintf("<i>%s</i> %s<br>",
285 _("Starting date/time:"), buf);
287 /* Embed the 'show end date/time' loop inside here so it
288 * only executes if this is NOT an all day event.
290 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
292 t = icalproperty_get_dtend(q);
293 tt = icaltime_as_timet(t);
294 fmt_date(buf, tt, 1);
295 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
303 q = icalcomponent_get_first_property(Cal->cal, ICAL_DESCRIPTION_PROPERTY);
305 wprintf("<i>%s</i> ", _("Notes:"));
306 escputs((char *)icalproperty_get_comment(q));
312 icalproperty_get_comment(p));
313 wprintf("</a></font><br />\n");
316 wprintf("</td></tr></table>");
329 * \brief Display one day of a whole month view of a calendar
330 * \param thetime the month we want to see
332 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
342 struct icaltimetype t;
343 int month, day, year;
344 int all_day_event = 0;
348 time_format = get_time_format_cached ();
350 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
351 else timeformat="%I:%M %p";
353 localtime_r(&thetime, &today_tm);
354 month = today_tm.tm_mon + 1;
355 day = today_tm.tm_mday;
356 year = today_tm.tm_year + 1900;
358 for (i=0; i<(WC->num_cal); ++i) {
359 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
360 ICAL_DTSTART_PROPERTY);
362 t = icalproperty_get_dtstart(p);
363 event_tt = icaltime_as_timet(t);
365 if (t.is_date) all_day_event = 1;
366 else all_day_event = 0;
369 gmtime_r(&event_tts, &event_tms);
372 localtime_r(&event_tts, &event_tms);
374 /** \todo epoch &! daymask */
375 if ((event_tms.tm_year == today_tm.tm_year)
376 && (event_tms.tm_mon == today_tm.tm_mon)
377 && (event_tms.tm_mday == today_tm.tm_mday)) {
383 p = icalcomponent_get_first_property(
385 ICAL_SUMMARY_PROPERTY);
386 e = icalcomponent_get_first_property(
388 ICAL_DTEND_PROPERTY);
389 if ((p != NULL) && (e != NULL)) {
392 t = icalproperty_get_dtend(e);
393 event_tte = icaltime_as_timet(t);
394 localtime_r(&event_tte, &event_tme);
395 difftime=(event_tte-event_tts)/60;
396 hours=(int)(difftime / 60);
397 minutes=difftime % 60;
398 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
400 "<a href=\"display_edit_event?msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\">",
404 WC->disp_cal[i].cal_msgnum,
412 icalproperty_get_comment(p));
413 /** \todo: allso ammitime format */
414 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
415 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
417 wprintf("</a></font></td>"
418 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
435 * \brief view one month. pretty view
436 * \param year the year
437 * \param month the month
438 * \param day the actual day we want to see
440 void calendar_month_view(int year, int month, int day) {
441 struct tm starting_tm;
445 time_t previous_month;
447 time_t colheader_time;
448 struct tm colheader_tm;
449 char colheader_label[32];
452 char weekstart_buf[16];
454 /* Determine what day to start.
456 get_preference("weekstart", weekstart_buf, sizeof weekstart_buf);
457 weekstart = atoi(weekstart_buf);
460 * Now back up to the 1st of the month...
462 memset(&starting_tm, 0, sizeof(struct tm));
464 starting_tm.tm_year = year - 1900;
465 starting_tm.tm_mon = month - 1;
466 starting_tm.tm_mday = day;
467 thetime = mktime(&starting_tm);
469 memcpy(&tm, &starting_tm, sizeof(struct tm));
470 while (tm.tm_mday != 1) {
471 thetime = thetime - (time_t)86400; /* go back 24 hours */
472 localtime_r(&thetime, &tm);
475 /** Determine previous and next months ... for links */
476 previous_month = thetime - (time_t)864000L; /* back 10 days */
477 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
479 /** Now back up until we're on the user's preferred start day */
480 localtime_r(&thetime, &tm);
481 while (tm.tm_wday != weekstart) {
482 thetime = thetime - (time_t)86400; /* go back 24 hours */
483 localtime_r(&thetime, &tm);
486 /** Outer table (to get the background color) */
487 wprintf("<div class=\"fix_scrollbar_bug\">"
488 "<table class=\"calendar\"> \n <tr><td>");
490 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
492 wprintf("<td align=center>");
494 localtime_r(&previous_month, &tm);
495 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
496 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
497 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
499 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
500 wprintf(" "
501 "<font size=+1 color=\"#FFFFFF\">"
504 " ", colheader_label, year);
506 localtime_r(&next_month, &tm);
507 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
508 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
509 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
511 wprintf("</td></tr></table>\n");
513 /** Inner table (the real one) */
514 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
515 "bgcolor=#204B78 id=\"inner_month\"><tr>");
516 colheader_time = thetime;
517 for (i=0; i<7; ++i) {
518 colheader_time = thetime + (i * 86400) ;
519 localtime_r(&colheader_time, &colheader_tm);
520 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
521 wprintf("<td align=center width=14%%>"
522 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
528 /** Now do 35 or 42 days */
529 for (i = 0; i < 42; ++i) {
530 localtime_r(&thetime, &tm);
532 if ((i < 35) || (chg_month == 0)) {
534 if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) {
541 /** Before displaying Sunday, start a new row */
546 wprintf("<td class=\"cal%s\"><div class=\"day\">",
547 ((tm.tm_mon != month-1) ? "out" :
548 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
551 if ((i==0) || (tm.tm_mday == 1)) {
552 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
553 wprintf("%s ", colheader_label);
555 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
562 /** put the data here, stupid */
563 calendar_month_view_display_events(
571 /** After displaying Saturday, end the row */
578 thetime += (time_t)86400; /** ahead 24 hours */
581 wprintf("</table>" /** end of inner table */
582 "</td></tr></table>" /** end of outer table */
586 * Initialize the bubble tooltips.
588 * Yes, this is as stupid as it looks. Instead of just making the call
589 * to btt_enableTooltips() straight away, we have to create a timer event
590 * and let it initialize as an event after 1 millisecond. This is to
591 * work around a bug in Internet Explorer that causes it to crash if we
592 * manipulate the innerHTML of various DOM nodes while the page is still
593 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
594 * for more information.
596 wprintf("<script type=\"text/javascript\">"
597 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
603 * \brief view one month. brief view
604 * \param year the year
605 * \param month the month
606 * \param day the actual day we want to see
608 void calendar_brief_month_view(int year, int month, int day) {
609 struct tm starting_tm;
613 time_t previous_month;
615 char month_label[32];
617 /** Determine what day to start.
618 * First, back up to the 1st of the month...
620 memset(&starting_tm, 0, sizeof(struct tm));
621 starting_tm.tm_year = year - 1900;
622 starting_tm.tm_mon = month - 1;
623 starting_tm.tm_mday = day;
624 thetime = mktime(&starting_tm);
626 memcpy(&tm, &starting_tm, sizeof(struct tm));
627 while (tm.tm_mday != 1) {
628 thetime = thetime - (time_t)86400; /* go back 24 hours */
629 localtime_r(&thetime, &tm);
632 /** Determine previous and next months ... for links */
633 previous_month = thetime - (time_t)864000L; /* back 10 days */
634 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
636 /** Now back up until we're on a Sunday */
637 localtime_r(&thetime, &tm);
638 while (tm.tm_wday != 0) {
639 thetime = thetime - (time_t)86400; /* go back 24 hours */
640 localtime_r(&thetime, &tm);
643 /** Outer table (to get the background color) */
644 wprintf("<div class=\"fix_scrollbar_bug\">"
645 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
646 "bgcolor=#204B78><TR><TD>\n");
648 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
650 wprintf("<td align=center>");
652 localtime_r(&previous_month, &tm);
653 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
654 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
655 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
657 wc_strftime(month_label, sizeof month_label, "%B", &tm);
658 wprintf(" "
659 "<font size=+1 color=\"#FFFFFF\">"
662 " ", month_label, year);
664 localtime_r(&next_month, &tm);
665 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
666 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
667 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
669 wprintf("</td></tr></table>\n");
671 /** Inner table (the real one) */
672 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
673 "bgcolor=#EEEECC><TR>");
675 wprintf("<tr><td colspan=\"100%\">\n");
677 /** Now do 35 days */
678 for (i = 0; i < 35; ++i) {
679 char weeknumber[255];
680 char weekday_name[32];
682 localtime_r(&thetime, &tm);
685 /** Before displaying Sunday, start a new CELL */
687 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
688 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
689 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
699 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
700 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
704 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
705 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
706 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
708 weekday_name,tm.tm_mday,
711 /** put the data of one day here, stupid */
712 calendar_month_view_brief_events(thetime, daycolor);
715 /** After displaying Saturday, end the row */
717 wprintf("</td></tr></table>\n");
720 thetime += (time_t)86400; /** ahead 24 hours */
723 wprintf("</table>" /** end of inner table */
724 "</td></tr></table>" /** end of outer table */
729 * \brief view one week
730 * this should view just one week, but it's not here yet.
731 * \todo ny implemented
732 * \param year the year
733 * \param month the month
734 * \param day the day which we want to see the week around
736 void calendar_week_view(int year, int month, int day) {
737 wprintf("<center><i>week view FIXME</i></center><br />\n");
742 * \brief display one day
743 * Display events for a particular hour of a particular day.
744 * (Specify hour < 0 to show "all day" events)
745 * \param year the year
746 * \param month the month
748 * \param hour the hour we want to start displaying
749 * \param dstart daystart
752 void calendar_day_view_display_events(time_t thetime, int year, int month,
754 int dstart, int dend) {
756 icalproperty *p = NULL;
757 icalproperty *q = NULL;
765 int all_day_event = 0;
766 int ongoing_event = 0;
767 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
768 struct disp_cal *Cal;
769 struct icaltimetype t;
770 struct icaltimetype end_t;
771 struct icaltimetype today_start_t;
772 struct icaltimetype today_end_t;
773 struct tm starting_tm;
778 if (WCC->num_cal == 0) {
779 // \todo FIXME wprintf("<br /><br /><br />\n");
783 event_start = thetime + 60 * 60 * hour;
784 event_end = thetime + 60 * 60 * (hour + 1);
787 /* Create an imaginary event which spans the current hour. Any events which
788 * overlap with this one take place at least partially in this day.
790 memset(&starting_tm, 0, sizeof(struct tm));
791 starting_tm.tm_year = year - 1900;
792 starting_tm.tm_mon = month - 1;
793 starting_tm.tm_mday = day;
794 starting_tm.tm_hour = hour;
795 starting_tm.tm_min = 0;
796 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
797 today_start_t.is_utc = 1;
799 memset(&ending_tm, 0, sizeof(struct tm));
800 ending_tm.tm_year = year - 1900;
801 ending_tm.tm_mon = month - 1;
802 ending_tm.tm_mday = day;
803 ending_tm.tm_hour = hour;
804 ending_tm.tm_min = 59;
805 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
806 today_end_t.is_utc = 1;
808 /* Now loop through our list of events to see which ones occur today.
810 for (i=0; i<(WCC->num_cal); ++i) {
811 Cal = &WCC->disp_cal[i];
816 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
818 t = icalproperty_get_dtstart(q);
819 event_tt = icaltime_as_timet(t);
820 localtime_r(&event_tt, &event_te);
823 memset(&t, 0, sizeof t);
825 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
827 end_t = icalproperty_get_dtend(q);
828 event_tte = icaltime_as_timet(end_t);
829 localtime_r(&event_tte, &event_tm);
832 memset(&end_t, 0, sizeof end_t);
834 if (t.is_date) all_day_event = 1;
838 show_event = ((t.year == year) && (t.month == month) && (t.day == day) && (hour == -1));
842 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
846 /* If we determined that this event occurs today, then display it.
848 p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
849 if ((show_event) && (p != NULL)) {
851 if ((event_te.tm_mday != today_start_t.day) && (event_tm.tm_mday != today_start_t.day)) ongoing_event = 1;
855 wprintf("<li><a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
856 Cal->cal_msgnum, year, month, day, hour);
857 escputs((char *) icalproperty_get_comment(p));
859 wprintf(_("All day event"));
862 else if (ongoing_event && (hour == -1))
864 wprintf("<li><a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
865 Cal->cal_msgnum, year, month, day, hour);
866 escputs((char *) icalproperty_get_comment(p));
868 wprintf(_("Ongoing event"));
873 if ((hour == event_te.tm_hour) && ! ongoing_event ) {
875 if (event_te.tm_mday != today_start_t.day) event_te.tm_hour = 0;
876 if (event_tm.tm_mday != today_start_t.day) event_tm.tm_hour = 24;
878 if ((event_te.tm_hour < dstart) && (event_tm.tm_hour <= dstart)) {
879 top = (event_te.tm_hour * 11) -1;
880 height= (event_tm.tm_hour - event_te.tm_hour) * 11;
882 if ((event_te.tm_hour < dstart) && (event_tm.tm_hour >= dstart)) {
883 top = (event_te.tm_hour * 11) - 1;
884 height = ((dstart - event_te.tm_hour) * 11) + ((event_tm.tm_hour - dstart) * 31);
886 if ((event_te.tm_hour <= dstart) && (event_tm.tm_hour > dend)) {
887 top = (event_te.tm_hour * 11) - 1;
888 height = ((dstart - event_te.tm_hour) * 11) + ((dend - dstart + 1) * 31) + ((event_tm.tm_hour - dend - 1) * 10);
890 if ((event_te.tm_hour >= dstart) && (event_tm.tm_hour <= dend)) {
891 top = (dstart * 11) + ((event_te.tm_hour - dstart) * 31) - 1;
892 height = ((event_tm.tm_hour - event_te.tm_hour) * 31);
894 if ((event_te.tm_hour >= dstart) && (event_te.tm_hour <= dend) && (event_tm.tm_hour > dend)) {
895 top = (dstart * 11) + ((event_te.tm_hour - dstart) * 31) - 1;
896 height = (((dend - event_te.tm_hour + 1) * 31) + ((event_tm.tm_hour - dend - 1) * 11));
898 if ((event_te.tm_hour > dend) && (event_tm.tm_hour > dend)) {
899 top = (dstart * 11) + ((dend - dstart + 1) * 31) + ((event_tm.tm_hour - event_te.tm_hour) * 11) - 1;
900 height = ((event_tm.tm_hour - event_te.tm_hour) * 11);
902 wprintf("<dd class=\"event\" "
903 "style=\"position: absolute; "
904 "top:%dpx; left:100px; "
908 wprintf("<a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d&case=%d\">",
909 Cal->cal_msgnum, year, month, day, t.hour, hour);
910 escputs((char *) icalproperty_get_comment(p));
911 wprintf("</a></dd>\n");
920 * \brief view one day
921 * \param year the year
922 * \param month the month
923 * \param day the day we want to display
925 void calendar_day_view(int year, int month, int day) {
927 struct icaltimetype today, yesterday, tomorrow;
930 char daystart_str[16], dayend_str[16];
936 time_format = get_time_format_cached ();
937 get_preference("daystart", daystart_str, sizeof daystart_str);
938 if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
939 get_preference("dayend", dayend_str, sizeof dayend_str);
940 if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str);
943 memset(&d_tm, 0, sizeof d_tm);
944 d_tm.tm_year = year - 1900;
945 d_tm.tm_mon = month - 1;
947 today_t = mktime(&d_tm);
949 /** Figure out the dates for "yesterday" and "tomorrow" links */
951 memset(&today, 0, sizeof(struct icaltimetype));
957 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
959 yesterday = icaltime_normalize(yesterday);
961 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
963 tomorrow = icaltime_normalize(tomorrow);
965 wprintf("<div class=\"fix_scrollbar_bug\">");
967 /** Inner table (the real one) */
968 wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
970 /** Innermost cell (contains hours etc.) */
971 wprintf("<td class=\"events_of_the_day\" >");
972 wprintf("<dl class=\"events\" >");
973 /** Now the middle of the day... */
974 for (hour = 0; hour < 24; ++hour) { /* could do HEIGHT=xx */
975 wprintf("<dt class=\"hour%s\"><a href=\"display_edit_event?msgnum=0"
976 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
977 (hour < daystart ? "before" : (hour > dayend ? "after" : "")),
978 year, month, day, hour
981 if (time_format == WC_TIMEFORMAT_24) {
982 wprintf("%2d:00</a> ", hour);
985 wprintf("%d:00%s</a> ",
986 (hour <= 12 ? hour : hour-12),
987 (hour < 12 ? "am" : "pm")
994 /* put the data here, stupid */
995 calendar_day_view_display_events(today_t, year, month, day, hour, daystart, dayend);
1000 wprintf("</td>"); /* end of innermost table */
1002 /** Extra events on the middle */
1003 wprintf("<td class=\"extra_events\">");
1007 /** Display all-day events) */
1008 calendar_day_view_display_events(today_t, year, month, day, -1, daystart, dayend);
1012 wprintf("</td>"); /** end extra on the middle */
1014 wprintf("<td width=20%% align=center valign=top>"); /** begin stuff-on-the-right */
1016 /** Begin todays-date-with-left-and-right-arrows */
1017 wprintf("<table border=0 width=100%% "
1018 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
1022 wprintf("<td align=center>");
1023 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
1024 yesterday.year, yesterday.month, yesterday.day);
1025 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
1028 wc_strftime(d_str, sizeof d_str,
1030 "<font size=+2>%B</font><br />"
1031 "<font size=+3>%d</font><br />"
1032 "<font size=+2>%Y</font><br />"
1036 wprintf("%s", d_str);
1039 wprintf("<td align=center>");
1040 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
1041 tomorrow.year, tomorrow.month, tomorrow.day);
1042 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
1043 " border=0></a>\n");
1046 wprintf("</tr></table>\n");
1047 /** End todays-date-with-left-and-right-arrows */
1049 /** Embed a mini month calendar in this space */
1050 wprintf("<br />\n");
1051 embeddable_mini_calendar(year, month, "readfwd?calview=day&year=%d&month=%d&day=%d");
1053 wprintf("</font></center>\n");
1055 wprintf("</td></tr>"); /** end stuff-on-the-right */
1057 wprintf("</table>" /** end of inner table */
1060 wprintf("<script type=\"text/javascript\">"
1061 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); "
1068 * \brief Display today's events.
1070 void calendar_summary_view(void) {
1073 struct icaltimetype t;
1078 int all_day_event = 0;
1079 char timestring[SIZ];
1081 if (WC->num_cal == 0) {
1086 localtime_r(&now, &today_tm);
1088 for (i=0; i<(WC->num_cal); ++i) {
1089 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1090 ICAL_DTSTART_PROPERTY);
1092 t = icalproperty_get_dtstart(p);
1093 event_tt = icaltime_as_timet(t);
1100 fmt_time(timestring, event_tt);
1102 if (all_day_event) {
1103 gmtime_r(&event_tt, &event_tm);
1106 localtime_r(&event_tt, &event_tm);
1109 if ( (event_tm.tm_year == today_tm.tm_year)
1110 && (event_tm.tm_mon == today_tm.tm_mon)
1111 && (event_tm.tm_mday == today_tm.tm_mday)
1115 p = icalcomponent_get_first_property(
1116 WC->disp_cal[i].cal,
1117 ICAL_SUMMARY_PROPERTY);
1120 icalproperty_get_comment(p));
1121 wprintf(" (%s)<br />\n", timestring);
1126 free_calendar_buffer();
1131 * \brief clean up ical memory
1132 * \todo this could get troubel with future ical versions
1134 void free_calendar_buffer(void) {
1136 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1137 icalcomponent_free(WC->disp_cal[i].cal);
1141 WC->disp_cal = NULL;
1147 * \brief do the whole calendar page
1148 * view any part of the calender. decide which way, etc.
1150 void do_calendar_view(void) {
1153 int year, month, day;
1156 /** In case no date was specified, go with today */
1158 localtime_r(&now, &tm);
1159 year = tm.tm_year + 1900;
1160 month = tm.tm_mon + 1;
1163 /** Now see if a date was specified */
1164 if (!IsEmptyStr(bstr("year"))) year = atoi(bstr("year"));
1165 if (!IsEmptyStr(bstr("month"))) month = atoi(bstr("month"));
1166 if (!IsEmptyStr(bstr("day"))) day = atoi(bstr("day"));
1168 /** How would you like that cooked? */
1169 if (!IsEmptyStr(bstr("calview"))) {
1170 strcpy(calview, bstr("calview"));
1173 strcpy(calview, "month");
1176 /** Display the selected view */
1177 if (!strcasecmp(calview, "day")) {
1178 calendar_day_view(year, month, day);
1180 else if (!strcasecmp(calview, "week")) {
1181 calendar_week_view(year, month, day);
1184 if (WC->wc_view == VIEW_CALBRIEF) {
1185 calendar_brief_month_view(year, month, day);
1188 calendar_month_view(year, month, day);
1192 /** Free the calendar stuff */
1193 free_calendar_buffer();
1199 * \brief get task due date
1200 * Helper function for do_tasks_view().
1201 * \param vtodo a task to get the due date
1202 * \return the date/time due.
1204 time_t get_task_due_date(icalcomponent *vtodo) {
1207 if (vtodo == NULL) {
1212 * If we're looking at a fully encapsulated VCALENDAR
1213 * rather than a VTODO component, recurse into the data
1214 * structure until we get a VTODO.
1216 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1217 return get_task_due_date(
1218 icalcomponent_get_first_component(
1219 vtodo, ICAL_VTODO_COMPONENT
1224 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1226 return(icaltime_as_timet(icalproperty_get_due(p)));
1235 * \brief Compare the due dates of two tasks (this is for sorting)
1236 * \param task1 first task to compare
1237 * \param task2 second task to compare
1239 int task_due_cmp(const void *task1, const void *task2) {
1243 t1 = get_task_due_date(((struct disp_cal *)task1)->cal);
1244 t2 = get_task_due_date(((struct disp_cal *)task2)->cal);
1246 if (t1 < t2) return(-1);
1247 if (t1 > t2) return(1);
1255 * \brief do the whole task view stuff
1257 void do_tasks_view(void) {
1264 wprintf("<div class=\"fix_scrollbar_bug\">"
1265 "<table class=\"calendar_view_background\">\n<tr>\n"
1267 wprintf(_("Name of task"));
1268 wprintf("</th><th>");
1269 wprintf(_("Date due"));
1270 wprintf("</th></tr>\n"
1273 /** Sort them if necessary */
1274 if (WC->num_cal > 1) {
1277 sizeof(struct disp_cal),
1282 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1285 wprintf("<tr bgcolor=\"#%s\"><td>",
1286 (bg ? "DDDDDD" : "FFFFFF")
1289 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1290 ICAL_SUMMARY_PROPERTY);
1291 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1292 WC->disp_cal[i].cal_msgnum );
1293 urlescputs(WC->wc_roomname);
1295 wprintf("<img align=middle "
1296 "src=\"static/taskmanag_16x.gif\" border=0> ");
1298 escputs((char *)icalproperty_get_comment(p));
1303 due = get_task_due_date(WC->disp_cal[i].cal);
1304 fmt_date(buf, due, 0);
1305 wprintf("<td><font");
1306 if (due < time(NULL)) {
1307 wprintf(" color=\"#FF0000\"");
1309 wprintf(">%s</font></td></tr>\n", buf);
1312 wprintf("</table></div>\n");
1314 /** Free the list */
1315 free_calendar_buffer();
1319 #else /* WEBCIT_WITH_CALENDAR_SERVICE */
1321 /**\brief stub for non-libical builds */
1322 void do_calendar_view(void) {
1323 wprintf("<center><i>");
1324 wprintf(_("The calendar view is not available."));
1325 wprintf("</i></center><br />\n");
1328 /**\brief stub for non-libical builds */
1329 void do_tasks_view(void) {
1330 wprintf("<center><I>");
1331 wprintf(_("The tasks view is not available."));
1332 wprintf("</i></center><br />\n");
1336 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */