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;
779 if (WCC->num_cal == 0) {
780 // \todo FIXME wprintf("<br /><br /><br />\n");
784 event_start = thetime + 60 * 60 * hour;
785 event_end = thetime + 60 * 60 * (hour + 1);
788 /* Create an imaginary event which spans the current hour. Any events which
789 * overlap with this one take place at least partially in this day.
791 memset(&starting_tm, 0, sizeof(struct tm));
792 starting_tm.tm_year = year - 1900;
793 starting_tm.tm_mon = month - 1;
794 starting_tm.tm_mday = day;
795 starting_tm.tm_hour = hour;
796 starting_tm.tm_min = 0;
797 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
798 today_start_t.is_utc = 1;
800 memset(&ending_tm, 0, sizeof(struct tm));
801 ending_tm.tm_year = year - 1900;
802 ending_tm.tm_mon = month - 1;
803 ending_tm.tm_mday = day;
804 ending_tm.tm_hour = hour;
805 ending_tm.tm_min = 59;
806 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
807 today_end_t.is_utc = 1;
809 /* Now loop through our list of events to see which ones occur today.
811 for (i=0; i<(WCC->num_cal); ++i) {
812 Cal = &WCC->disp_cal[i];
817 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
819 t = icalproperty_get_dtstart(q);
820 event_tt = icaltime_as_timet(t);
821 localtime_r(&event_tt, &event_te);
824 memset(&t, 0, sizeof t);
826 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
828 end_t = icalproperty_get_dtend(q);
829 event_tte = icaltime_as_timet(end_t);
830 localtime_r(&event_tte, &event_tm);
833 memset(&end_t, 0, sizeof end_t);
835 if (t.is_date) all_day_event = 1;
839 show_event = ((t.year == year) && (t.month == month) && (t.day == day) && (hour == -1));
843 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
847 /* If we determined that this event occurs today, then display it.
849 p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
850 if ((show_event) && (p != NULL)) {
852 if ((event_te.tm_mday != today_start_t.day) && (event_tm.tm_mday != today_start_t.day)) ongoing_event = 1;
856 wprintf("<li><a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
857 Cal->cal_msgnum, year, month, day, hour);
858 escputs((char *) icalproperty_get_comment(p));
860 wprintf(_("All day event"));
863 else if (ongoing_event && (hour == -1))
865 wprintf("<li><a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
866 Cal->cal_msgnum, year, month, day, hour);
867 escputs((char *) icalproperty_get_comment(p));
869 wprintf(_("Ongoing event"));
874 if ((hour == event_te.tm_hour) && ! ongoing_event ) {
876 if (event_te.tm_mday != today_start_t.day) event_te.tm_hour = 0;
877 if (event_tm.tm_mday != today_start_t.day) event_tm.tm_hour = 24;
879 if ((event_te.tm_hour < dstart) && (event_tm.tm_hour <= dstart)) {
880 top = (event_te.tm_hour * 11) -1;
881 height= (event_tm.tm_hour - event_te.tm_hour) * 11;
883 if ((event_te.tm_hour < dstart) && (event_tm.tm_hour >= dstart)) {
884 top = (event_te.tm_hour * 11) - 1;
885 height = ((dstart - event_te.tm_hour) * 11) + ((event_tm.tm_hour - dstart) * 31);
887 if ((event_te.tm_hour <= dstart) && (event_tm.tm_hour > dend)) {
888 top = (event_te.tm_hour * 11) - 1;
889 height = ((dstart - event_te.tm_hour) * 11) + ((dend - dstart + 1) * 31) + ((event_tm.tm_hour - dend - 1) * 10);
891 if ((event_te.tm_hour >= dstart) && (event_tm.tm_hour <= dend)) {
892 top = (dstart * 11) + ((event_te.tm_hour - dstart) * 31) - 1;
893 height = ((event_tm.tm_hour - event_te.tm_hour) * 31);
895 if ((event_te.tm_hour >= dstart) && (event_te.tm_hour <= dend) && (event_tm.tm_hour > dend)) {
896 top = (dstart * 11) + ((event_te.tm_hour - dstart) * 31) - 1;
897 height = (((dend - event_te.tm_hour + 1) * 31) + ((event_tm.tm_hour - dend - 1) * 11));
899 if ((event_te.tm_hour > dend) && (event_tm.tm_hour > dend)) {
900 top = (dstart * 11) + ((dend - dstart + 1) * 31) + ((event_tm.tm_hour - event_te.tm_hour) * 11) - 1;
901 height = ((event_tm.tm_hour - event_te.tm_hour) * 11);
903 wprintf("<dd class=\"event\" "
904 "style=\"position: absolute; "
905 "top:%dpx; left:%dpx; "
907 top, (50 + (gap * 50)), height
909 wprintf("<a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d&case=%d\">",
910 Cal->cal_msgnum, year, month, day, t.hour, hour);
911 escputs((char *) icalproperty_get_comment(p));
912 wprintf("</a></dd>\n");
922 * \brief view one day
923 * \param year the year
924 * \param month the month
925 * \param day the day we want to display
927 void calendar_day_view(int year, int month, int day) {
929 struct icaltimetype today, yesterday, tomorrow;
932 char daystart_str[16], dayend_str[16];
938 time_format = get_time_format_cached ();
939 get_preference("daystart", daystart_str, sizeof daystart_str);
940 if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
941 get_preference("dayend", dayend_str, sizeof dayend_str);
942 if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str);
945 memset(&d_tm, 0, sizeof d_tm);
946 d_tm.tm_year = year - 1900;
947 d_tm.tm_mon = month - 1;
949 today_t = mktime(&d_tm);
951 /** Figure out the dates for "yesterday" and "tomorrow" links */
953 memset(&today, 0, sizeof(struct icaltimetype));
959 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
961 yesterday = icaltime_normalize(yesterday);
963 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
965 tomorrow = icaltime_normalize(tomorrow);
967 wprintf("<div class=\"fix_scrollbar_bug\">");
969 /** Inner table (the real one) */
970 wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
972 /** Innermost cell (contains hours etc.) */
973 wprintf("<td class=\"events_of_the_day\" >");
974 wprintf("<dl class=\"events\" >");
975 /** Now the middle of the day... */
976 for (hour = 0; hour < 24; ++hour) { /* could do HEIGHT=xx */
977 wprintf("<dt class=\"hour%s\"><a href=\"display_edit_event?msgnum=0"
978 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
979 (hour < daystart ? "before" : (hour > dayend ? "after" : "")),
980 year, month, day, hour
983 if (time_format == WC_TIMEFORMAT_24) {
984 wprintf("%2d:00</a> ", hour);
987 wprintf("%d:00%s</a> ",
988 (hour <= 12 ? hour : hour-12),
989 (hour < 12 ? "am" : "pm")
996 /* put the data here, stupid */
997 calendar_day_view_display_events(today_t, year, month, day, hour, daystart, dayend);
1002 wprintf("</td>"); /* end of innermost table */
1004 /** Extra events on the middle */
1005 wprintf("<td class=\"extra_events\">");
1009 /** Display all-day events) */
1010 calendar_day_view_display_events(today_t, year, month, day, -1, daystart, dayend);
1014 wprintf("</td>"); /** end extra on the middle */
1016 wprintf("<td width=20%% align=center valign=top>"); /** begin stuff-on-the-right */
1018 /** Begin todays-date-with-left-and-right-arrows */
1019 wprintf("<table border=0 width=100%% "
1020 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
1024 wprintf("<td align=center>");
1025 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
1026 yesterday.year, yesterday.month, yesterday.day);
1027 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
1030 wc_strftime(d_str, sizeof d_str,
1032 "<font size=+2>%B</font><br />"
1033 "<font size=+3>%d</font><br />"
1034 "<font size=+2>%Y</font><br />"
1038 wprintf("%s", d_str);
1041 wprintf("<td align=center>");
1042 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
1043 tomorrow.year, tomorrow.month, tomorrow.day);
1044 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
1045 " border=0></a>\n");
1048 wprintf("</tr></table>\n");
1049 /** End todays-date-with-left-and-right-arrows */
1051 /** Embed a mini month calendar in this space */
1052 wprintf("<br />\n");
1053 embeddable_mini_calendar(year, month, "readfwd?calview=day&year=%d&month=%d&day=%d");
1055 wprintf("</font></center>\n");
1057 wprintf("</td></tr>"); /** end stuff-on-the-right */
1059 wprintf("</table>" /** end of inner table */
1062 wprintf("<script type=\"text/javascript\">"
1063 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); "
1070 * \brief Display today's events.
1072 void calendar_summary_view(void) {
1075 struct icaltimetype t;
1080 int all_day_event = 0;
1081 char timestring[SIZ];
1083 if (WC->num_cal == 0) {
1088 localtime_r(&now, &today_tm);
1090 for (i=0; i<(WC->num_cal); ++i) {
1091 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1092 ICAL_DTSTART_PROPERTY);
1094 t = icalproperty_get_dtstart(p);
1095 event_tt = icaltime_as_timet(t);
1102 fmt_time(timestring, event_tt);
1104 if (all_day_event) {
1105 gmtime_r(&event_tt, &event_tm);
1108 localtime_r(&event_tt, &event_tm);
1111 if ( (event_tm.tm_year == today_tm.tm_year)
1112 && (event_tm.tm_mon == today_tm.tm_mon)
1113 && (event_tm.tm_mday == today_tm.tm_mday)
1117 p = icalcomponent_get_first_property(
1118 WC->disp_cal[i].cal,
1119 ICAL_SUMMARY_PROPERTY);
1122 icalproperty_get_comment(p));
1123 wprintf(" (%s)<br />\n", timestring);
1128 free_calendar_buffer();
1133 * \brief clean up ical memory
1134 * \todo this could get troubel with future ical versions
1136 void free_calendar_buffer(void) {
1138 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1139 icalcomponent_free(WC->disp_cal[i].cal);
1143 WC->disp_cal = NULL;
1149 * \brief do the whole calendar page
1150 * view any part of the calender. decide which way, etc.
1152 void do_calendar_view(void) {
1155 int year, month, day;
1158 /** In case no date was specified, go with today */
1160 localtime_r(&now, &tm);
1161 year = tm.tm_year + 1900;
1162 month = tm.tm_mon + 1;
1165 /** Now see if a date was specified */
1166 if (!IsEmptyStr(bstr("year"))) year = atoi(bstr("year"));
1167 if (!IsEmptyStr(bstr("month"))) month = atoi(bstr("month"));
1168 if (!IsEmptyStr(bstr("day"))) day = atoi(bstr("day"));
1170 /** How would you like that cooked? */
1171 if (!IsEmptyStr(bstr("calview"))) {
1172 strcpy(calview, bstr("calview"));
1175 strcpy(calview, "month");
1178 /** Display the selected view */
1179 if (!strcasecmp(calview, "day")) {
1180 calendar_day_view(year, month, day);
1182 else if (!strcasecmp(calview, "week")) {
1183 calendar_week_view(year, month, day);
1186 if (WC->wc_view == VIEW_CALBRIEF) {
1187 calendar_brief_month_view(year, month, day);
1190 calendar_month_view(year, month, day);
1194 /** Free the calendar stuff */
1195 free_calendar_buffer();
1201 * \brief get task due date
1202 * Helper function for do_tasks_view().
1203 * \param vtodo a task to get the due date
1204 * \return the date/time due.
1206 time_t get_task_due_date(icalcomponent *vtodo) {
1209 if (vtodo == NULL) {
1214 * If we're looking at a fully encapsulated VCALENDAR
1215 * rather than a VTODO component, recurse into the data
1216 * structure until we get a VTODO.
1218 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1219 return get_task_due_date(
1220 icalcomponent_get_first_component(
1221 vtodo, ICAL_VTODO_COMPONENT
1226 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1228 return(icaltime_as_timet(icalproperty_get_due(p)));
1237 * \brief Compare the due dates of two tasks (this is for sorting)
1238 * \param task1 first task to compare
1239 * \param task2 second task to compare
1241 int task_due_cmp(const void *task1, const void *task2) {
1245 t1 = get_task_due_date(((struct disp_cal *)task1)->cal);
1246 t2 = get_task_due_date(((struct disp_cal *)task2)->cal);
1248 if (t1 < t2) return(-1);
1249 if (t1 > t2) return(1);
1257 * \brief do the whole task view stuff
1259 void do_tasks_view(void) {
1266 wprintf("<div class=\"fix_scrollbar_bug\">"
1267 "<table class=\"calendar_view_background\">\n<tr>\n"
1269 wprintf(_("Name of task"));
1270 wprintf("</th><th>");
1271 wprintf(_("Date due"));
1272 wprintf("</th></tr>\n"
1275 /** Sort them if necessary */
1276 if (WC->num_cal > 1) {
1279 sizeof(struct disp_cal),
1284 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1287 wprintf("<tr bgcolor=\"#%s\"><td>",
1288 (bg ? "DDDDDD" : "FFFFFF")
1291 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1292 ICAL_SUMMARY_PROPERTY);
1293 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1294 WC->disp_cal[i].cal_msgnum );
1295 urlescputs(WC->wc_roomname);
1297 wprintf("<img align=middle "
1298 "src=\"static/taskmanag_16x.gif\" border=0> ");
1300 escputs((char *)icalproperty_get_comment(p));
1305 due = get_task_due_date(WC->disp_cal[i].cal);
1306 fmt_date(buf, due, 0);
1307 wprintf("<td><font");
1308 if (due < time(NULL)) {
1309 wprintf(" color=\"#FF0000\"");
1311 wprintf(">%s</font></td></tr>\n", buf);
1314 wprintf("</table></div>\n");
1316 /** Free the list */
1317 free_calendar_buffer();
1321 #else /* WEBCIT_WITH_CALENDAR_SERVICE */
1323 /**\brief stub for non-libical builds */
1324 void do_calendar_view(void) {
1325 wprintf("<center><i>");
1326 wprintf(_("The calendar view is not available."));
1327 wprintf("</i></center><br />\n");
1330 /**\brief stub for non-libical builds */
1331 void do_tasks_view(void) {
1332 wprintf("<center><I>");
1333 wprintf(_("The tasks view is not available."));
1334 wprintf("</i></center><br />\n");
1338 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */