4 * Handles the HTML display of calendar items.
10 /* These define how high the hour rows are in the day view */
12 #define EXTRATIMELINE (TIMELINE / 2)
14 void embeddable_mini_calendar(int year, int month)
16 struct tm starting_tm;
20 time_t previous_month;
22 time_t colheader_time;
23 struct tm colheader_tm;
24 char colheader_label[32];
29 snprintf(div_id, sizeof div_id, "mini_calendar_%d", rand() );
31 /* Determine what day to start. If an impossible value is found, start on Sunday.
33 get_pref_long("weekstart", &weekstart, 17);
34 if (weekstart > 6) weekstart = 0;
37 * Now back up to the 1st of the month...
39 memset(&starting_tm, 0, sizeof(struct tm));
41 starting_tm.tm_year = year - 1900;
42 starting_tm.tm_mon = month - 1;
43 starting_tm.tm_mday = 1;
44 thetime = mktime(&starting_tm);
46 memcpy(&tm, &starting_tm, sizeof(struct tm));
47 while (tm.tm_mday != 1) {
48 thetime = thetime - (time_t)86400; /* go back 24 hours */
49 localtime_r(&thetime, &tm);
52 /* Determine previous and next months ... for links */
53 previous_month = thetime - (time_t)864000L; /* back 10 days */
54 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
56 /* Now back up until we're on the user's preferred start day */
57 localtime_r(&thetime, &tm);
58 while (tm.tm_wday != weekstart) {
59 thetime = thetime - (time_t)86400; /* go back 24 hours */
60 localtime_r(&thetime, &tm);
63 wprintf("<div class=\"mini_calendar\" id=\"%s\">\n", div_id);
65 /* Previous month link */
66 localtime_r(&previous_month, &tm);
67 wprintf("<a href=\"javascript:minical_change_month(%d,%d);\">«</a>",
68 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
70 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
71 wprintf(" "
72 "<span class=\"mini_calendar_month_label\">"
75 " ", colheader_label, year);
78 localtime_r(&next_month, &tm);
79 wprintf("<a href=\"javascript:minical_change_month(%d,%d);\">»</a>",
80 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
82 wprintf("<table border=0 cellpadding=1 cellspacing=1 class=\"mini_calendar_days\">"
84 colheader_time = thetime;
86 colheader_time = thetime + (i * 86400) ;
87 localtime_r(&colheader_time, &colheader_tm);
88 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
89 wprintf("<th>%c</th>", colheader_label[0]);
95 /* Now do 35 or 42 days */
96 for (i = 0; i < 42; ++i) {
97 localtime_r(&thetime, &tm);
101 /* Before displaying Sunday, start a new row */
106 if (tm.tm_mon == month-1) {
107 snprintf(url, sizeof url, "readfwd?calview=day&year=%d&month=%d&day=%d",
108 tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday);
109 wprintf("<td><a href=\"%s\">%d</a></td>", url, tm.tm_mday);
112 wprintf("<td> </td>");
115 /* After displaying one week, end the row */
122 thetime += (time_t)86400; /* ahead 24 hours */
125 wprintf("</table>" /* end of inner table */
128 StrBufAppendPrintf(WC->trailing_javascript,
129 " function minical_change_month(year, month) { \n"
130 " p = 'year=' + year + '&month=' + month \n"
131 " + '&r=' + CtdlRandomString(); \n"
132 " new Ajax.Updater('%s', 'mini_calendar', \n"
133 " { method: 'get', parameters: p, evalScripts: true } ); \n"
142 * ajax embedder for the above mini calendar
144 void ajax_mini_calendar(void)
146 embeddable_mini_calendar( ibstr("year"), ibstr("month"));
151 * Display one day of a whole month view of a calendar
153 void calendar_month_view_display_events(int year, int month, int day)
160 icalproperty *p = NULL;
161 icalproperty *q = NULL;
162 struct icaltimetype t;
163 struct icaltimetype end_t;
164 struct icaltimetype today_start_t;
165 struct icaltimetype today_end_t;
166 struct icaltimetype today_t;
167 struct tm starting_tm;
169 int all_day_event = 0;
175 if (GetCount(WCC->disp_cal_items) == 0) {
176 wprintf("<br /><br /><br />\n");
181 * Create an imaginary event which spans the 24 hours of today. Any events which
182 * overlap with this one take place at least partially in this day. We have to
183 * convert it from a struct tm in order to make it UTC.
185 memset(&starting_tm, 0, sizeof(struct tm));
186 starting_tm.tm_year = year - 1900;
187 starting_tm.tm_mon = month - 1;
188 starting_tm.tm_mday = day;
189 starting_tm.tm_hour = 0;
190 starting_tm.tm_min = 0;
191 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
192 today_start_t.is_utc = 1;
194 memset(&ending_tm, 0, sizeof(struct tm));
195 ending_tm.tm_year = year - 1900;
196 ending_tm.tm_mon = month - 1;
197 ending_tm.tm_mday = day;
198 ending_tm.tm_hour = 23;
199 ending_tm.tm_min = 59;
200 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
201 today_end_t.is_utc = 1;
204 * Create another one without caring about the timezone for all day events.
206 today_t = icaltime_null_date();
208 today_t.month = month;
212 * Now loop through our list of events to see which ones occur today.
214 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
215 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
216 Cal = (disp_cal*)vCal;
218 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
220 t = icalproperty_get_dtstart(q);
223 memset(&t, 0, sizeof t);
225 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
227 end_t = icalproperty_get_dtend(q);
230 memset(&end_t, 0, sizeof end_t);
232 if (t.is_date) all_day_event = 1;
236 show_event = ical_ctdl_is_overlap(t, end_t, today_t, icaltime_null_time());
240 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
244 * If we determined that this event occurs today, then display it.
247 p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
249 p = icalproperty_new_summary(_("Untitled Event"));
250 icalcomponent_add_property(Cal->cal, p);
255 wprintf("<table border=0 cellpadding=2><TR>"
256 "<td bgcolor=\"#CCCCDD\">"
260 wprintf("<font size=\"-1\">"
261 "<a class=\"event%s\" href=\"display_edit_event?"
262 "msgnum=%ld?calview=month?year=%d?month=%d?day=%d\""
264 (Cal->unread)?"_unread":"_read",
269 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
270 wprintf("<i>%s</i> ", _("Summary:"));
271 escputs((char *)icalproperty_get_comment(p));
274 q = icalcomponent_get_first_property(
276 ICAL_LOCATION_PROPERTY);
278 wprintf("<i>%s</i> ", _("Location:"));
279 escputs((char *)icalproperty_get_comment(q));
284 * Only show start/end times if we're actually looking at the VEVENT
285 * component. Otherwise it shows bogus dates for e.g. timezones
287 if (icalcomponent_isa(Cal->cal) == ICAL_VEVENT_COMPONENT) {
289 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
293 t = icalproperty_get_dtstart(q);
294 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
296 end_t = icalproperty_get_dtend(q);
300 * events with starting date/time equal
301 * ending date/time might get only
302 * DTSTART but no DTEND
312 /* end given, have to adjust it */
313 icaltime_adjust(&end_t, -1, 0, 0, 0);
315 memset(&d_tm, 0, sizeof d_tm);
316 d_tm.tm_year = t.year - 1900;
317 d_tm.tm_mon = t.month - 1;
318 d_tm.tm_mday = t.day;
319 wc_strftime(buf, sizeof buf, "%x", &d_tm);
321 if (no_end || !icaltime_compare(t, end_t)) {
322 wprintf("<i>%s</i> %s<br>",
326 wprintf("<i>%s</i> %s<br>",
327 _("Starting date:"), buf);
328 d_tm.tm_year = end_t.year - 1900;
329 d_tm.tm_mon = end_t.month - 1;
330 d_tm.tm_mday = end_t.day;
331 wc_strftime(buf, sizeof buf, "%x", &d_tm);
332 wprintf("<i>%s</i> %s<br>",
333 _("Ending date:"), buf);
337 tt = icaltime_as_timet(t);
338 webcit_fmt_date(buf, 256, tt, DATEFMT_BRIEF);
339 if (no_end || !icaltime_compare(t, end_t)) {
340 wprintf("<i>%s</i> %s<br>",
341 _("Date/time:"), buf);
344 wprintf("<i>%s</i> %s<br>",
345 _("Starting date/time:"), buf);
346 tt = icaltime_as_timet(end_t);
347 webcit_fmt_date(buf, 256, tt, DATEFMT_BRIEF);
348 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
356 q = icalcomponent_get_first_property(Cal->cal, ICAL_DESCRIPTION_PROPERTY);
358 wprintf("<i>%s</i> ", _("Notes:"));
359 escputs((char *)icalproperty_get_comment(q));
365 icalproperty_get_comment(p));
366 wprintf("</a></font><br />\n");
369 wprintf("</td></tr></table>");
383 * Display one day of a whole month view of a calendar
385 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
399 struct icaltimetype t;
401 int month, day, year;
402 int all_day_event = 0;
406 time_format = get_time_format_cached ();
408 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
409 else timeformat="%I:%M %p";
411 localtime_r(&thetime, &today_tm);
412 month = today_tm.tm_mon + 1;
413 day = today_tm.tm_mday;
414 year = today_tm.tm_year + 1900;
416 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
417 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
418 Cal = (disp_cal*)vCal;
419 p = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
421 t = icalproperty_get_dtstart(p);
422 event_tt = icaltime_as_timet(t);
424 if (t.is_date) all_day_event = 1;
425 else all_day_event = 0;
428 gmtime_r(&event_tts, &event_tms);
431 localtime_r(&event_tts, &event_tms);
433 /* \todo epoch &! daymask */
434 if ((event_tms.tm_year == today_tm.tm_year)
435 && (event_tms.tm_mon == today_tm.tm_mon)
436 && (event_tms.tm_mday == today_tm.tm_mday)) {
442 p = icalcomponent_get_first_property(
444 ICAL_SUMMARY_PROPERTY);
446 p = icalproperty_new_summary(_("Untitled Event"));
447 icalcomponent_add_property(Cal->cal, p);
449 e = icalcomponent_get_first_property(
451 ICAL_DTEND_PROPERTY);
452 if ((p != NULL) && (e != NULL)) {
455 t = icalproperty_get_dtend(e);
456 event_tte = icaltime_as_timet(t);
457 localtime_r(&event_tte, &event_tme);
458 difftime=(event_tte-event_tts)/60;
459 hours=(int)(difftime / 60);
460 minutes=difftime % 60;
461 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
463 "<a class=\"event%s\" href=\"display_edit_event?msgnum=%ld?calview=calbrief?year=%s?month=%s?day=%s\">",
466 (Cal->unread)?"_unread":"_read",
475 icalproperty_get_comment(p));
476 /* \todo: allso ammitime format */
477 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
478 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
480 wprintf("</a></font></td>"
481 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
498 * view one month. pretty view
500 void calendar_month_view(int year, int month, int day) {
501 struct tm starting_tm;
505 time_t previous_month;
507 time_t colheader_time;
508 struct tm colheader_tm;
509 char colheader_label[32];
513 * Determine what day to start. If an impossible value is found, start on Sunday.
515 get_pref_long("weekstart", &weekstart, 17);
516 if (weekstart > 6) weekstart = 0;
519 * Now back up to the 1st of the month...
521 memset(&starting_tm, 0, sizeof(struct tm));
523 starting_tm.tm_year = year - 1900;
524 starting_tm.tm_mon = month - 1;
525 starting_tm.tm_mday = day;
526 thetime = mktime(&starting_tm);
528 memcpy(&tm, &starting_tm, sizeof(struct tm));
529 while (tm.tm_mday != 1) {
530 thetime = thetime - (time_t)86400; /* go back 24 hours */
531 localtime_r(&thetime, &tm);
534 /* Determine previous and next months ... for links */
535 previous_month = thetime - (time_t)864000L; /* back 10 days */
536 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
538 /* Now back up until we're on the user's preferred start day */
539 localtime_r(&thetime, &tm);
540 while (tm.tm_wday != weekstart) {
541 thetime = thetime - (time_t)86400; /* go back 24 hours */
542 localtime_r(&thetime, &tm);
545 /* Outer table (to get the background color) */
546 wprintf("<div class=\"fix_scrollbar_bug\">"
547 "<table class=\"calendar\"> \n <tr><td>");
549 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
551 wprintf("<td align=center>");
553 localtime_r(&previous_month, &tm);
554 wprintf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
555 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
556 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
558 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
559 wprintf(" "
560 "<font size=+1 color=\"#FFFFFF\">"
563 " ", colheader_label, year);
565 localtime_r(&next_month, &tm);
566 wprintf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
567 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
568 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
570 wprintf("</td></tr></table>\n");
572 /* Inner table (the real one) */
573 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
574 "bgcolor=#204B78 id=\"inner_month\"><tr>");
575 colheader_time = thetime;
576 for (i=0; i<7; ++i) {
577 colheader_time = thetime + (i * 86400) ;
578 localtime_r(&colheader_time, &colheader_tm);
579 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
580 wprintf("<th align=center width=14%%>"
581 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
587 /* Now do 35 or 42 days */
588 localtime_r(&thetime, &tm);
589 for (i = 0; i<42; ++i) {
591 /* Before displaying the first day of the week, start a new row */
596 wprintf("<td class=\"cal%s\"><div class=\"day\">",
597 ((tm.tm_mon != month-1) ? "out" :
598 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
601 if ((i==0) || (tm.tm_mday == 1)) {
602 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
603 wprintf("%s ", colheader_label);
605 wprintf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">"
612 /* put the data here, stupid */
613 calendar_month_view_display_events(
621 /* After displaying the last day of the week, end the row */
626 thetime += (time_t)86400; /* ahead 24 hours */
627 localtime_r(&thetime, &tm);
629 if ( ((i % 7) == 6) && (tm.tm_mon != month-1) && (tm.tm_mday < 15) ) {
630 i = 100; /* break out of the loop */
634 wprintf("</table>" /* end of inner table */
635 "</td></tr></table>" /* end of outer table */
639 * Initialize the bubble tooltips.
641 * Yes, this is as stupid as it looks. Instead of just making the call
642 * to btt_enableTooltips() straight away, we have to create a timer event
643 * and let it initialize as an event after 1 millisecond. This is to
644 * work around a bug in Internet Explorer that causes it to crash if we
645 * manipulate the innerHTML of various DOM nodes while the page is still
646 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
647 * for more information.
649 StrBufAppendPrintf(WC->trailing_javascript,
650 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); \n"
655 * view one month. brief view
657 void calendar_brief_month_view(int year, int month, int day) {
658 struct tm starting_tm;
662 time_t previous_month;
664 char month_label[32];
666 /* Determine what day to start.
667 * First, back up to the 1st of the month...
669 memset(&starting_tm, 0, sizeof(struct tm));
670 starting_tm.tm_year = year - 1900;
671 starting_tm.tm_mon = month - 1;
672 starting_tm.tm_mday = day;
673 thetime = mktime(&starting_tm);
675 memcpy(&tm, &starting_tm, sizeof(struct tm));
676 while (tm.tm_mday != 1) {
677 thetime = thetime - (time_t)86400; /* go back 24 hours */
678 localtime_r(&thetime, &tm);
681 /* Determine previous and next months ... for links */
682 previous_month = thetime - (time_t)864000L; /* back 10 days */
683 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
685 /* Now back up until we're on a Sunday */
686 localtime_r(&thetime, &tm);
687 while (tm.tm_wday != 0) {
688 thetime = thetime - (time_t)86400; /* go back 24 hours */
689 localtime_r(&thetime, &tm);
692 /* Outer table (to get the background color) */
693 wprintf("<div class=\"fix_scrollbar_bug\">"
694 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
695 "bgcolor=#204B78><TR><TD>\n");
697 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
699 wprintf("<td align=center>");
701 localtime_r(&previous_month, &tm);
702 wprintf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
703 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
704 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
706 wc_strftime(month_label, sizeof month_label, "%B", &tm);
707 wprintf(" "
708 "<font size=+1 color=\"#FFFFFF\">"
711 " ", month_label, year);
713 localtime_r(&next_month, &tm);
714 wprintf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
715 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
716 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
718 wprintf("</td></tr></table>\n");
720 /* Inner table (the real one) */
721 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
722 "bgcolor=#EEEECC><TR>");
724 wprintf("<tr><td colspan=\"100%%\">\n");
727 for (i = 0; i < 35; ++i) {
728 char weeknumber[255];
729 char weekday_name[32];
731 localtime_r(&thetime, &tm);
734 /* Before displaying Sunday, start a new CELL */
736 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
737 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%%'> <tr><th colspan='4'>%s %s</th></tr>"
738 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
748 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
749 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
753 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
754 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
755 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
757 weekday_name,tm.tm_mday,
760 /* put the data of one day here, stupid */
761 calendar_month_view_brief_events(thetime, daycolor);
764 /* After displaying Saturday, end the row */
766 wprintf("</td></tr></table>\n");
769 thetime += (time_t)86400; /* ahead 24 hours */
772 wprintf("</table>" /* end of inner table */
773 "</td></tr></table>" /* end of outer table */
778 * Calendar week view -- not implemented yet, this is a stub function
780 void calendar_week_view(int year, int month, int day) {
781 wprintf("<center><i>week view FIXME</i></center><br />\n");
787 * Display events for a particular hour of a particular day.
788 * (Specify hour < 0 to show "all day" events)
790 * dstart and dend indicate which hours our "daytime" begins and end
792 void calendar_day_view_display_events(time_t thetime,
804 icalproperty *p = NULL;
805 icalproperty *q = NULL;
811 int all_day_event = 0;
812 int ongoing_event = 0;
815 struct icaltimetype t;
816 struct icaltimetype end_t;
817 struct icaltimetype today_start_t;
818 struct icaltimetype today_end_t;
819 struct icaltimetype today_t;
820 struct tm starting_tm;
831 if (GetCount(WCC->disp_cal_items) == 0) {
832 /* nothing to display */
836 /* Create an imaginary event which spans the current day. Any events which
837 * overlap with this one take place at least partially in this day.
839 memset(&starting_tm, 0, sizeof(struct tm));
840 starting_tm.tm_year = year - 1900;
841 starting_tm.tm_mon = month - 1;
842 starting_tm.tm_mday = day;
843 starting_tm.tm_hour = 0;
844 starting_tm.tm_min = 0;
845 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
846 today_start_t.is_utc = 1;
848 memset(&ending_tm, 0, sizeof(struct tm));
849 ending_tm.tm_year = year - 1900;
850 ending_tm.tm_mon = month - 1;
851 ending_tm.tm_mday = day;
852 ending_tm.tm_hour = 23;
853 ending_tm.tm_min = 59;
854 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
855 today_end_t.is_utc = 1;
858 * Create another one without caring about the timezone for all day events.
860 today_t = icaltime_null_date();
862 today_t.month = month;
865 /* Now loop through our list of events to see which ones occur today.
867 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
868 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
869 Cal = (disp_cal*)vCal;
874 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
876 t = icalproperty_get_dtstart(q);
877 event_tt = icaltime_as_timet(t);
878 localtime_r(&event_tt, &event_te);
881 memset(&t, 0, sizeof t);
884 if (t.is_date) all_day_event = 1;
886 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
888 end_t = icalproperty_get_dtend(q);
891 /* no end given means end = start */
892 memcpy(&end_t, &t, sizeof(struct icaltimetype));
897 show_event = ical_ctdl_is_overlap(t, end_t, today_t, icaltime_null_time());
898 if (icaltime_compare(t, end_t)) {
900 * the end date is non-inclusive so adjust it by one
901 * day because our test is inclusive, note that a day is
902 * not to much because we are talking about all day
905 icaltime_adjust(&end_t, -1, 0, 0, 0);
910 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
913 event_tte = icaltime_as_timet(end_t);
914 localtime_r(&event_tte, &event_tm);
916 /* If we determined that this event occurs today, then display it.
918 p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
920 p = icalproperty_new_summary(_("Untitled Event"));
921 icalcomponent_add_property(Cal->cal, p);
924 if ((show_event) && (p != NULL)) {
926 if ((event_te.tm_mday != day) || (event_tm.tm_mday != day)) ongoing_event = 1;
928 if (all_day_event && notime_events)
930 wprintf("<li class=\"event_framed%s\"> "
931 "<a href=\"display_edit_event?"
932 "msgnum=%ld?calview=day?year=%d?month=%d?day=%d\" "
933 " class=\"event_title\" "
935 (Cal->unread)?"_unread":"_read",
936 Cal->cal_msgnum, year, month, day);
937 wprintf("<i>%s</i><br />", _("All day event"));
938 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
939 wprintf("<i>%s</i> ", _("Summary:"));
940 escputs((char *) icalproperty_get_comment(p));
942 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
944 wprintf("<i>%s</i> ", _("Location:"));
945 escputs((char *)icalproperty_get_comment(q));
948 if (!icaltime_compare(t, end_t)) { /* one day only */
949 webcit_fmt_date(buf, 256, event_tt, DATEFMT_LOCALEDATE);
950 wprintf("<i>%s</i> %s<br>", _("Date:"), buf);
953 webcit_fmt_date(buf, 256, event_tt, DATEFMT_LOCALEDATE);
954 wprintf("<i>%s</i> %s<br>", _("Starting date:"), buf);
955 webcit_fmt_date(buf, 256, event_tte, DATEFMT_LOCALEDATE);
956 wprintf("<i>%s</i> %s<br>", _("Ending date:"), buf);
958 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
960 wprintf("<i>%s</i> ", _("Notes:"));
961 escputs((char *)icalproperty_get_comment(q));
965 escputs((char *) icalproperty_get_comment(p));
966 wprintf("</a> <span>(");
967 wprintf(_("All day event"));
968 wprintf(")</span></li>\n");
970 else if (ongoing_event && notime_events)
972 wprintf("<li class=\"event_framed%s\"> "
973 "<a href=\"display_edit_event?"
974 "msgnum=%ld&calview=day?year=%d?month=%d?day=%d\" "
975 " class=\"event_title\" "
977 (Cal->unread)?"_unread":"_read",
978 Cal->cal_msgnum, year, month, day);
979 wprintf("<i>%s</i><br />", _("Ongoing event"));
980 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
981 wprintf("<i>%s</i> ", _("Summary:"));
982 escputs((char *) icalproperty_get_comment(p));
984 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
986 wprintf("<i>%s</i> ", _("Location:"));
987 escputs((char *)icalproperty_get_comment(q));
990 webcit_fmt_date(buf, 256, event_tt, DATEFMT_BRIEF);
991 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
992 webcit_fmt_date(buf, 256, event_tte, DATEFMT_BRIEF);
993 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
994 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
996 wprintf("<i>%s</i> ", _("Notes:"));
997 escputs((char *)icalproperty_get_comment(q));
1001 escputs((char *) icalproperty_get_comment(p));
1002 wprintf("</a> <span>(");
1003 wprintf(_("Ongoing event"));
1004 wprintf(")</span></li>\n");
1006 else if (!all_day_event && !notime_events)
1010 if (event_te.tm_mday != day) event_te.tm_hour = 0;
1011 if (event_tm.tm_mday != day) event_tm.tm_hour = 24;
1013 /* Calculate the location of the top of the box */
1014 if (event_te.tm_hour < dstart) {
1015 startmin = diffmin = event_te.tm_min / 6;
1016 top = (event_te.tm_hour * EXTRATIMELINE) + startmin;
1018 else if ((event_te.tm_hour >= dstart) && (event_te.tm_hour <= dend)) {
1019 startmin = diffmin = (event_te.tm_min / 2);
1020 top = (dstart * EXTRATIMELINE) + ((event_te.tm_hour - dstart) * TIMELINE) + startmin;
1022 else if (event_te.tm_hour >dend) {
1023 startmin = diffmin = event_te.tm_min / 6;
1024 top = (dstart * EXTRATIMELINE) + ((dend - dstart - 1) * TIMELINE) + ((event_tm.tm_hour - dend + 1) * EXTRATIMELINE) + startmin ;
1027 /* should never get here */
1030 /* Calculate the location of the bottom of the box */
1031 if (event_tm.tm_hour < dstart) {
1032 endmin = diffmin = event_tm.tm_min / 6;
1033 bottom = (event_tm.tm_hour * EXTRATIMELINE) + endmin;
1035 else if ((event_tm.tm_hour >= dstart) && (event_tm.tm_hour <= dend)) {
1036 endmin = diffmin = (event_tm.tm_min / 2);
1037 bottom = (dstart * EXTRATIMELINE) + ((event_tm.tm_hour - dstart) * TIMELINE) + endmin ;
1039 else if (event_tm.tm_hour >dend) {
1040 endmin = diffmin = event_tm.tm_min / 6;
1041 bottom = (dstart * EXTRATIMELINE) + ((dend - dstart + 1) * TIMELINE) + ((event_tm.tm_hour - dend - 1) * EXTRATIMELINE) + endmin;
1044 /* should never get here */
1047 wprintf("<dd class=\"event_framed%s\" "
1048 "style=\"position: absolute; "
1049 "top:%dpx; left:%dpx; "
1050 "height:%dpx; \" >",
1051 (Cal->unread)?"_unread":"_read",
1052 top, (gap * 40), (bottom-top)
1054 wprintf("<a href=\"display_edit_event?"
1055 "msgnum=%ld?calview=day?year=%d?month=%d?day=%d?hour=%d\" "
1056 "class=\"event_title\" "
1058 Cal->cal_msgnum, year, month, day, t.hour);
1059 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
1060 wprintf("<i>%s</i> ", _("Summary:"));
1061 escputs((char *) icalproperty_get_comment(p));
1063 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
1065 wprintf("<i>%s</i> ", _("Location:"));
1066 escputs((char *)icalproperty_get_comment(q));
1069 if (!icaltime_compare(t, end_t)) { /* one day only */
1070 webcit_fmt_date(buf, 256, event_tt, DATEFMT_BRIEF);
1071 wprintf("<i>%s</i> %s<br>", _("Date/time:"), buf);
1074 webcit_fmt_date(buf, 256, event_tt, DATEFMT_BRIEF);
1075 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
1076 webcit_fmt_date(buf, 256, event_tte, DATEFMT_BRIEF);
1077 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
1079 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
1081 wprintf("<i>%s</i> ", _("Notes:"));
1082 escputs((char *)icalproperty_get_comment(q));
1087 escputs((char *) icalproperty_get_comment(p));
1088 wprintf("</a></dd>\n");
1092 DeleteHashPos(&Pos);
1098 void calendar_day_view(int year, int month, int day) {
1100 struct icaltimetype today, yesterday, tomorrow;
1107 int timeline = TIMELINE;
1108 int extratimeline = EXTRATIMELINE;
1113 time_format = get_time_format_cached ();
1114 get_pref_long("daystart", &daystart, 8);
1115 get_pref_long("dayend", &dayend, 17);
1117 /* when loading daystart/dayend, replace missing, corrupt, or impossible values with defaults */
1118 if ((daystart < 0) || (dayend < 2) || (daystart >= 23) || (dayend > 23) || (dayend <= daystart)) {
1124 memset(&d_tm, 0, sizeof d_tm);
1125 d_tm.tm_year = year - 1900;
1126 d_tm.tm_mon = month - 1;
1128 today_t = mktime(&d_tm);
1130 /* Figure out the dates for "yesterday" and "tomorrow" links */
1132 memset(&today, 0, sizeof(struct icaltimetype));
1134 today.month = month;
1138 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
1140 yesterday = icaltime_normalize(yesterday);
1142 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
1144 tomorrow = icaltime_normalize(tomorrow);
1146 wprintf("<div class=\"fix_scrollbar_bug\">");
1148 /* Inner table (the real one) */
1149 wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
1151 /* Innermost cell (contains hours etc.) */
1152 wprintf("<td class=\"events_of_the_day\" >");
1153 wprintf("<dl class=\"events\" >");
1155 /* Now the middle of the day... */
1157 extrahourlabel = extratimeline - 2;
1158 hourlabel = extrahourlabel * 150 / 100;
1159 if (hourlabel > (timeline - 2)) hourlabel = timeline - 2;
1161 for (hour = 0; hour < daystart; ++hour) { /* could do HEIGHT=xx */
1162 wprintf("<dt class=\"extrahour\" "
1164 "position: absolute; "
1165 "top: %dpx; left: 0px; "
1169 "<a href=\"display_edit_event?msgnum=0"
1170 "?calview=day?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
1171 (hour * extratimeline ),
1174 year, month, day, hour
1177 if (time_format == WC_TIMEFORMAT_24) {
1178 wprintf("%2d:00</a> ", hour);
1181 wprintf("%d:00%s</a> ",
1182 ((hour == 0) ? 12 : (hour <= 12 ? hour : hour-12)),
1183 (hour < 12 ? "am" : "pm")
1190 gap = daystart * extratimeline;
1192 for (hour = daystart; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
1193 wprintf("<dt class=\"hour\" "
1195 "position: absolute; "
1196 "top: %ldpx; left: 0px; "
1200 "<a href=\"display_edit_event?msgnum=0?calview=day"
1201 "?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
1202 gap + ((hour - daystart) * timeline ),
1205 year, month, day, hour
1208 if (time_format == WC_TIMEFORMAT_24) {
1209 wprintf("%2d:00</a> ", hour);
1212 wprintf("%d:00%s</a> ",
1213 (hour <= 12 ? hour : hour-12),
1214 (hour < 12 ? "am" : "pm")
1221 gap = gap + ((dayend - daystart + 1) * timeline);
1223 for (hour = (dayend + 1); hour < 24; ++hour) { /* could do HEIGHT=xx */
1224 wprintf("<dt class=\"extrahour\" "
1226 "position: absolute; "
1227 "top: %ldpx; left: 0px; "
1231 "<a href=\"display_edit_event?msgnum=0?calview=day"
1232 "?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
1233 gap + ((hour - dayend - 1) * extratimeline ),
1236 year, month, day, hour
1239 if (time_format == WC_TIMEFORMAT_24) {
1240 wprintf("%2d:00</a> ", hour);
1243 wprintf("%d:00%s</a> ",
1244 (hour <= 12 ? hour : hour-12),
1245 (hour < 12 ? "am" : "pm")
1252 /* Display events with start and end times on this day */
1253 calendar_day_view_display_events(today_t, year, month, day, 0, daystart, dayend);
1256 wprintf("</td>"); /* end of innermost table */
1258 /* Display extra events (start/end times not present or not today) in the middle column */
1259 wprintf("<td class=\"extra_events\">");
1263 /* Display all-day events */
1264 calendar_day_view_display_events(today_t, year, month, day, 1, daystart, dayend);
1268 wprintf("</td>"); /* end extra on the middle */
1270 wprintf("<td width=20%% align=center valign=top>"); /* begin stuff-on-the-right */
1272 /* Begin todays-date-with-left-and-right-arrows */
1273 wprintf("<table border=0 width=100%% "
1274 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
1278 wprintf("<td align=center>");
1279 wprintf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">",
1280 yesterday.year, yesterday.month, yesterday.day);
1281 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
1284 wc_strftime(d_str, sizeof d_str,
1286 "<font size=+2>%B</font><br />"
1287 "<font size=+3>%d</font><br />"
1288 "<font size=+2>%Y</font><br />"
1292 wprintf("%s", d_str);
1295 wprintf("<td align=center>");
1296 wprintf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">",
1297 tomorrow.year, tomorrow.month, tomorrow.day);
1298 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
1299 " border=0></a>\n");
1302 wprintf("</tr></table>\n");
1303 /* End todays-date-with-left-and-right-arrows */
1305 /* Embed a mini month calendar in this space */
1306 wprintf("<br />\n");
1307 embeddable_mini_calendar(year, month);
1309 wprintf("</font></center>\n");
1311 wprintf("</td></tr>"); /* end stuff-on-the-right */
1313 wprintf("</table>" /* end of inner table */
1316 StrBufAppendPrintf(WC->trailing_javascript,
1317 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); \n"
1323 * Display today's events. Returns the number of items displayed.
1325 int calendar_summary_view(void) {
1327 const char *HashKey;
1332 struct icaltimetype t;
1337 int all_day_event = 0;
1338 char timestring[SIZ];
1339 wcsession *WCC = WC;
1340 int num_displayed = 0;
1342 if (GetCount(WC->disp_cal_items) == 0) {
1347 localtime_r(&now, &today_tm);
1349 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
1350 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
1351 Cal = (disp_cal*)vCal;
1352 p = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
1354 t = icalproperty_get_dtstart(p);
1355 event_tt = icaltime_as_timet(t);
1362 fmt_time(timestring, SIZ, event_tt);
1364 if (all_day_event) {
1365 gmtime_r(&event_tt, &event_tm);
1368 localtime_r(&event_tt, &event_tm);
1371 if ( (event_tm.tm_year == today_tm.tm_year)
1372 && (event_tm.tm_mon == today_tm.tm_mon)
1373 && (event_tm.tm_mday == today_tm.tm_mday)
1376 p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
1378 p = icalproperty_new_summary(_("Untitled Task"));
1379 icalcomponent_add_property(Cal->cal, p);
1384 if (WCC->wc_view == VIEW_TASKS) {
1385 wprintf("<a href=\"display_edit_task"
1387 "?return_to_summary=1"
1391 escputs(ChrPtr(WCC->wc_roomname));
1395 wprintf("<a href=\"display_edit_event"
1403 today_tm.tm_year + 1900,
1404 today_tm.tm_mon + 1,
1407 escputs(ChrPtr(WCC->wc_roomname));
1410 escputs((char *) icalproperty_get_comment(p));
1411 if (!all_day_event) {
1412 wprintf(" (%s)", timestring);
1414 wprintf("</a><br />\n");
1420 DeleteHashPos(&Pos);
1421 DeleteHash(&WC->disp_cal_items);
1422 return(num_displayed);
1426 * Parse the URL variables in order to determine the scope and display of a calendar view
1428 void parse_calendar_view_request(struct calview *c) {
1434 /* In case no date was specified, go with today */
1436 localtime_r(&now, &tm);
1437 c->year = tm.tm_year + 1900;
1438 c->month = tm.tm_mon + 1;
1439 c->day = tm.tm_mday;
1441 /* Now see if a date was specified */
1442 if (havebstr("year")) c->year = ibstr("year");
1443 if (havebstr("month")) c->month = ibstr("month");
1444 if (havebstr("day")) c->day = ibstr("day");
1446 /* How would you like that cooked? */
1447 if (havebstr("calview")) {
1448 strcpy(calview, bstr("calview"));
1451 strcpy(calview, "month");
1454 /* Display the selected view */
1455 if (!strcasecmp(calview, "day")) {
1456 c->view = calview_day;
1458 else if (!strcasecmp(calview, "week")) {
1459 c->view = calview_week;
1461 else if (!strcasecmp(calview, "summary")) { /* shouldn't ever happen, but just in case */
1462 c->view = calview_day;
1465 if (WC->wc_view == VIEW_CALBRIEF) {
1466 c->view = calview_brief;
1469 c->view = calview_month;
1473 /* Now try and set the lower and upper bounds so that we don't
1474 * burn too many cpu cycles parsing data way in the past or future
1477 tm.tm_year = c->year - 1900;
1478 tm.tm_mon = c->month - 1;
1479 tm.tm_mday = c->day;
1482 if (c->view == calview_month) span = 3888000;
1483 if (c->view == calview_brief) span = 3888000;
1484 if (c->view == calview_week) span = 604800;
1485 if (c->view == calview_day) span = 86400;
1486 if (c->view == calview_summary) span = 86400;
1488 c->lower_bound = now - span;
1489 c->upper_bound = now + span;
1495 * Render a calendar view from data previously loaded into memory
1497 void render_calendar_view(struct calview *c)
1499 if (c->view == calview_day) {
1500 calendar_day_view(c->year, c->month, c->day);
1502 else if (c->view == calview_week) {
1503 calendar_week_view(c->year, c->month, c->day);
1506 if (WC->wc_view == VIEW_CALBRIEF) {
1507 calendar_brief_month_view(c->year, c->month, c->day);
1510 calendar_month_view(c->year, c->month, c->day);
1514 /* Free the in-memory list of calendar items */
1515 DeleteHash(&WC->disp_cal_items);
1520 * Helper function for do_tasks_view(). Returns the due date/time of a vtodo.
1522 time_t get_task_due_date(icalcomponent *vtodo, int *is_date) {
1525 if (vtodo == NULL) {
1530 * If we're looking at a fully encapsulated VCALENDAR
1531 * rather than a VTODO component, recurse into the data
1532 * structure until we get a VTODO.
1534 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1535 return get_task_due_date(
1536 icalcomponent_get_first_component(
1537 vtodo, ICAL_VTODO_COMPONENT
1542 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1544 struct icaltimetype t = icalproperty_get_due(p);
1547 *is_date = t.is_date;
1548 return(icaltime_as_timet(t));
1557 * Compare the due dates of two tasks (this is for sorting)
1559 int task_due_cmp(const void *vtask1, const void *vtask2) {
1560 disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
1561 disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2);
1566 t1 = get_task_due_date(Task1->cal, NULL);
1567 t2 = get_task_due_date(Task2->cal, NULL);
1568 if (t1 < t2) return(-1);
1569 if (t1 > t2) return(1);
1574 * qsort filter to move completed tasks to bottom of task list
1576 int task_completed_cmp(const void *vtask1, const void *vtask2) {
1577 disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
1578 /* disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2); */
1580 icalproperty_status t1 = icalcomponent_get_status((Task1)->cal);
1581 /* icalproperty_status t2 = icalcomponent_get_status(((struct disp_cal *)task2)->cal); */
1583 if (t1 == ICAL_STATUS_COMPLETED)
1591 * do the whole task view stuff
1593 void do_tasks_view(void) {
1595 const char *HashKey;
1603 wcsession *WCC = WC;
1605 wprintf("<div class=\"fix_scrollbar_bug\">"
1606 "<table class=\"calendar_view_background\"><tbody id=\"taskview\">\n<tr>\n"
1608 wprintf(_("Completed?"));
1609 wprintf("</th><th>");
1610 wprintf(_("Name of task"));
1611 wprintf("</th><th>");
1612 wprintf(_("Date due"));
1613 wprintf("</th><th>");
1614 wprintf(_("Category"));
1615 wprintf(" (<select id=\"selectcategory\"><option value=\"showall\">%s</option></select>)</th></tr>\n",
1618 nItems = GetCount(WC->disp_cal_items);
1620 /* Sort them if necessary
1622 SortByPayload(WC->disp_cal_items, task_due_cmp);
1624 * this shouldn't be neccessary, since we sort by the start time.
1627 /* And then again, by completed */
1629 SortByPayload(WC->disp_cal_items,
1630 task_completed_cmp);
1633 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
1634 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
1635 icalproperty_status todoStatus;
1638 Cal = (disp_cal*)vCal;
1639 wprintf("<tr><td>");
1640 todoStatus = icalcomponent_get_status(Cal->cal);
1641 wprintf("<input type=\"checkbox\" name=\"completed\" value=\"completed\" ");
1642 if (todoStatus == ICAL_STATUS_COMPLETED) {
1643 wprintf("checked=\"checked\" ");
1645 wprintf("disabled=\"disabled\">\n</td><td>");
1646 p = icalcomponent_get_first_property(Cal->cal,
1647 ICAL_SUMMARY_PROPERTY);
1648 wprintf("<a href=\"display_edit_task?msgnum=%ld?taskrm=", Cal->cal_msgnum);
1649 urlescputs(ChrPtr(WC->wc_roomname));
1651 /* wprintf("<img align=middle "
1652 "src=\"static/taskmanag_16x.gif\" border=0> "); */
1654 escputs((char *)icalproperty_get_comment(p));
1659 due = get_task_due_date(Cal->cal, &is_date);
1660 wprintf("<td><span");
1662 webcit_fmt_date(buf, SIZ, due, is_date ? DATEFMT_RAWDATE : DATEFMT_FULL);
1668 wprintf("</span></td>");
1670 p = icalcomponent_get_first_property(Cal->cal,
1671 ICAL_CATEGORIES_PROPERTY);
1673 escputs((char *)icalproperty_get_categories(p));
1679 wprintf("</tbody></table></div>\n");
1682 DeleteHash(&WC->disp_cal_items);
1683 DeleteHashPos(&Pos);