5 * \defgroup CalHtmlHandles Handles the HTML display of calendar items.
10 #include "webserver.h"
12 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
14 /****************************************************************************/
17 void embeddable_mini_calendar(int year, int month, char *urlformat)
19 struct tm starting_tm;
23 time_t previous_month;
25 time_t colheader_time;
26 struct tm colheader_tm;
27 char colheader_label[32];
29 char weekstart_buf[16];
32 char escaped_urlformat[256];
34 snprintf(div_id, sizeof div_id, "mini_calendar_%d", rand() );
36 /* Determine what day to start.
38 get_preference("weekstart", weekstart_buf, sizeof weekstart_buf);
39 weekstart = atoi(weekstart_buf);
42 * Now back up to the 1st of the month...
44 memset(&starting_tm, 0, sizeof(struct tm));
46 starting_tm.tm_year = year - 1900;
47 starting_tm.tm_mon = month - 1;
48 starting_tm.tm_mday = 1;
49 thetime = mktime(&starting_tm);
51 memcpy(&tm, &starting_tm, sizeof(struct tm));
52 while (tm.tm_mday != 1) {
53 thetime = thetime - (time_t)86400; /* go back 24 hours */
54 localtime_r(&thetime, &tm);
57 /** Determine previous and next months ... for links */
58 previous_month = thetime - (time_t)864000L; /* back 10 days */
59 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
61 /** Now back up until we're on the user's preferred start day */
62 localtime_r(&thetime, &tm);
63 while (tm.tm_wday != weekstart) {
64 thetime = thetime - (time_t)86400; /* go back 24 hours */
65 localtime_r(&thetime, &tm);
68 wprintf("<div class=\"mini_calendar\" id=\"%s\">\n", div_id);
70 /* Previous month link */
71 localtime_r(&previous_month, &tm);
72 wprintf("<a href=\"javascript:minical_change_month(%d,%d);\">«</a>",
73 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
75 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
76 wprintf(" "
77 "<span class=\"mini_calendar_month_label\">"
80 " ", colheader_label, year);
83 localtime_r(&next_month, &tm);
84 wprintf("<a href=\"javascript:minical_change_month(%d,%d);\">»</a>",
85 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
87 wprintf("<table border=0 cellpadding=1 cellspacing=1 class=\"mini_calendar_days\">"
89 colheader_time = thetime;
91 colheader_time = thetime + (i * 86400) ;
92 localtime_r(&colheader_time, &colheader_tm);
93 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
94 wprintf("<th>%c</th>", colheader_label[0]);
100 /** Now do 35 or 42 days */
101 for (i = 0; i < 42; ++i) {
102 localtime_r(&thetime, &tm);
106 /** Before displaying Sunday, start a new row */
111 if (tm.tm_mon == month-1) {
112 snprintf(url, sizeof url, urlformat,
113 tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday);
114 wprintf("<td><a href=\"%s\">%d</a></td>", url, tm.tm_mday);
117 wprintf("<td> </td>");
120 /** After displaying one week, end the row */
127 thetime += (time_t)86400; /** ahead 24 hours */
130 wprintf("</table>" /** end of inner table */
133 /* javascript for previous and next month */
134 len = strlen(urlformat);
135 for (i=0; i<len; ++i) {
136 sprintf(&escaped_urlformat[i*2], "%02X", urlformat[i]);
139 wprintf("<script type=\"text/javascript\"> "
140 " function minical_change_month(year, month) { "
141 " p = 'year=' + year + '&month=' + month "
142 " + '&urlformat=%s&r=' + CtdlRandomString(); "
143 " new Ajax.Updater('%s', 'mini_calendar', "
144 " { method: 'get', parameters: p, evalScripts: true } ); "
148 escaped_urlformat, div_id
153 /* ajax embedder for the above mini calendar */
154 void ajax_mini_calendar(void) {
157 char *escaped_urlformat;
159 escaped_urlformat = bstr("urlformat");
160 len = strlen(escaped_urlformat) * 2 ;
161 for (i=0; i<len; ++i) {
162 urlformat[i] = xtoi(&escaped_urlformat[i*2], 2);
166 embeddable_mini_calendar( atoi(bstr("year")), atoi(bstr("month")), urlformat );
171 * \brief Display one day of a whole month view of a calendar
172 * \param thetime the month we want to see
174 void calendar_month_view_display_events(int year, int month, int day)
177 icalproperty *p = NULL;
178 icalproperty *q = NULL;
179 struct icaltimetype t;
180 struct icaltimetype end_t;
181 struct icaltimetype today_start_t;
182 struct icaltimetype today_end_t;
183 struct tm starting_tm;
185 int all_day_event = 0;
188 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
189 struct disp_cal *Cal;
192 if (WCC->num_cal == 0) {
193 wprintf("<br /><br /><br />\n");
197 /* Create an imaginary event which spans the 24 hours of today. Any events which
198 * overlap with this one take place at least partially in this day. We have to
199 * convert it from a struct tm in order to make it UTC.
201 memset(&starting_tm, 0, sizeof(struct tm));
202 starting_tm.tm_year = year - 1900;
203 starting_tm.tm_mon = month - 1;
204 starting_tm.tm_mday = day;
205 starting_tm.tm_hour = 0;
206 starting_tm.tm_min = 0;
207 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
208 today_start_t.is_utc = 1;
210 memset(&ending_tm, 0, sizeof(struct tm));
211 ending_tm.tm_year = year - 1900;
212 ending_tm.tm_mon = month - 1;
213 ending_tm.tm_mday = day;
214 ending_tm.tm_hour = 23;
215 ending_tm.tm_min = 59;
216 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
217 today_end_t.is_utc = 1;
219 /* Now loop through our list of events to see which ones occur today.
221 for (i=0; i<(WCC->num_cal); ++i) {
222 Cal = &WCC->disp_cal[i];
224 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
226 t = icalproperty_get_dtstart(q);
229 memset(&t, 0, sizeof t);
231 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
233 end_t = icalproperty_get_dtend(q);
236 memset(&end_t, 0, sizeof end_t);
238 if (t.is_date) all_day_event = 1;
242 show_event = ((t.year == year) && (t.month == month) && (t.day == day));
246 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
249 /* If we determined that this event occurs today, then display it.
252 p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
256 wprintf("<table border=0 cellpadding=2><TR>"
257 "<td bgcolor=\"#CCCCDD\">"
261 wprintf("<font size=-1>"
262 "<a href=\"display_edit_event?"
263 "msgnum=%ld&calview=month&year=%d&month=%d&day=%d\""
265 WC->disp_cal[i].cal_msgnum,
269 wprintf("<i>%s</i> ", _("Summary:"));
270 escputs((char *)icalproperty_get_comment(p));
273 q = icalcomponent_get_first_property(
275 ICAL_LOCATION_PROPERTY);
277 wprintf("<i>%s</i> ", _("Location:"));
278 escputs((char *)icalproperty_get_comment(q));
283 * Only show start/end times if we're actually looking at the VEVENT
284 * component. Otherwise it shows bogus dates for e.g. timezones
286 if (icalcomponent_isa(Cal->cal) == ICAL_VEVENT_COMPONENT) {
288 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
290 t = icalproperty_get_dtstart(q);
295 memset(&d_tm, 0, sizeof d_tm);
296 d_tm.tm_year = t.year - 1900;
297 d_tm.tm_mon = t.month - 1;
298 d_tm.tm_mday = t.day;
299 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
300 wprintf("<i>%s</i> %s<br>",
304 tt = icaltime_as_timet(t);
305 webcit_fmt_date(buf, tt, 1);
306 wprintf("<i>%s</i> %s<br>",
307 _("Starting date/time:"), buf);
309 /* Embed the 'show end date/time' loop inside here so it
310 * only executes if this is NOT an all day event.
312 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
314 t = icalproperty_get_dtend(q);
315 tt = icaltime_as_timet(t);
316 webcit_fmt_date(buf, tt, 1);
317 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
325 q = icalcomponent_get_first_property(Cal->cal, ICAL_DESCRIPTION_PROPERTY);
327 wprintf("<i>%s</i> ", _("Notes:"));
328 escputs((char *)icalproperty_get_comment(q));
334 icalproperty_get_comment(p));
335 wprintf("</a></font><br />\n");
338 wprintf("</td></tr></table>");
351 * \brief Display one day of a whole month view of a calendar
352 * \param thetime the month we want to see
354 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
364 struct icaltimetype t;
365 int month, day, year;
366 int all_day_event = 0;
370 time_format = get_time_format_cached ();
372 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
373 else timeformat="%I:%M %p";
375 localtime_r(&thetime, &today_tm);
376 month = today_tm.tm_mon + 1;
377 day = today_tm.tm_mday;
378 year = today_tm.tm_year + 1900;
380 for (i=0; i<(WC->num_cal); ++i) {
381 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
382 ICAL_DTSTART_PROPERTY);
384 t = icalproperty_get_dtstart(p);
385 event_tt = icaltime_as_timet(t);
387 if (t.is_date) all_day_event = 1;
388 else all_day_event = 0;
391 gmtime_r(&event_tts, &event_tms);
394 localtime_r(&event_tts, &event_tms);
396 /** \todo epoch &! daymask */
397 if ((event_tms.tm_year == today_tm.tm_year)
398 && (event_tms.tm_mon == today_tm.tm_mon)
399 && (event_tms.tm_mday == today_tm.tm_mday)) {
405 p = icalcomponent_get_first_property(
407 ICAL_SUMMARY_PROPERTY);
408 e = icalcomponent_get_first_property(
410 ICAL_DTEND_PROPERTY);
411 if ((p != NULL) && (e != NULL)) {
414 t = icalproperty_get_dtend(e);
415 event_tte = icaltime_as_timet(t);
416 localtime_r(&event_tte, &event_tme);
417 difftime=(event_tte-event_tts)/60;
418 hours=(int)(difftime / 60);
419 minutes=difftime % 60;
420 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
422 "<a href=\"display_edit_event?msgnum=%ld&calview=calbrief&year=%s&month=%s&day=%s\">",
426 WC->disp_cal[i].cal_msgnum,
433 icalproperty_get_comment(p));
434 /** \todo: allso ammitime format */
435 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
436 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
438 wprintf("</a></font></td>"
439 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
456 * \brief view one month. pretty view
457 * \param year the year
458 * \param month the month
459 * \param day the actual day we want to see
461 void calendar_month_view(int year, int month, int day) {
462 struct tm starting_tm;
466 time_t previous_month;
468 time_t colheader_time;
469 struct tm colheader_tm;
470 char colheader_label[32];
473 char weekstart_buf[16];
475 /* Determine what day to start.
477 get_preference("weekstart", weekstart_buf, sizeof weekstart_buf);
478 weekstart = atoi(weekstart_buf);
481 * Now back up to the 1st of the month...
483 memset(&starting_tm, 0, sizeof(struct tm));
485 starting_tm.tm_year = year - 1900;
486 starting_tm.tm_mon = month - 1;
487 starting_tm.tm_mday = day;
488 thetime = mktime(&starting_tm);
490 memcpy(&tm, &starting_tm, sizeof(struct tm));
491 while (tm.tm_mday != 1) {
492 thetime = thetime - (time_t)86400; /* go back 24 hours */
493 localtime_r(&thetime, &tm);
496 /** Determine previous and next months ... for links */
497 previous_month = thetime - (time_t)864000L; /* back 10 days */
498 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
500 /** Now back up until we're on the user's preferred start day */
501 localtime_r(&thetime, &tm);
502 while (tm.tm_wday != weekstart) {
503 thetime = thetime - (time_t)86400; /* go back 24 hours */
504 localtime_r(&thetime, &tm);
507 /** Outer table (to get the background color) */
508 wprintf("<div class=\"fix_scrollbar_bug\">"
509 "<table class=\"calendar\"> \n <tr><td>");
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(colheader_label, sizeof colheader_label, "%B", &starting_tm);
521 wprintf(" "
522 "<font size=+1 color=\"#FFFFFF\">"
525 " ", colheader_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=#204B78 id=\"inner_month\"><tr>");
537 colheader_time = thetime;
538 for (i=0; i<7; ++i) {
539 colheader_time = thetime + (i * 86400) ;
540 localtime_r(&colheader_time, &colheader_tm);
541 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
542 wprintf("<th align=center width=14%%>"
543 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
549 /** Now do 35 or 42 days */
550 for (i = 0; i < 42; ++i) {
551 localtime_r(&thetime, &tm);
553 if ((i < 35) || (chg_month == 0)) {
555 if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) {
562 /** Before displaying Sunday, start a new row */
567 wprintf("<td class=\"cal%s\"><div class=\"day\">",
568 ((tm.tm_mon != month-1) ? "out" :
569 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
572 if ((i==0) || (tm.tm_mday == 1)) {
573 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
574 wprintf("%s ", colheader_label);
576 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
583 /** put the data here, stupid */
584 calendar_month_view_display_events(
592 /** After displaying Saturday, end the row */
599 thetime += (time_t)86400; /** ahead 24 hours */
602 wprintf("</table>" /** end of inner table */
603 "</td></tr></table>" /** end of outer table */
607 * Initialize the bubble tooltips.
609 * Yes, this is as stupid as it looks. Instead of just making the call
610 * to btt_enableTooltips() straight away, we have to create a timer event
611 * and let it initialize as an event after 1 millisecond. This is to
612 * work around a bug in Internet Explorer that causes it to crash if we
613 * manipulate the innerHTML of various DOM nodes while the page is still
614 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
615 * for more information.
617 wprintf("<script type=\"text/javascript\">"
618 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
624 * \brief view one month. brief view
625 * \param year the year
626 * \param month the month
627 * \param day the actual day we want to see
629 void calendar_brief_month_view(int year, int month, int day) {
630 struct tm starting_tm;
634 time_t previous_month;
636 char month_label[32];
638 /** Determine what day to start.
639 * First, back up to the 1st of the month...
641 memset(&starting_tm, 0, sizeof(struct tm));
642 starting_tm.tm_year = year - 1900;
643 starting_tm.tm_mon = month - 1;
644 starting_tm.tm_mday = day;
645 thetime = mktime(&starting_tm);
647 memcpy(&tm, &starting_tm, sizeof(struct tm));
648 while (tm.tm_mday != 1) {
649 thetime = thetime - (time_t)86400; /* go back 24 hours */
650 localtime_r(&thetime, &tm);
653 /** Determine previous and next months ... for links */
654 previous_month = thetime - (time_t)864000L; /* back 10 days */
655 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
657 /** Now back up until we're on a Sunday */
658 localtime_r(&thetime, &tm);
659 while (tm.tm_wday != 0) {
660 thetime = thetime - (time_t)86400; /* go back 24 hours */
661 localtime_r(&thetime, &tm);
664 /** Outer table (to get the background color) */
665 wprintf("<div class=\"fix_scrollbar_bug\">"
666 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
667 "bgcolor=#204B78><TR><TD>\n");
669 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
671 wprintf("<td align=center>");
673 localtime_r(&previous_month, &tm);
674 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
675 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
676 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
678 wc_strftime(month_label, sizeof month_label, "%B", &tm);
679 wprintf(" "
680 "<font size=+1 color=\"#FFFFFF\">"
683 " ", month_label, year);
685 localtime_r(&next_month, &tm);
686 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
687 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
688 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
690 wprintf("</td></tr></table>\n");
692 /** Inner table (the real one) */
693 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
694 "bgcolor=#EEEECC><TR>");
696 wprintf("<tr><td colspan=\"100%\">\n");
698 /** Now do 35 days */
699 for (i = 0; i < 35; ++i) {
700 char weeknumber[255];
701 char weekday_name[32];
703 localtime_r(&thetime, &tm);
706 /** Before displaying Sunday, start a new CELL */
708 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
709 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
710 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
720 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
721 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
725 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
726 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
727 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
729 weekday_name,tm.tm_mday,
732 /** put the data of one day here, stupid */
733 calendar_month_view_brief_events(thetime, daycolor);
736 /** After displaying Saturday, end the row */
738 wprintf("</td></tr></table>\n");
741 thetime += (time_t)86400; /** ahead 24 hours */
744 wprintf("</table>" /** end of inner table */
745 "</td></tr></table>" /** end of outer table */
750 * \brief view one week
751 * this should view just one week, but it's not here yet.
752 * \todo ny implemented
753 * \param year the year
754 * \param month the month
755 * \param day the day which we want to see the week around
757 void calendar_week_view(int year, int month, int day) {
758 wprintf("<center><i>week view FIXME</i></center><br />\n");
763 * \brief display one day
764 * Display events for a particular hour of a particular day.
765 * (Specify hour < 0 to show "all day" events)
766 * \param year the year
767 * \param month the month
769 * \param hour the hour we want to start displaying
770 * \param dstart daystart
773 void calendar_day_view_display_events(time_t thetime,
782 icalproperty *p = NULL;
783 icalproperty *q = NULL;
789 int all_day_event = 0;
790 int ongoing_event = 0;
791 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
792 struct disp_cal *Cal;
793 struct icaltimetype t;
794 struct icaltimetype end_t;
795 struct icaltimetype today_start_t;
796 struct icaltimetype today_end_t;
797 struct tm starting_tm;
810 if (WCC->num_cal == 0) {
811 /* nothing to display */
815 /* Create an imaginary event which spans the current day. Any events which
816 * overlap with this one take place at least partially in this day.
818 memset(&starting_tm, 0, sizeof(struct tm));
819 starting_tm.tm_year = year - 1900;
820 starting_tm.tm_mon = month - 1;
821 starting_tm.tm_mday = day;
822 starting_tm.tm_hour = 0;
823 starting_tm.tm_min = 0;
824 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
825 today_start_t.is_utc = 1;
827 memset(&ending_tm, 0, sizeof(struct tm));
828 ending_tm.tm_year = year - 1900;
829 ending_tm.tm_mon = month - 1;
830 ending_tm.tm_mday = day;
831 ending_tm.tm_hour = 23;
832 ending_tm.tm_min = 59;
833 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
834 today_end_t.is_utc = 1;
836 /* Now loop through our list of events to see which ones occur today.
838 for (i=0; i<(WCC->num_cal); ++i) {
839 Cal = &WCC->disp_cal[i];
844 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
846 t = icalproperty_get_dtstart(q);
847 event_tt = icaltime_as_timet(t);
848 localtime_r(&event_tt, &event_te);
851 memset(&t, 0, sizeof t);
853 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
855 end_t = icalproperty_get_dtend(q);
856 event_tte = icaltime_as_timet(end_t);
857 localtime_r(&event_tte, &event_tm);
860 memset(&end_t, 0, sizeof end_t);
862 if (t.is_date) all_day_event = 1;
866 show_event = ((t.year == year) && (t.month == month) && (t.day == day) && (notime_events));
870 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
873 /* If we determined that this event occurs today, then display it.
875 p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
877 if ((show_event) && (p != NULL)) {
879 if ((event_te.tm_mday != day) || (event_tm.tm_mday != day)) ongoing_event = 1;
881 if (all_day_event && notime_events)
883 wprintf("<li class=\"event\"> "
884 "<a href=\"display_edit_event?"
885 "msgnum=%ld&calview=day&year=%d&month=%d&day=%d\" "
886 " class=\"event_title\" "
888 Cal->cal_msgnum, year, month, day);
889 wprintf("<i>%s</i><br />", _("All day event"));
890 wprintf("<i>%s</i> ", _("Summary:"));
891 escputs((char *) icalproperty_get_comment(p));
893 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
895 wprintf("<i>%s</i> ", _("Location:"));
896 escputs((char *)icalproperty_get_comment(q));
899 memset(&d_tm, 0, sizeof d_tm);
900 d_tm.tm_year = t.year - 1900;
901 d_tm.tm_mon = t.month - 1;
902 d_tm.tm_mday = t.day;
903 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
904 wprintf("<i>%s</i> %s<br>",_("Date:"), d_str);
905 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
907 wprintf("<i>%s</i> ", _("Notes:"));
908 escputs((char *)icalproperty_get_comment(q));
912 escputs((char *) icalproperty_get_comment(p));
913 wprintf("</a> <span>(");
914 wprintf(_("All day event"));
915 wprintf(")</span></li>\n");
917 else if (ongoing_event && notime_events)
919 wprintf("<li class=\"event\"> "
920 "<a href=\"display_edit_event?"
921 "msgnum=%ld&calview=day&year=%d&month=%d&day=%d\" "
922 " class=\"event_title\" "
924 Cal->cal_msgnum, year, month, day);
925 wprintf("<i>%s</i><br />", _("Ongoing event"));
926 wprintf("<i>%s</i> ", _("Summary:"));
927 escputs((char *) icalproperty_get_comment(p));
929 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
931 wprintf("<i>%s</i> ", _("Location:"));
932 escputs((char *)icalproperty_get_comment(q));
935 webcit_fmt_date(buf, event_tt, 1);
936 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
937 webcit_fmt_date(buf, event_tte, 1);
938 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
939 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
941 wprintf("<i>%s</i> ", _("Notes:"));
942 escputs((char *)icalproperty_get_comment(q));
946 escputs((char *) icalproperty_get_comment(p));
947 wprintf("</a> <span>(");
948 wprintf(_("Ongoing event"));
949 wprintf(")</span></li>\n");
951 else if (!all_day_event && !notime_events)
955 if (event_te.tm_mday != day) event_te.tm_hour = 0;
956 if (event_tm.tm_mday != day) event_tm.tm_hour = 24;
958 /* Calculate the location of the top of the box */
959 if (event_te.tm_hour < dstart) {
960 startmin = diffmin = event_te.tm_min / 6;
961 top = (event_te.tm_hour * 10) + startmin;
963 else if ((event_te.tm_hour >= dstart) && (event_te.tm_hour <= dend)) {
964 startmin = diffmin = (event_te.tm_min / 2);
965 top = (dstart * 10) + ((event_te.tm_hour - dstart) * 30) + startmin;
967 else if (event_te.tm_hour >dend) {
968 startmin = diffmin = event_te.tm_min / 6;
969 top = (dstart * 10) + ((dend - dstart - 1) * 30) + ((event_tm.tm_hour - dend + 1) * 10) + startmin ;
972 /* should never get here */
975 /* Calculate the location of the bottom of the box */
976 if (event_tm.tm_hour < dstart) {
977 endmin = diffmin = event_tm.tm_min / 6;
978 bottom = (event_tm.tm_hour * 10) + endmin;
980 else if ((event_tm.tm_hour >= dstart) && (event_tm.tm_hour <= dend)) {
981 endmin = diffmin = (event_tm.tm_min / 2);
982 bottom = (dstart * 10) + ((event_tm.tm_hour - dstart) * 30) + endmin ;
984 else if (event_tm.tm_hour >dend) {
985 endmin = diffmin = event_tm.tm_min / 6;
986 bottom = (dstart * 10) + ((dend - dstart + 1) * 30) + ((event_tm.tm_hour - dend - 1) * 10) + endmin;
989 /* should never get here */
992 wprintf("<dd class=\"event\" "
993 "style=\"position: absolute; "
994 "top:%dpx; left:%dpx; "
996 top, (gap * 40), (bottom-top)
998 wprintf("<a href=\"display_edit_event?"
999 "msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\" "
1000 "class=\"event_title\" "
1002 Cal->cal_msgnum, year, month, day, t.hour);
1003 wprintf("<i>%s</i> ", _("Summary:"));
1004 escputs((char *) icalproperty_get_comment(p));
1006 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
1008 wprintf("<i>%s</i> ", _("Location:"));
1009 escputs((char *)icalproperty_get_comment(q));
1012 webcit_fmt_date(buf, event_tt, 1);
1013 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
1014 webcit_fmt_date(buf, event_tte, 1);
1015 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
1016 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
1018 wprintf("<i>%s</i> ", _("Notes:"));
1019 escputs((char *)icalproperty_get_comment(q));
1024 escputs((char *) icalproperty_get_comment(p));
1025 wprintf("</a></dd>\n");
1032 * \brief view one day
1033 * \param year the year
1034 * \param month the month
1035 * \param day the day we want to display
1037 void calendar_day_view(int year, int month, int day) {
1039 struct icaltimetype today, yesterday, tomorrow;
1042 char daystart_str[16], dayend_str[16];
1048 int extratimeline = 0;
1051 time_format = get_time_format_cached ();
1052 get_preference("daystart", daystart_str, sizeof daystart_str);
1053 if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
1054 get_preference("dayend", dayend_str, sizeof dayend_str);
1055 if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str);
1058 memset(&d_tm, 0, sizeof d_tm);
1059 d_tm.tm_year = year - 1900;
1060 d_tm.tm_mon = month - 1;
1062 today_t = mktime(&d_tm);
1064 /** Figure out the dates for "yesterday" and "tomorrow" links */
1066 memset(&today, 0, sizeof(struct icaltimetype));
1068 today.month = month;
1072 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
1074 yesterday = icaltime_normalize(yesterday);
1076 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
1078 tomorrow = icaltime_normalize(tomorrow);
1080 wprintf("<div class=\"fix_scrollbar_bug\">");
1082 /** Inner table (the real one) */
1083 wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
1085 /** Innermost cell (contains hours etc.) */
1086 wprintf("<td class=\"events_of_the_day\" >");
1087 wprintf("<dl class=\"events\" >");
1089 /** Now the middle of the day... */
1091 extratimeline = timeline / 3;
1093 for (hour = 0; hour < daystart; ++hour) { /* could do HEIGHT=xx */
1094 wprintf("<dt class=\"extrahour\" "
1096 "position: absolute; "
1097 "top: %dpx; left: 0px; "
1100 "<a href=\"display_edit_event?msgnum=0"
1101 "&calview=day&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
1102 (hour * extratimeline ), extratimeline,
1103 year, month, day, hour
1106 if (time_format == WC_TIMEFORMAT_24) {
1107 wprintf("%2d:00</a> ", hour);
1110 wprintf("%d:00%s</a> ",
1111 (hour <= 12 ? hour : hour-12),
1112 (hour < 12 ? "am" : "pm")
1119 gap = daystart * extratimeline;
1121 for (hour = daystart; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
1122 wprintf("<dt class=\"hour\" "
1124 "position: absolute; "
1125 "top: %dpx; left: 0px; "
1128 "<a href=\"display_edit_event?msgnum=0&calview=day"
1129 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
1130 gap + ((hour - daystart) * timeline ), timeline,
1131 year, month, day, hour
1134 if (time_format == WC_TIMEFORMAT_24) {
1135 wprintf("%2d:00</a> ", hour);
1138 wprintf("%d:00%s</a> ",
1139 (hour <= 12 ? hour : hour-12),
1140 (hour < 12 ? "am" : "pm")
1147 gap = gap + ((dayend - daystart + 1) * timeline);
1149 for (hour = (dayend + 1); hour < 24; ++hour) { /* could do HEIGHT=xx */
1150 wprintf("<dt class=\"extrahour\" "
1152 "position: absolute; "
1153 "top: %dpx; left: 0px; "
1156 "<a href=\"display_edit_event?msgnum=0&calview=day"
1157 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
1158 gap + ((hour - dayend - 1) * extratimeline ), extratimeline,
1159 year, month, day, hour
1162 if (time_format == WC_TIMEFORMAT_24) {
1163 wprintf("%2d:00</a> ", hour);
1166 wprintf("%d:00%s</a> ",
1167 (hour <= 12 ? hour : hour-12),
1168 (hour < 12 ? "am" : "pm")
1175 /* Display events with start and end times on this day */
1176 calendar_day_view_display_events(today_t, year, month, day, 0, daystart, dayend);
1179 wprintf("</td>"); /* end of innermost table */
1181 /** Display extra events (start/end times not present or not today) in the middle column */
1182 wprintf("<td class=\"extra_events\">");
1186 /** Display all-day events */
1187 calendar_day_view_display_events(today_t, year, month, day, 1, daystart, dayend);
1191 wprintf("</td>"); /** end extra on the middle */
1193 wprintf("<td width=20%% align=center valign=top>"); /** begin stuff-on-the-right */
1195 /** Begin todays-date-with-left-and-right-arrows */
1196 wprintf("<table border=0 width=100%% "
1197 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
1201 wprintf("<td align=center>");
1202 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
1203 yesterday.year, yesterday.month, yesterday.day);
1204 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
1207 wc_strftime(d_str, sizeof d_str,
1209 "<font size=+2>%B</font><br />"
1210 "<font size=+3>%d</font><br />"
1211 "<font size=+2>%Y</font><br />"
1215 wprintf("%s", d_str);
1218 wprintf("<td align=center>");
1219 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
1220 tomorrow.year, tomorrow.month, tomorrow.day);
1221 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
1222 " border=0></a>\n");
1225 wprintf("</tr></table>\n");
1226 /** End todays-date-with-left-and-right-arrows */
1228 /** Embed a mini month calendar in this space */
1229 wprintf("<br />\n");
1230 embeddable_mini_calendar(year, month, "readfwd?calview=day&year=%d&month=%d&day=%d");
1232 wprintf("</font></center>\n");
1234 wprintf("</td></tr>"); /** end stuff-on-the-right */
1236 wprintf("</table>" /** end of inner table */
1239 wprintf("<script type=\"text/javascript\">"
1240 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); "
1247 * \brief Display today's events.
1249 void calendar_summary_view(void) {
1252 struct icaltimetype t;
1257 int all_day_event = 0;
1258 char timestring[SIZ];
1260 if (WC->num_cal == 0) {
1265 localtime_r(&now, &today_tm);
1267 for (i=0; i<(WC->num_cal); ++i) {
1268 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1269 ICAL_DTSTART_PROPERTY);
1271 t = icalproperty_get_dtstart(p);
1272 event_tt = icaltime_as_timet(t);
1279 fmt_time(timestring, event_tt);
1281 if (all_day_event) {
1282 gmtime_r(&event_tt, &event_tm);
1285 localtime_r(&event_tt, &event_tm);
1288 if ( (event_tm.tm_year == today_tm.tm_year)
1289 && (event_tm.tm_mon == today_tm.tm_mon)
1290 && (event_tm.tm_mday == today_tm.tm_mday)
1294 p = icalcomponent_get_first_property(
1295 WC->disp_cal[i].cal,
1296 ICAL_SUMMARY_PROPERTY);
1299 icalproperty_get_comment(p));
1300 wprintf(" (%s)<br />\n", timestring);
1305 free_calendar_buffer();
1310 * \brief clean up ical memory
1311 * \todo this could get troubel with future ical versions
1313 void free_calendar_buffer(void) {
1315 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1316 icalcomponent_free(WC->disp_cal[i].cal);
1320 WC->disp_cal = NULL;
1326 * \brief do the whole calendar page
1327 * view any part of the calender. decide which way, etc.
1329 void do_calendar_view(void) {
1332 int year, month, day;
1335 /** In case no date was specified, go with today */
1337 localtime_r(&now, &tm);
1338 year = tm.tm_year + 1900;
1339 month = tm.tm_mon + 1;
1342 /** Now see if a date was specified */
1343 if (!IsEmptyStr(bstr("year"))) year = atoi(bstr("year"));
1344 if (!IsEmptyStr(bstr("month"))) month = atoi(bstr("month"));
1345 if (!IsEmptyStr(bstr("day"))) day = atoi(bstr("day"));
1347 /** How would you like that cooked? */
1348 if (!IsEmptyStr(bstr("calview"))) {
1349 strcpy(calview, bstr("calview"));
1352 strcpy(calview, "month");
1355 /** Display the selected view */
1356 if (!strcasecmp(calview, "day")) {
1357 calendar_day_view(year, month, day);
1359 else if (!strcasecmp(calview, "week")) {
1360 calendar_week_view(year, month, day);
1363 if (WC->wc_view == VIEW_CALBRIEF) {
1364 calendar_brief_month_view(year, month, day);
1367 calendar_month_view(year, month, day);
1371 /** Free the calendar stuff */
1372 free_calendar_buffer();
1378 * \brief get task due date
1379 * Helper function for do_tasks_view().
1380 * \param vtodo a task to get the due date
1381 * \return the date/time due.
1383 time_t get_task_due_date(icalcomponent *vtodo) {
1386 if (vtodo == NULL) {
1391 * If we're looking at a fully encapsulated VCALENDAR
1392 * rather than a VTODO component, recurse into the data
1393 * structure until we get a VTODO.
1395 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1396 return get_task_due_date(
1397 icalcomponent_get_first_component(
1398 vtodo, ICAL_VTODO_COMPONENT
1403 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1405 return(icaltime_as_timet(icalproperty_get_due(p)));
1414 * \brief Compare the due dates of two tasks (this is for sorting)
1415 * \param task1 first task to compare
1416 * \param task2 second task to compare
1418 int task_due_cmp(const void *task1, const void *task2) {
1422 t1 = get_task_due_date(((struct disp_cal *)task1)->cal);
1423 t2 = get_task_due_date(((struct disp_cal *)task2)->cal);
1425 if (t1 < t2) return(-1);
1426 if (t1 > t2) return(1);
1434 * \brief do the whole task view stuff
1436 void do_tasks_view(void) {
1443 wprintf("<div class=\"fix_scrollbar_bug\">"
1444 "<table class=\"calendar_view_background\">\n<tr>\n"
1446 wprintf(_("Name of task"));
1447 wprintf("</th><th>");
1448 wprintf(_("Date due"));
1449 wprintf("</th></tr>\n"
1452 /** Sort them if necessary */
1453 if (WC->num_cal > 1) {
1456 sizeof(struct disp_cal),
1461 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1464 wprintf("<tr bgcolor=\"#%s\"><td>",
1465 (bg ? "DDDDDD" : "FFFFFF")
1468 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1469 ICAL_SUMMARY_PROPERTY);
1470 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1471 WC->disp_cal[i].cal_msgnum );
1472 urlescputs(WC->wc_roomname);
1474 wprintf("<img align=middle "
1475 "src=\"static/taskmanag_16x.gif\" border=0> ");
1477 escputs((char *)icalproperty_get_comment(p));
1482 due = get_task_due_date(WC->disp_cal[i].cal);
1483 webcit_fmt_date(buf, due, 0);
1484 wprintf("<td><font");
1485 if (due < time(NULL)) {
1486 wprintf(" color=\"#FF0000\"");
1488 wprintf(">%s</font></td></tr>\n", buf);
1491 wprintf("</table></div>\n");
1493 /** Free the list */
1494 free_calendar_buffer();
1498 #else /* WEBCIT_WITH_CALENDAR_SERVICE */
1500 /**\brief stub for non-libical builds */
1501 void do_calendar_view(void) {
1502 wprintf("<center><i>");
1503 wprintf(_("The calendar view is not available."));
1504 wprintf("</i></center><br />\n");
1507 /**\brief stub for non-libical builds */
1508 void do_tasks_view(void) {
1509 wprintf("<center><I>");
1510 wprintf(_("The tasks view is not available."));
1511 wprintf("</i></center><br />\n");
1514 /**\brief stub for non-libical builds */
1515 void ajax_mini_calendar(void) {
1518 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */