4 * Handles the HTML display of calendar items.
11 void embeddable_mini_calendar(int year, int month, char *urlformat)
13 struct tm starting_tm;
17 time_t previous_month;
19 time_t colheader_time;
20 struct tm colheader_tm;
21 char colheader_label[32];
25 char escaped_urlformat[256];
27 snprintf(div_id, sizeof div_id, "mini_calendar_%d", rand() );
29 /* Determine what day to start. If an impossible value is found, start on Sunday.
31 get_pref_long("weekstart", &weekstart, 17);
32 if (weekstart > 6) weekstart = 0;
35 * Now back up to the 1st of the month...
37 memset(&starting_tm, 0, sizeof(struct tm));
39 starting_tm.tm_year = year - 1900;
40 starting_tm.tm_mon = month - 1;
41 starting_tm.tm_mday = 1;
42 thetime = mktime(&starting_tm);
44 memcpy(&tm, &starting_tm, sizeof(struct tm));
45 while (tm.tm_mday != 1) {
46 thetime = thetime - (time_t)86400; /* go back 24 hours */
47 localtime_r(&thetime, &tm);
50 /* Determine previous and next months ... for links */
51 previous_month = thetime - (time_t)864000L; /* back 10 days */
52 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
54 /* Now back up until we're on the user's preferred start day */
55 localtime_r(&thetime, &tm);
56 while (tm.tm_wday != weekstart) {
57 thetime = thetime - (time_t)86400; /* go back 24 hours */
58 localtime_r(&thetime, &tm);
61 wprintf("<div class=\"mini_calendar\" id=\"%s\">\n", div_id);
63 /* Previous month link */
64 localtime_r(&previous_month, &tm);
65 wprintf("<a href=\"javascript:minical_change_month(%d,%d);\">«</a>",
66 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
68 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
69 wprintf(" "
70 "<span class=\"mini_calendar_month_label\">"
73 " ", colheader_label, year);
76 localtime_r(&next_month, &tm);
77 wprintf("<a href=\"javascript:minical_change_month(%d,%d);\">»</a>",
78 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
80 wprintf("<table border=0 cellpadding=1 cellspacing=1 class=\"mini_calendar_days\">"
82 colheader_time = thetime;
84 colheader_time = thetime + (i * 86400) ;
85 localtime_r(&colheader_time, &colheader_tm);
86 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
87 wprintf("<th>%c</th>", colheader_label[0]);
93 /* Now do 35 or 42 days */
94 for (i = 0; i < 42; ++i) {
95 localtime_r(&thetime, &tm);
99 /* Before displaying Sunday, start a new row */
104 if (tm.tm_mon == month-1) {
105 snprintf(url, sizeof url, urlformat,
106 tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday);
107 wprintf("<td><a href=\"%s\">%d</a></td>", url, tm.tm_mday);
110 wprintf("<td> </td>");
113 /* After displaying one week, end the row */
120 thetime += (time_t)86400; /* ahead 24 hours */
123 wprintf("</table>" /* end of inner table */
126 /* javascript for previous and next month */
127 len = strlen(urlformat);
128 for (i=0; i<len; ++i) {
129 sprintf(&escaped_urlformat[i*2], "%02X", urlformat[i]);
132 StrBufAppendPrintf(WC->trailing_javascript,
133 " function minical_change_month(year, month) { \n"
134 " p = 'year=' + year + '&month=' + month \n"
135 " + '&urlformat=%s&r=' + CtdlRandomString(); \n"
136 " new Ajax.Updater('%s', 'mini_calendar', \n"
137 " { method: 'get', parameters: p, evalScripts: true } ); \n"
140 escaped_urlformat, div_id
146 * ajax embedder for the above mini calendar
148 void ajax_mini_calendar(void) {
151 char *escaped_urlformat;
153 escaped_urlformat = bstr("urlformat");
154 len = strlen(escaped_urlformat) * 2 ;
155 for (i=0; i<len; ++i) {
156 urlformat[i] = xtoi(&escaped_urlformat[i*2], 2);
160 embeddable_mini_calendar( ibstr("year"), ibstr("month"), urlformat );
165 * Display one day of a whole month view of a calendar
167 void calendar_month_view_display_events(int year, int month, int day)
174 icalproperty *p = NULL;
175 icalproperty *q = NULL;
176 struct icaltimetype t;
177 struct icaltimetype end_t;
178 struct icaltimetype today_start_t;
179 struct icaltimetype today_end_t;
180 struct tm starting_tm;
182 int all_day_event = 0;
188 if (GetCount(WCC->disp_cal_items) == 0) {
189 wprintf("<br /><br /><br />\n");
194 * Create an imaginary event which spans the 24 hours of today. Any events which
195 * overlap with this one take place at least partially in this day. We have to
196 * convert it from a struct tm in order to make it UTC.
198 memset(&starting_tm, 0, sizeof(struct tm));
199 starting_tm.tm_year = year - 1900;
200 starting_tm.tm_mon = month - 1;
201 starting_tm.tm_mday = day;
202 starting_tm.tm_hour = 0;
203 starting_tm.tm_min = 0;
204 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
205 today_start_t.is_utc = 1;
207 memset(&ending_tm, 0, sizeof(struct tm));
208 ending_tm.tm_year = year - 1900;
209 ending_tm.tm_mon = month - 1;
210 ending_tm.tm_mday = day;
211 ending_tm.tm_hour = 23;
212 ending_tm.tm_min = 59;
213 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
214 today_end_t.is_utc = 1;
217 * Now loop through our list of events to see which ones occur today.
219 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
220 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
221 Cal = (disp_cal*)vCal;
223 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
225 t = icalproperty_get_dtstart(q);
228 memset(&t, 0, sizeof t);
230 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
232 end_t = icalproperty_get_dtend(q);
235 memset(&end_t, 0, sizeof end_t);
237 if (t.is_date) all_day_event = 1;
241 show_event = ((t.year == year) && (t.month == month) && (t.day == day));
245 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 class=\"event%s\" href=\"display_edit_event?"
263 "msgnum=%ld?calview=month?year=%d?month=%d?day=%d\""
265 (Cal->unread)?"_unread":"_read",
270 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
271 wprintf("<i>%s</i> ", _("Summary:"));
272 escputs((char *)icalproperty_get_comment(p));
275 q = icalcomponent_get_first_property(
277 ICAL_LOCATION_PROPERTY);
279 wprintf("<i>%s</i> ", _("Location:"));
280 escputs((char *)icalproperty_get_comment(q));
285 * Only show start/end times if we're actually looking at the VEVENT
286 * component. Otherwise it shows bogus dates for e.g. timezones
288 if (icalcomponent_isa(Cal->cal) == ICAL_VEVENT_COMPONENT) {
290 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
292 t = icalproperty_get_dtstart(q);
297 memset(&d_tm, 0, sizeof d_tm);
298 d_tm.tm_year = t.year - 1900;
299 d_tm.tm_mon = t.month - 1;
300 d_tm.tm_mday = t.day;
301 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
302 wprintf("<i>%s</i> %s<br>",
306 tt = icaltime_as_timet(t);
307 webcit_fmt_date(buf, tt, 1);
308 wprintf("<i>%s</i> %s<br>",
309 _("Starting date/time:"), buf);
312 * Embed the 'show end date/time' loop inside here so it
313 * only executes if this is NOT an all day event.
315 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
317 t = icalproperty_get_dtend(q);
318 tt = icaltime_as_timet(t);
319 webcit_fmt_date(buf, tt, 1);
320 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
328 q = icalcomponent_get_first_property(Cal->cal, ICAL_DESCRIPTION_PROPERTY);
330 wprintf("<i>%s</i> ", _("Notes:"));
331 escputs((char *)icalproperty_get_comment(q));
337 icalproperty_get_comment(p));
338 wprintf("</a></font><br />\n");
341 wprintf("</td></tr></table>");
355 * Display one day of a whole month view of a calendar
357 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
371 struct icaltimetype t;
373 int month, day, year;
374 int all_day_event = 0;
378 time_format = get_time_format_cached ();
380 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
381 else timeformat="%I:%M %p";
383 localtime_r(&thetime, &today_tm);
384 month = today_tm.tm_mon + 1;
385 day = today_tm.tm_mday;
386 year = today_tm.tm_year + 1900;
388 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
389 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
390 Cal = (disp_cal*)vCal;
391 p = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
393 t = icalproperty_get_dtstart(p);
394 event_tt = icaltime_as_timet(t);
396 if (t.is_date) all_day_event = 1;
397 else all_day_event = 0;
400 gmtime_r(&event_tts, &event_tms);
403 localtime_r(&event_tts, &event_tms);
405 /* \todo epoch &! daymask */
406 if ((event_tms.tm_year == today_tm.tm_year)
407 && (event_tms.tm_mon == today_tm.tm_mon)
408 && (event_tms.tm_mday == today_tm.tm_mday)) {
414 p = icalcomponent_get_first_property(
416 ICAL_SUMMARY_PROPERTY);
417 e = icalcomponent_get_first_property(
419 ICAL_DTEND_PROPERTY);
420 if ((p != NULL) && (e != NULL)) {
423 t = icalproperty_get_dtend(e);
424 event_tte = icaltime_as_timet(t);
425 localtime_r(&event_tte, &event_tme);
426 difftime=(event_tte-event_tts)/60;
427 hours=(int)(difftime / 60);
428 minutes=difftime % 60;
429 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
431 "<a class=\"event%s\" href=\"display_edit_event?msgnum=%ld?calview=calbrief?year=%s?month=%s?day=%s\">",
434 (Cal->unread)?"_unread":"_read",
443 icalproperty_get_comment(p));
444 /* \todo: allso ammitime format */
445 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
446 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
448 wprintf("</a></font></td>"
449 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
466 * view one month. pretty view
468 void calendar_month_view(int year, int month, int day) {
469 struct tm starting_tm;
473 time_t previous_month;
475 time_t colheader_time;
476 struct tm colheader_tm;
477 char colheader_label[32];
481 * Determine what day to start. If an impossible value is found, start on Sunday.
483 get_pref_long("weekstart", &weekstart, 17);
484 if (weekstart > 6) weekstart = 0;
487 * Now back up to the 1st of the month...
489 memset(&starting_tm, 0, sizeof(struct tm));
491 starting_tm.tm_year = year - 1900;
492 starting_tm.tm_mon = month - 1;
493 starting_tm.tm_mday = day;
494 thetime = mktime(&starting_tm);
496 memcpy(&tm, &starting_tm, sizeof(struct tm));
497 while (tm.tm_mday != 1) {
498 thetime = thetime - (time_t)86400; /* go back 24 hours */
499 localtime_r(&thetime, &tm);
502 /* Determine previous and next months ... for links */
503 previous_month = thetime - (time_t)864000L; /* back 10 days */
504 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
506 /* Now back up until we're on the user's preferred start day */
507 localtime_r(&thetime, &tm);
508 while (tm.tm_wday != weekstart) {
509 thetime = thetime - (time_t)86400; /* go back 24 hours */
510 localtime_r(&thetime, &tm);
513 /* Outer table (to get the background color) */
514 wprintf("<div class=\"fix_scrollbar_bug\">"
515 "<table class=\"calendar\"> \n <tr><td>");
517 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
519 wprintf("<td align=center>");
521 localtime_r(&previous_month, &tm);
522 wprintf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
523 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
524 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
526 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
527 wprintf(" "
528 "<font size=+1 color=\"#FFFFFF\">"
531 " ", colheader_label, year);
533 localtime_r(&next_month, &tm);
534 wprintf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
535 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
536 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
538 wprintf("</td></tr></table>\n");
540 /* Inner table (the real one) */
541 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
542 "bgcolor=#204B78 id=\"inner_month\"><tr>");
543 colheader_time = thetime;
544 for (i=0; i<7; ++i) {
545 colheader_time = thetime + (i * 86400) ;
546 localtime_r(&colheader_time, &colheader_tm);
547 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
548 wprintf("<th align=center width=14%%>"
549 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
555 /* Now do 35 or 42 days */
556 localtime_r(&thetime, &tm);
557 for (i = 0; i<42; ++i) {
559 /* Before displaying the first day of the week, start a new row */
564 wprintf("<td class=\"cal%s\"><div class=\"day\">",
565 ((tm.tm_mon != month-1) ? "out" :
566 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
569 if ((i==0) || (tm.tm_mday == 1)) {
570 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
571 wprintf("%s ", colheader_label);
573 wprintf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">"
580 /* put the data here, stupid */
581 calendar_month_view_display_events(
589 /* After displaying the last day of the week, end the row */
594 thetime += (time_t)86400; /* ahead 24 hours */
595 localtime_r(&thetime, &tm);
597 if ( ((i % 7) == 6) && (tm.tm_mon != month-1) && (tm.tm_mday < 15) ) {
598 i = 100; /* break out of the loop */
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 StrBufAppendPrintf(WC->trailing_javascript,
618 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); \n"
623 * view one month. brief view
625 void calendar_brief_month_view(int year, int month, int day) {
626 struct tm starting_tm;
630 time_t previous_month;
632 char month_label[32];
634 /* Determine what day to start.
635 * First, back up to the 1st of the month...
637 memset(&starting_tm, 0, sizeof(struct tm));
638 starting_tm.tm_year = year - 1900;
639 starting_tm.tm_mon = month - 1;
640 starting_tm.tm_mday = day;
641 thetime = mktime(&starting_tm);
643 memcpy(&tm, &starting_tm, sizeof(struct tm));
644 while (tm.tm_mday != 1) {
645 thetime = thetime - (time_t)86400; /* go back 24 hours */
646 localtime_r(&thetime, &tm);
649 /* Determine previous and next months ... for links */
650 previous_month = thetime - (time_t)864000L; /* back 10 days */
651 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
653 /* Now back up until we're on a Sunday */
654 localtime_r(&thetime, &tm);
655 while (tm.tm_wday != 0) {
656 thetime = thetime - (time_t)86400; /* go back 24 hours */
657 localtime_r(&thetime, &tm);
660 /* Outer table (to get the background color) */
661 wprintf("<div class=\"fix_scrollbar_bug\">"
662 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
663 "bgcolor=#204B78><TR><TD>\n");
665 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
667 wprintf("<td align=center>");
669 localtime_r(&previous_month, &tm);
670 wprintf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
671 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
672 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
674 wc_strftime(month_label, sizeof month_label, "%B", &tm);
675 wprintf(" "
676 "<font size=+1 color=\"#FFFFFF\">"
679 " ", month_label, year);
681 localtime_r(&next_month, &tm);
682 wprintf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
683 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
684 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
686 wprintf("</td></tr></table>\n");
688 /* Inner table (the real one) */
689 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
690 "bgcolor=#EEEECC><TR>");
692 wprintf("<tr><td colspan=\"100%%\">\n");
695 for (i = 0; i < 35; ++i) {
696 char weeknumber[255];
697 char weekday_name[32];
699 localtime_r(&thetime, &tm);
702 /* Before displaying Sunday, start a new CELL */
704 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
705 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%%'> <tr><th colspan='4'>%s %s</th></tr>"
706 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
716 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
717 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
721 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
722 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
723 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
725 weekday_name,tm.tm_mday,
728 /* put the data of one day here, stupid */
729 calendar_month_view_brief_events(thetime, daycolor);
732 /* After displaying Saturday, end the row */
734 wprintf("</td></tr></table>\n");
737 thetime += (time_t)86400; /* ahead 24 hours */
740 wprintf("</table>" /* end of inner table */
741 "</td></tr></table>" /* end of outer table */
746 * Calendar week view -- not implemented yet, this is a stub function
748 void calendar_week_view(int year, int month, int day) {
749 wprintf("<center><i>week view FIXME</i></center><br />\n");
755 * Display events for a particular hour of a particular day.
756 * (Specify hour < 0 to show "all day" events)
758 * dstart and dend indicate which hours our "daytime" begins and end
760 void calendar_day_view_display_events(time_t thetime,
772 icalproperty *p = NULL;
773 icalproperty *q = NULL;
779 int all_day_event = 0;
780 int ongoing_event = 0;
783 struct icaltimetype t;
784 struct icaltimetype end_t;
785 struct icaltimetype today_start_t;
786 struct icaltimetype today_end_t;
787 struct tm starting_tm;
800 if (GetCount(WCC->disp_cal_items) == 0) {
801 /* nothing to display */
805 /* Create an imaginary event which spans the current day. Any events which
806 * overlap with this one take place at least partially in this day.
808 memset(&starting_tm, 0, sizeof(struct tm));
809 starting_tm.tm_year = year - 1900;
810 starting_tm.tm_mon = month - 1;
811 starting_tm.tm_mday = day;
812 starting_tm.tm_hour = 0;
813 starting_tm.tm_min = 0;
814 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
815 today_start_t.is_utc = 1;
817 memset(&ending_tm, 0, sizeof(struct tm));
818 ending_tm.tm_year = year - 1900;
819 ending_tm.tm_mon = month - 1;
820 ending_tm.tm_mday = day;
821 ending_tm.tm_hour = 23;
822 ending_tm.tm_min = 59;
823 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
824 today_end_t.is_utc = 1;
826 /* Now loop through our list of events to see which ones occur today.
828 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
829 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
830 Cal = (disp_cal*)vCal;
835 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
837 t = icalproperty_get_dtstart(q);
838 event_tt = icaltime_as_timet(t);
839 localtime_r(&event_tt, &event_te);
842 memset(&t, 0, sizeof t);
844 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
846 end_t = icalproperty_get_dtend(q);
847 event_tte = icaltime_as_timet(end_t);
848 localtime_r(&event_tte, &event_tm);
851 memset(&end_t, 0, sizeof end_t);
853 if (t.is_date) all_day_event = 1;
857 show_event = ((t.year == year) && (t.month == month) && (t.day == day) && (notime_events));
861 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
864 /* If we determined that this event occurs today, then display it.
866 p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
868 if ((show_event) && (p != NULL)) {
870 if ((event_te.tm_mday != day) || (event_tm.tm_mday != day)) ongoing_event = 1;
872 if (all_day_event && notime_events)
874 wprintf("<li class=\"event_framed%s\"> "
875 "<a href=\"display_edit_event?"
876 "msgnum=%ld?calview=day?year=%d?month=%d?day=%d\" "
877 " class=\"event_title\" "
879 (Cal->unread)?"_unread":"_read",
880 Cal->cal_msgnum, year, month, day);
881 wprintf("<i>%s</i><br />", _("All day event"));
882 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
883 wprintf("<i>%s</i> ", _("Summary:"));
884 escputs((char *) icalproperty_get_comment(p));
886 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
888 wprintf("<i>%s</i> ", _("Location:"));
889 escputs((char *)icalproperty_get_comment(q));
892 memset(&d_tm, 0, sizeof d_tm);
893 d_tm.tm_year = t.year - 1900;
894 d_tm.tm_mon = t.month - 1;
895 d_tm.tm_mday = t.day;
896 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
897 wprintf("<i>%s</i> %s<br>",_("Date:"), d_str);
898 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
900 wprintf("<i>%s</i> ", _("Notes:"));
901 escputs((char *)icalproperty_get_comment(q));
905 escputs((char *) icalproperty_get_comment(p));
906 wprintf("</a> <span>(");
907 wprintf(_("All day event"));
908 wprintf(")</span></li>\n");
910 else if (ongoing_event && notime_events)
912 wprintf("<li class=\"event_framed%s\"> "
913 "<a href=\"display_edit_event?"
914 "msgnum=%ld&calview=day?year=%d?month=%d?day=%d\" "
915 " class=\"event_title\" "
917 (Cal->unread)?"_unread":"_read",
918 Cal->cal_msgnum, year, month, day);
919 wprintf("<i>%s</i><br />", _("Ongoing event"));
920 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
921 wprintf("<i>%s</i> ", _("Summary:"));
922 escputs((char *) icalproperty_get_comment(p));
924 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
926 wprintf("<i>%s</i> ", _("Location:"));
927 escputs((char *)icalproperty_get_comment(q));
930 webcit_fmt_date(buf, event_tt, 1);
931 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
932 webcit_fmt_date(buf, event_tte, 1);
933 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
934 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
936 wprintf("<i>%s</i> ", _("Notes:"));
937 escputs((char *)icalproperty_get_comment(q));
941 escputs((char *) icalproperty_get_comment(p));
942 wprintf("</a> <span>(");
943 wprintf(_("Ongoing event"));
944 wprintf(")</span></li>\n");
946 else if (!all_day_event && !notime_events)
950 if (event_te.tm_mday != day) event_te.tm_hour = 0;
951 if (event_tm.tm_mday != day) event_tm.tm_hour = 24;
953 /* Calculate the location of the top of the box */
954 if (event_te.tm_hour < dstart) {
955 startmin = diffmin = event_te.tm_min / 6;
956 top = (event_te.tm_hour * 10) + startmin;
958 else if ((event_te.tm_hour >= dstart) && (event_te.tm_hour <= dend)) {
959 startmin = diffmin = (event_te.tm_min / 2);
960 top = (dstart * 10) + ((event_te.tm_hour - dstart) * 30) + startmin;
962 else if (event_te.tm_hour >dend) {
963 startmin = diffmin = event_te.tm_min / 6;
964 top = (dstart * 10) + ((dend - dstart - 1) * 30) + ((event_tm.tm_hour - dend + 1) * 10) + startmin ;
967 /* should never get here */
970 /* Calculate the location of the bottom of the box */
971 if (event_tm.tm_hour < dstart) {
972 endmin = diffmin = event_tm.tm_min / 6;
973 bottom = (event_tm.tm_hour * 10) + endmin;
975 else if ((event_tm.tm_hour >= dstart) && (event_tm.tm_hour <= dend)) {
976 endmin = diffmin = (event_tm.tm_min / 2);
977 bottom = (dstart * 10) + ((event_tm.tm_hour - dstart) * 30) + endmin ;
979 else if (event_tm.tm_hour >dend) {
980 endmin = diffmin = event_tm.tm_min / 6;
981 bottom = (dstart * 10) + ((dend - dstart + 1) * 30) + ((event_tm.tm_hour - dend - 1) * 10) + endmin;
984 /* should never get here */
987 wprintf("<dd class=\"event_framed%s\" "
988 "style=\"position: absolute; "
989 "top:%dpx; left:%dpx; "
991 (Cal->unread)?"_unread":"_read",
992 top, (gap * 40), (bottom-top)
994 wprintf("<a href=\"display_edit_event?"
995 "msgnum=%ld?calview=day?year=%d?month=%d?day=%d?hour=%d\" "
996 "class=\"event_title\" "
998 Cal->cal_msgnum, year, month, day, t.hour);
999 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
1000 wprintf("<i>%s</i> ", _("Summary:"));
1001 escputs((char *) icalproperty_get_comment(p));
1003 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
1005 wprintf("<i>%s</i> ", _("Location:"));
1006 escputs((char *)icalproperty_get_comment(q));
1009 webcit_fmt_date(buf, event_tt, 1);
1010 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
1011 webcit_fmt_date(buf, event_tte, 1);
1012 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
1013 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
1015 wprintf("<i>%s</i> ", _("Notes:"));
1016 escputs((char *)icalproperty_get_comment(q));
1021 escputs((char *) icalproperty_get_comment(p));
1022 wprintf("</a></dd>\n");
1026 DeleteHashPos(&Pos);
1032 void calendar_day_view(int year, int month, int day) {
1034 struct icaltimetype today, yesterday, tomorrow;
1042 int extratimeline = 0;
1045 time_format = get_time_format_cached ();
1046 get_pref_long("daystart", &daystart, 8);
1047 get_pref_long("dayend", &dayend, 17);
1049 /* when loading daystart/dayend, replace missing, corrupt, or impossible values with defaults */
1050 if ((daystart < 0) || (dayend < 2) || (daystart >= 23) || (dayend > 23) || (dayend <= daystart)) {
1056 memset(&d_tm, 0, sizeof d_tm);
1057 d_tm.tm_year = year - 1900;
1058 d_tm.tm_mon = month - 1;
1060 today_t = mktime(&d_tm);
1062 /* Figure out the dates for "yesterday" and "tomorrow" links */
1064 memset(&today, 0, sizeof(struct icaltimetype));
1066 today.month = month;
1070 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
1072 yesterday = icaltime_normalize(yesterday);
1074 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
1076 tomorrow = icaltime_normalize(tomorrow);
1078 wprintf("<div class=\"fix_scrollbar_bug\">");
1080 /* Inner table (the real one) */
1081 wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
1083 /* Innermost cell (contains hours etc.) */
1084 wprintf("<td class=\"events_of_the_day\" >");
1085 wprintf("<dl class=\"events\" >");
1087 /* Now the middle of the day... */
1089 extratimeline = timeline / 3;
1091 for (hour = 0; hour < daystart; ++hour) { /* could do HEIGHT=xx */
1092 wprintf("<dt class=\"extrahour\" "
1094 "position: absolute; "
1095 "top: %dpx; left: 0px; "
1098 "<a href=\"display_edit_event?msgnum=0"
1099 "?calview=day?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
1100 (hour * extratimeline ), extratimeline,
1101 year, month, day, hour
1104 if (time_format == WC_TIMEFORMAT_24) {
1105 wprintf("%2d:00</a> ", hour);
1108 wprintf("%d:00%s</a> ",
1109 (hour <= 12 ? hour : hour-12),
1110 (hour < 12 ? "am" : "pm")
1117 gap = daystart * extratimeline;
1119 for (hour = daystart; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
1120 wprintf("<dt class=\"hour\" "
1122 "position: absolute; "
1123 "top: %ldpx; left: 0px; "
1126 "<a href=\"display_edit_event?msgnum=0?calview=day"
1127 "?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
1128 gap + ((hour - daystart) * timeline ), timeline,
1129 year, month, day, hour
1132 if (time_format == WC_TIMEFORMAT_24) {
1133 wprintf("%2d:00</a> ", hour);
1136 wprintf("%d:00%s</a> ",
1137 (hour <= 12 ? hour : hour-12),
1138 (hour < 12 ? "am" : "pm")
1145 gap = gap + ((dayend - daystart + 1) * timeline);
1147 for (hour = (dayend + 1); hour < 24; ++hour) { /* could do HEIGHT=xx */
1148 wprintf("<dt class=\"extrahour\" "
1150 "position: absolute; "
1151 "top: %ldpx; left: 0px; "
1154 "<a href=\"display_edit_event?msgnum=0?calview=day"
1155 "?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
1156 gap + ((hour - dayend - 1) * extratimeline ), extratimeline,
1157 year, month, day, hour
1160 if (time_format == WC_TIMEFORMAT_24) {
1161 wprintf("%2d:00</a> ", hour);
1164 wprintf("%d:00%s</a> ",
1165 (hour <= 12 ? hour : hour-12),
1166 (hour < 12 ? "am" : "pm")
1173 /* Display events with start and end times on this day */
1174 calendar_day_view_display_events(today_t, year, month, day, 0, daystart, dayend);
1177 wprintf("</td>"); /* end of innermost table */
1179 /* Display extra events (start/end times not present or not today) in the middle column */
1180 wprintf("<td class=\"extra_events\">");
1184 /* Display all-day events */
1185 calendar_day_view_display_events(today_t, year, month, day, 1, daystart, dayend);
1189 wprintf("</td>"); /* end extra on the middle */
1191 wprintf("<td width=20%% align=center valign=top>"); /* begin stuff-on-the-right */
1193 /* Begin todays-date-with-left-and-right-arrows */
1194 wprintf("<table border=0 width=100%% "
1195 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
1199 wprintf("<td align=center>");
1200 wprintf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">",
1201 yesterday.year, yesterday.month, yesterday.day);
1202 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
1205 wc_strftime(d_str, sizeof d_str,
1207 "<font size=+2>%B</font><br />"
1208 "<font size=+3>%d</font><br />"
1209 "<font size=+2>%Y</font><br />"
1213 wprintf("%s", d_str);
1216 wprintf("<td align=center>");
1217 wprintf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">",
1218 tomorrow.year, tomorrow.month, tomorrow.day);
1219 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
1220 " border=0></a>\n");
1223 wprintf("</tr></table>\n");
1224 /* End todays-date-with-left-and-right-arrows */
1226 /* Embed a mini month calendar in this space */
1227 wprintf("<br />\n");
1228 embeddable_mini_calendar(year, month, "readfwd?calview=day?year=%d?month=%d?day=%d");
1230 wprintf("</font></center>\n");
1232 wprintf("</td></tr>"); /* end stuff-on-the-right */
1234 wprintf("</table>" /* end of inner table */
1237 StrBufAppendPrintf(WC->trailing_javascript,
1238 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); \n"
1244 * Display today's events.
1246 void calendar_summary_view(void) {
1248 const char *HashKey;
1253 struct icaltimetype t;
1258 int all_day_event = 0;
1259 char timestring[SIZ];
1260 wcsession *WCC = WC;
1262 if (GetCount(WC->disp_cal_items) == 0) {
1267 localtime_r(&now, &today_tm);
1269 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
1270 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
1271 Cal = (disp_cal*)vCal;
1272 p = icalcomponent_get_first_property(Cal->cal,
1273 ICAL_DTSTART_PROPERTY);
1275 t = icalproperty_get_dtstart(p);
1276 event_tt = icaltime_as_timet(t);
1283 fmt_time(timestring, event_tt);
1285 if (all_day_event) {
1286 gmtime_r(&event_tt, &event_tm);
1289 localtime_r(&event_tt, &event_tm);
1292 if ( (event_tm.tm_year == today_tm.tm_year)
1293 && (event_tm.tm_mon == today_tm.tm_mon)
1294 && (event_tm.tm_mday == today_tm.tm_mday)
1298 p = icalcomponent_get_first_property(
1300 ICAL_SUMMARY_PROPERTY);
1303 icalproperty_get_comment(p));
1304 wprintf(" (%s)<br />\n", timestring);
1309 DeleteHashPos(&Pos);
1310 DeleteHash(&WC->disp_cal_items);
1315 * Parse the URL variables in order to determine the scope and display of a calendar view
1317 void parse_calendar_view_request(struct calview *c) {
1322 /* In case no date was specified, go with today */
1324 localtime_r(&now, &tm);
1325 c->year = tm.tm_year + 1900;
1326 c->month = tm.tm_mon + 1;
1327 c->day = tm.tm_mday;
1329 /* Now see if a date was specified */
1330 if (havebstr("year")) c->year = ibstr("year");
1331 if (havebstr("month")) c->month = ibstr("month");
1332 if (havebstr("day")) c->day = ibstr("day");
1334 /* How would you like that cooked? */
1335 if (havebstr("calview")) {
1336 strcpy(calview, bstr("calview"));
1339 strcpy(calview, "month");
1342 /* Display the selected view */
1343 if (!strcasecmp(calview, "day")) {
1344 c->view = calview_day;
1346 else if (!strcasecmp(calview, "week")) {
1347 c->view = calview_week;
1350 if (WC->wc_view == VIEW_CALBRIEF) {
1351 c->view = calview_brief;
1354 c->view = calview_month;
1358 /* Now try and set the lower and upper bounds so that we don't
1359 * burn too many cpu cycles parsing data way in the past or future
1362 tm.tm_year = c->year - 1900;
1363 tm.tm_mon = c->month - 1;
1364 tm.tm_mday = c->day;
1368 if (c->view == calview_month) span = 3888000;
1369 if (c->view == calview_brief) span = 3888000;
1370 if (c->view == calview_week) span = 604800;
1371 if (c->view == calview_day) span = 86400;
1373 c->lower_bound = now - span;
1374 c->upper_bound = now + span;
1380 * Render a calendar view from data previously loaded into memory
1382 void render_calendar_view(struct calview *c)
1384 if (c->view == calview_day) {
1385 calendar_day_view(c->year, c->month, c->day);
1387 else if (c->view == calview_week) {
1388 calendar_week_view(c->year, c->month, c->day);
1391 if (WC->wc_view == VIEW_CALBRIEF) {
1392 calendar_brief_month_view(c->year, c->month, c->day);
1395 calendar_month_view(c->year, c->month, c->day);
1399 /* Free the in-memory list of calendar items */
1400 DeleteHash(&WC->disp_cal_items);
1405 * Helper function for do_tasks_view(). Returns the due date/time of a vtodo.
1407 time_t get_task_due_date(icalcomponent *vtodo) {
1410 if (vtodo == NULL) {
1415 * If we're looking at a fully encapsulated VCALENDAR
1416 * rather than a VTODO component, recurse into the data
1417 * structure until we get a VTODO.
1419 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1420 return get_task_due_date(
1421 icalcomponent_get_first_component(
1422 vtodo, ICAL_VTODO_COMPONENT
1427 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1429 return(icaltime_as_timet(icalproperty_get_due(p)));
1438 * Compare the due dates of two tasks (this is for sorting)
1440 int task_due_cmp(const void *vtask1, const void *vtask2) {
1441 disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
1442 disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2);
1447 t1 = get_task_due_date(Task1->cal);
1448 t2 = get_task_due_date(Task2->cal);
1449 if (t1 < t2) return(-1);
1450 if (t1 > t2) return(1);
1455 * qsort filter to move completed tasks to bottom of task list
1457 int task_completed_cmp(const void *vtask1, const void *vtask2) {
1458 disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
1459 // disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2);
1461 icalproperty_status t1 = icalcomponent_get_status((Task1)->cal);
1462 // icalproperty_status t2 = icalcomponent_get_status(((struct disp_cal *)task2)->cal);
1464 if (t1 == ICAL_STATUS_COMPLETED)
1472 * do the whole task view stuff
1474 void do_tasks_view(void) {
1476 const char *HashKey;
1484 wcsession *WCC = WC;
1486 wprintf("<div class=\"fix_scrollbar_bug\">"
1487 "<table class=\"calendar_view_background\"><tbody id=\"taskview\">\n<tr>\n"
1489 wprintf(_("Completed?"));
1490 wprintf("</th><th>");
1491 wprintf(_("Name of task"));
1492 wprintf("</th><th>");
1493 wprintf(_("Date due"));
1494 wprintf("</th><th>");
1495 wprintf(_("Category"));
1496 wprintf(" (<select id=\"selectcategory\"><option value=\"showall\">%s</option></select>)</th></tr>\n",
1499 nItems = GetCount(WC->disp_cal_items);
1501 /* Sort them if necessary
1503 SortByPayload(WC->disp_cal_items, task_due_cmp);
1505 * this shouldn't be neccessary, since we sort by the start time.
1508 /* And then again, by completed */
1510 SortByPayload(WC->disp_cal_items,
1511 task_completed_cmp);
1514 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
1515 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
1516 Cal = (disp_cal*)vCal;
1517 wprintf("<tr><td>");
1518 icalproperty_status todoStatus = icalcomponent_get_status(Cal->cal);
1519 wprintf("<input type=\"checkbox\" name=\"completed\" value=\"completed\" ");
1520 if (todoStatus == ICAL_STATUS_COMPLETED) {
1521 wprintf("checked=\"checked\" ");
1523 wprintf("disabled=\"disabled\">\n</td><td>");
1524 p = icalcomponent_get_first_property(Cal->cal,
1525 ICAL_SUMMARY_PROPERTY);
1526 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1528 urlescputs(WC->wc_roomname);
1530 /* wprintf("<img align=middle "
1531 "src=\"static/taskmanag_16x.gif\" border=0> "); */
1533 escputs((char *)icalproperty_get_comment(p));
1538 due = get_task_due_date(Cal->cal);
1539 wprintf("<td><span");
1541 webcit_fmt_date(buf, due, 0);
1547 wprintf("</span></td>");
1549 p = icalcomponent_get_first_property(Cal->cal,
1550 ICAL_CATEGORIES_PROPERTY);
1552 escputs((char *)icalproperty_get_categories(p));
1558 wprintf("</tbody></table></div>\n");
1561 DeleteHash(&WC->disp_cal_items);
1562 DeleteHashPos(&Pos);