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;
185 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
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();
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) {
365 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
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();
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];
482 * Determine what day to start. If an impossible value is found, start on Sunday.
484 get_pref_long("weekstart", &weekstart, 17);
485 if (weekstart > 6) weekstart = 0;
488 * Now back up to the 1st of the month...
490 memset(&starting_tm, 0, sizeof(struct tm));
492 starting_tm.tm_year = year - 1900;
493 starting_tm.tm_mon = month - 1;
494 starting_tm.tm_mday = day;
495 thetime = mktime(&starting_tm);
497 memcpy(&tm, &starting_tm, sizeof(struct tm));
498 while (tm.tm_mday != 1) {
499 thetime = thetime - (time_t)86400; /* go back 24 hours */
500 localtime_r(&thetime, &tm);
503 /* Determine previous and next months ... for links */
504 previous_month = thetime - (time_t)864000L; /* back 10 days */
505 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
507 /* Now back up until we're on the user's preferred start day */
508 localtime_r(&thetime, &tm);
509 while (tm.tm_wday != weekstart) {
510 thetime = thetime - (time_t)86400; /* go back 24 hours */
511 localtime_r(&thetime, &tm);
514 /* Outer table (to get the background color) */
515 wprintf("<div class=\"fix_scrollbar_bug\">"
516 "<table class=\"calendar\"> \n <tr><td>");
518 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
520 wprintf("<td align=center>");
522 localtime_r(&previous_month, &tm);
523 wprintf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
524 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
525 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
527 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
528 wprintf(" "
529 "<font size=+1 color=\"#FFFFFF\">"
532 " ", colheader_label, year);
534 localtime_r(&next_month, &tm);
535 wprintf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
536 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
537 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
539 wprintf("</td></tr></table>\n");
541 /* Inner table (the real one) */
542 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
543 "bgcolor=#204B78 id=\"inner_month\"><tr>");
544 colheader_time = thetime;
545 for (i=0; i<7; ++i) {
546 colheader_time = thetime + (i * 86400) ;
547 localtime_r(&colheader_time, &colheader_tm);
548 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
549 wprintf("<th align=center width=14%%>"
550 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
556 /* Now do 35 or 42 days */
557 for (i = 0; i < 42; ++i) {
558 localtime_r(&thetime, &tm);
560 if ((i < 35) || (chg_month == 0)) {
562 if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) {
569 /* Before displaying the first day of the week, start a new row */
574 wprintf("<td class=\"cal%s\"><div class=\"day\">",
575 ((tm.tm_mon != month-1) ? "out" :
576 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
579 if ((i==0) || (tm.tm_mday == 1)) {
580 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
581 wprintf("%s ", colheader_label);
583 wprintf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">"
590 /* put the data here, stupid */
591 calendar_month_view_display_events(
599 /* After displaying the last day of the week, end the row */
606 thetime += (time_t)86400; /* ahead 24 hours */
609 wprintf("</table>" /* end of inner table */
610 "</td></tr></table>" /* end of outer table */
614 * Initialize the bubble tooltips.
616 * Yes, this is as stupid as it looks. Instead of just making the call
617 * to btt_enableTooltips() straight away, we have to create a timer event
618 * and let it initialize as an event after 1 millisecond. This is to
619 * work around a bug in Internet Explorer that causes it to crash if we
620 * manipulate the innerHTML of various DOM nodes while the page is still
621 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
622 * for more information.
624 StrBufAppendPrintf(WC->trailing_javascript,
625 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); \n"
630 * view one month. brief view
632 void calendar_brief_month_view(int year, int month, int day) {
633 struct tm starting_tm;
637 time_t previous_month;
639 char month_label[32];
641 /* Determine what day to start.
642 * First, back up to the 1st of the month...
644 memset(&starting_tm, 0, sizeof(struct tm));
645 starting_tm.tm_year = year - 1900;
646 starting_tm.tm_mon = month - 1;
647 starting_tm.tm_mday = day;
648 thetime = mktime(&starting_tm);
650 memcpy(&tm, &starting_tm, sizeof(struct tm));
651 while (tm.tm_mday != 1) {
652 thetime = thetime - (time_t)86400; /* go back 24 hours */
653 localtime_r(&thetime, &tm);
656 /* Determine previous and next months ... for links */
657 previous_month = thetime - (time_t)864000L; /* back 10 days */
658 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
660 /* Now back up until we're on a Sunday */
661 localtime_r(&thetime, &tm);
662 while (tm.tm_wday != 0) {
663 thetime = thetime - (time_t)86400; /* go back 24 hours */
664 localtime_r(&thetime, &tm);
667 /* Outer table (to get the background color) */
668 wprintf("<div class=\"fix_scrollbar_bug\">"
669 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
670 "bgcolor=#204B78><TR><TD>\n");
672 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
674 wprintf("<td align=center>");
676 localtime_r(&previous_month, &tm);
677 wprintf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
678 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
679 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
681 wc_strftime(month_label, sizeof month_label, "%B", &tm);
682 wprintf(" "
683 "<font size=+1 color=\"#FFFFFF\">"
686 " ", month_label, year);
688 localtime_r(&next_month, &tm);
689 wprintf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
690 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
691 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
693 wprintf("</td></tr></table>\n");
695 /* Inner table (the real one) */
696 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
697 "bgcolor=#EEEECC><TR>");
699 wprintf("<tr><td colspan=\"100%%\">\n");
702 for (i = 0; i < 35; ++i) {
703 char weeknumber[255];
704 char weekday_name[32];
706 localtime_r(&thetime, &tm);
709 /* Before displaying Sunday, start a new CELL */
711 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
712 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%%'> <tr><th colspan='4'>%s %s</th></tr>"
713 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
723 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
724 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
728 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
729 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
730 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
732 weekday_name,tm.tm_mday,
735 /* put the data of one day here, stupid */
736 calendar_month_view_brief_events(thetime, daycolor);
739 /* After displaying Saturday, end the row */
741 wprintf("</td></tr></table>\n");
744 thetime += (time_t)86400; /* ahead 24 hours */
747 wprintf("</table>" /* end of inner table */
748 "</td></tr></table>" /* end of outer table */
753 * Calendar week view -- not implemented yet, this is a stub function
755 void calendar_week_view(int year, int month, int day) {
756 wprintf("<center><i>week view FIXME</i></center><br />\n");
762 * Display events for a particular hour of a particular day.
763 * (Specify hour < 0 to show "all day" events)
765 * dstart and dend indicate which hours our "daytime" begins and end
767 void calendar_day_view_display_events(time_t thetime,
779 icalproperty *p = NULL;
780 icalproperty *q = NULL;
786 int all_day_event = 0;
787 int ongoing_event = 0;
788 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
790 struct icaltimetype t;
791 struct icaltimetype end_t;
792 struct icaltimetype today_start_t;
793 struct icaltimetype today_end_t;
794 struct tm starting_tm;
807 if (GetCount(WCC->disp_cal_items) == 0) {
808 /* nothing to display */
812 /* Create an imaginary event which spans the current day. Any events which
813 * overlap with this one take place at least partially in this day.
815 memset(&starting_tm, 0, sizeof(struct tm));
816 starting_tm.tm_year = year - 1900;
817 starting_tm.tm_mon = month - 1;
818 starting_tm.tm_mday = day;
819 starting_tm.tm_hour = 0;
820 starting_tm.tm_min = 0;
821 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
822 today_start_t.is_utc = 1;
824 memset(&ending_tm, 0, sizeof(struct tm));
825 ending_tm.tm_year = year - 1900;
826 ending_tm.tm_mon = month - 1;
827 ending_tm.tm_mday = day;
828 ending_tm.tm_hour = 23;
829 ending_tm.tm_min = 59;
830 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
831 today_end_t.is_utc = 1;
833 /* Now loop through our list of events to see which ones occur today.
835 Pos = GetNewHashPos();
836 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
837 Cal = (disp_cal*)vCal;
842 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
844 t = icalproperty_get_dtstart(q);
845 event_tt = icaltime_as_timet(t);
846 localtime_r(&event_tt, &event_te);
849 memset(&t, 0, sizeof t);
851 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
853 end_t = icalproperty_get_dtend(q);
854 event_tte = icaltime_as_timet(end_t);
855 localtime_r(&event_tte, &event_tm);
858 memset(&end_t, 0, sizeof end_t);
860 if (t.is_date) all_day_event = 1;
864 show_event = ((t.year == year) && (t.month == month) && (t.day == day) && (notime_events));
868 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
871 /* If we determined that this event occurs today, then display it.
873 p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
875 if ((show_event) && (p != NULL)) {
877 if ((event_te.tm_mday != day) || (event_tm.tm_mday != day)) ongoing_event = 1;
879 if (all_day_event && notime_events)
881 wprintf("<li class=\"event_framed%s\"> "
882 "<a href=\"display_edit_event?"
883 "msgnum=%ld?calview=day?year=%d?month=%d?day=%d\" "
884 " class=\"event_title\" "
886 (Cal->unread)?"_unread":"_read",
887 Cal->cal_msgnum, year, month, day);
888 wprintf("<i>%s</i><br />", _("All day event"));
889 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
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_framed%s\"> "
920 "<a href=\"display_edit_event?"
921 "msgnum=%ld&calview=day?year=%d?month=%d?day=%d\" "
922 " class=\"event_title\" "
924 (Cal->unread)?"_unread":"_read",
925 Cal->cal_msgnum, year, month, day);
926 wprintf("<i>%s</i><br />", _("Ongoing event"));
927 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
928 wprintf("<i>%s</i> ", _("Summary:"));
929 escputs((char *) icalproperty_get_comment(p));
931 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
933 wprintf("<i>%s</i> ", _("Location:"));
934 escputs((char *)icalproperty_get_comment(q));
937 webcit_fmt_date(buf, event_tt, 1);
938 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
939 webcit_fmt_date(buf, event_tte, 1);
940 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
941 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
943 wprintf("<i>%s</i> ", _("Notes:"));
944 escputs((char *)icalproperty_get_comment(q));
948 escputs((char *) icalproperty_get_comment(p));
949 wprintf("</a> <span>(");
950 wprintf(_("Ongoing event"));
951 wprintf(")</span></li>\n");
953 else if (!all_day_event && !notime_events)
957 if (event_te.tm_mday != day) event_te.tm_hour = 0;
958 if (event_tm.tm_mday != day) event_tm.tm_hour = 24;
960 /* Calculate the location of the top of the box */
961 if (event_te.tm_hour < dstart) {
962 startmin = diffmin = event_te.tm_min / 6;
963 top = (event_te.tm_hour * 10) + startmin;
965 else if ((event_te.tm_hour >= dstart) && (event_te.tm_hour <= dend)) {
966 startmin = diffmin = (event_te.tm_min / 2);
967 top = (dstart * 10) + ((event_te.tm_hour - dstart) * 30) + startmin;
969 else if (event_te.tm_hour >dend) {
970 startmin = diffmin = event_te.tm_min / 6;
971 top = (dstart * 10) + ((dend - dstart - 1) * 30) + ((event_tm.tm_hour - dend + 1) * 10) + startmin ;
974 /* should never get here */
977 /* Calculate the location of the bottom of the box */
978 if (event_tm.tm_hour < dstart) {
979 endmin = diffmin = event_tm.tm_min / 6;
980 bottom = (event_tm.tm_hour * 10) + endmin;
982 else if ((event_tm.tm_hour >= dstart) && (event_tm.tm_hour <= dend)) {
983 endmin = diffmin = (event_tm.tm_min / 2);
984 bottom = (dstart * 10) + ((event_tm.tm_hour - dstart) * 30) + endmin ;
986 else if (event_tm.tm_hour >dend) {
987 endmin = diffmin = event_tm.tm_min / 6;
988 bottom = (dstart * 10) + ((dend - dstart + 1) * 30) + ((event_tm.tm_hour - dend - 1) * 10) + endmin;
991 /* should never get here */
994 wprintf("<dd class=\"event_framed%s\" "
995 "style=\"position: absolute; "
996 "top:%dpx; left:%dpx; "
998 (Cal->unread)?"_unread":"_read",
999 top, (gap * 40), (bottom-top)
1001 wprintf("<a href=\"display_edit_event?"
1002 "msgnum=%ld?calview=day?year=%d?month=%d?day=%d?hour=%d\" "
1003 "class=\"event_title\" "
1005 Cal->cal_msgnum, year, month, day, t.hour);
1006 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
1007 wprintf("<i>%s</i> ", _("Summary:"));
1008 escputs((char *) icalproperty_get_comment(p));
1010 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
1012 wprintf("<i>%s</i> ", _("Location:"));
1013 escputs((char *)icalproperty_get_comment(q));
1016 webcit_fmt_date(buf, event_tt, 1);
1017 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
1018 webcit_fmt_date(buf, event_tte, 1);
1019 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
1020 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
1022 wprintf("<i>%s</i> ", _("Notes:"));
1023 escputs((char *)icalproperty_get_comment(q));
1028 escputs((char *) icalproperty_get_comment(p));
1029 wprintf("</a></dd>\n");
1033 DeleteHashPos(&Pos);
1039 void calendar_day_view(int year, int month, int day) {
1041 struct icaltimetype today, yesterday, tomorrow;
1049 int extratimeline = 0;
1052 time_format = get_time_format_cached ();
1053 get_pref_long("daystart", &daystart, 8);
1054 get_pref_long("dayend", &dayend, 17);
1056 /* when loading daystart/dayend, replace missing, corrupt, or impossible values with defaults */
1057 if ((daystart < 0) || (dayend < 2) || (daystart >= 23) || (dayend > 23) || (dayend <= daystart)) {
1063 memset(&d_tm, 0, sizeof d_tm);
1064 d_tm.tm_year = year - 1900;
1065 d_tm.tm_mon = month - 1;
1067 today_t = mktime(&d_tm);
1069 /* Figure out the dates for "yesterday" and "tomorrow" links */
1071 memset(&today, 0, sizeof(struct icaltimetype));
1073 today.month = month;
1077 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
1079 yesterday = icaltime_normalize(yesterday);
1081 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
1083 tomorrow = icaltime_normalize(tomorrow);
1085 wprintf("<div class=\"fix_scrollbar_bug\">");
1087 /* Inner table (the real one) */
1088 wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
1090 /* Innermost cell (contains hours etc.) */
1091 wprintf("<td class=\"events_of_the_day\" >");
1092 wprintf("<dl class=\"events\" >");
1094 /* Now the middle of the day... */
1096 extratimeline = timeline / 3;
1098 for (hour = 0; hour < daystart; ++hour) { /* could do HEIGHT=xx */
1099 wprintf("<dt class=\"extrahour\" "
1101 "position: absolute; "
1102 "top: %dpx; left: 0px; "
1105 "<a href=\"display_edit_event?msgnum=0"
1106 "?calview=day?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
1107 (hour * extratimeline ), extratimeline,
1108 year, month, day, hour
1111 if (time_format == WC_TIMEFORMAT_24) {
1112 wprintf("%2d:00</a> ", hour);
1115 wprintf("%d:00%s</a> ",
1116 (hour <= 12 ? hour : hour-12),
1117 (hour < 12 ? "am" : "pm")
1124 gap = daystart * extratimeline;
1126 for (hour = daystart; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
1127 wprintf("<dt class=\"hour\" "
1129 "position: absolute; "
1130 "top: %ldpx; left: 0px; "
1133 "<a href=\"display_edit_event?msgnum=0?calview=day"
1134 "?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
1135 gap + ((hour - daystart) * timeline ), timeline,
1136 year, month, day, hour
1139 if (time_format == WC_TIMEFORMAT_24) {
1140 wprintf("%2d:00</a> ", hour);
1143 wprintf("%d:00%s</a> ",
1144 (hour <= 12 ? hour : hour-12),
1145 (hour < 12 ? "am" : "pm")
1152 gap = gap + ((dayend - daystart + 1) * timeline);
1154 for (hour = (dayend + 1); hour < 24; ++hour) { /* could do HEIGHT=xx */
1155 wprintf("<dt class=\"extrahour\" "
1157 "position: absolute; "
1158 "top: %ldpx; left: 0px; "
1161 "<a href=\"display_edit_event?msgnum=0?calview=day"
1162 "?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
1163 gap + ((hour - dayend - 1) * extratimeline ), extratimeline,
1164 year, month, day, hour
1167 if (time_format == WC_TIMEFORMAT_24) {
1168 wprintf("%2d:00</a> ", hour);
1171 wprintf("%d:00%s</a> ",
1172 (hour <= 12 ? hour : hour-12),
1173 (hour < 12 ? "am" : "pm")
1180 /* Display events with start and end times on this day */
1181 calendar_day_view_display_events(today_t, year, month, day, 0, daystart, dayend);
1184 wprintf("</td>"); /* end of innermost table */
1186 /* Display extra events (start/end times not present or not today) in the middle column */
1187 wprintf("<td class=\"extra_events\">");
1191 /* Display all-day events */
1192 calendar_day_view_display_events(today_t, year, month, day, 1, daystart, dayend);
1196 wprintf("</td>"); /* end extra on the middle */
1198 wprintf("<td width=20%% align=center valign=top>"); /* begin stuff-on-the-right */
1200 /* Begin todays-date-with-left-and-right-arrows */
1201 wprintf("<table border=0 width=100%% "
1202 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
1206 wprintf("<td align=center>");
1207 wprintf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">",
1208 yesterday.year, yesterday.month, yesterday.day);
1209 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
1212 wc_strftime(d_str, sizeof d_str,
1214 "<font size=+2>%B</font><br />"
1215 "<font size=+3>%d</font><br />"
1216 "<font size=+2>%Y</font><br />"
1220 wprintf("%s", d_str);
1223 wprintf("<td align=center>");
1224 wprintf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">",
1225 tomorrow.year, tomorrow.month, tomorrow.day);
1226 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
1227 " border=0></a>\n");
1230 wprintf("</tr></table>\n");
1231 /* End todays-date-with-left-and-right-arrows */
1233 /* Embed a mini month calendar in this space */
1234 wprintf("<br />\n");
1235 embeddable_mini_calendar(year, month, "readfwd?calview=day?year=%d?month=%d?day=%d");
1237 wprintf("</font></center>\n");
1239 wprintf("</td></tr>"); /* end stuff-on-the-right */
1241 wprintf("</table>" /* end of inner table */
1244 StrBufAppendPrintf(WC->trailing_javascript,
1245 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); \n"
1251 * Display today's events.
1253 void calendar_summary_view(void) {
1255 const char *HashKey;
1260 struct icaltimetype t;
1265 int all_day_event = 0;
1266 char timestring[SIZ];
1267 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
1269 if (GetCount(WC->disp_cal_items) == 0) {
1274 localtime_r(&now, &today_tm);
1276 Pos = GetNewHashPos();
1277 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
1278 Cal = (disp_cal*)vCal;
1279 p = icalcomponent_get_first_property(Cal->cal,
1280 ICAL_DTSTART_PROPERTY);
1282 t = icalproperty_get_dtstart(p);
1283 event_tt = icaltime_as_timet(t);
1290 fmt_time(timestring, event_tt);
1292 if (all_day_event) {
1293 gmtime_r(&event_tt, &event_tm);
1296 localtime_r(&event_tt, &event_tm);
1299 if ( (event_tm.tm_year == today_tm.tm_year)
1300 && (event_tm.tm_mon == today_tm.tm_mon)
1301 && (event_tm.tm_mday == today_tm.tm_mday)
1305 p = icalcomponent_get_first_property(
1307 ICAL_SUMMARY_PROPERTY);
1310 icalproperty_get_comment(p));
1311 wprintf(" (%s)<br />\n", timestring);
1316 DeleteHashPos(&Pos);
1317 DeleteHash(&WC->disp_cal_items);
1322 * do the whole calendar page
1323 * view any part of the calender. decide which way, etc.
1325 void do_calendar_view(void) {
1328 int year, month, day;
1331 /* In case no date was specified, go with today */
1333 localtime_r(&now, &tm);
1334 year = tm.tm_year + 1900;
1335 month = tm.tm_mon + 1;
1338 /* Now see if a date was specified */
1339 if (havebstr("year")) year = ibstr("year");
1340 if (havebstr("month")) month = ibstr("month");
1341 if (havebstr("day")) day = ibstr("day");
1343 /* How would you like that cooked? */
1344 if (havebstr("calview")) {
1345 strcpy(calview, bstr("calview"));
1348 strcpy(calview, "month");
1351 /* Display the selected view */
1352 if (!strcasecmp(calview, "day")) {
1353 calendar_day_view(year, month, day);
1355 else if (!strcasecmp(calview, "week")) {
1356 calendar_week_view(year, month, day);
1359 if (WC->wc_view == VIEW_CALBRIEF) {
1360 calendar_brief_month_view(year, month, day);
1363 calendar_month_view(year, month, day);
1367 /* Free the in-memory list of calendar items */
1368 DeleteHash(&WC->disp_cal_items);
1373 * Helper function for do_tasks_view(). Returns the due date/time of a vtodo.
1375 time_t get_task_due_date(icalcomponent *vtodo) {
1378 if (vtodo == NULL) {
1383 * If we're looking at a fully encapsulated VCALENDAR
1384 * rather than a VTODO component, recurse into the data
1385 * structure until we get a VTODO.
1387 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1388 return get_task_due_date(
1389 icalcomponent_get_first_component(
1390 vtodo, ICAL_VTODO_COMPONENT
1395 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1397 return(icaltime_as_timet(icalproperty_get_due(p)));
1406 * Compare the due dates of two tasks (this is for sorting)
1408 int task_due_cmp(const void *vtask1, const void *vtask2) {
1409 disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
1410 disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2);
1415 t1 = get_task_due_date(Task1->cal);
1416 t2 = get_task_due_date(Task2->cal);
1417 if (t1 < t2) return(-1);
1418 if (t1 > t2) return(1);
1423 * qsort filter to move completed tasks to bottom of task list
1425 int task_completed_cmp(const void *vtask1, const void *vtask2) {
1426 disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
1427 // disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2);
1429 icalproperty_status t1 = icalcomponent_get_status((Task1)->cal);
1430 // icalproperty_status t2 = icalcomponent_get_status(((struct disp_cal *)task2)->cal);
1432 if (t1 == ICAL_STATUS_COMPLETED)
1440 * do the whole task view stuff
1442 void do_tasks_view(void) {
1444 const char *HashKey;
1452 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
1454 wprintf("<div class=\"fix_scrollbar_bug\">"
1455 "<table class=\"calendar_view_background\"><tbody id=\"taskview\">\n<tr>\n"
1457 wprintf(_("Completed?"));
1458 wprintf("</th><th>");
1459 wprintf(_("Name of task"));
1460 wprintf("</th><th>");
1461 wprintf(_("Date due"));
1462 wprintf("</th><th>");
1463 wprintf(_("Category"));
1464 wprintf(" (<select id=\"selectcategory\"><option value=\"showall\">%s</option></select>)</th></tr>\n",
1467 nItems = GetCount(WC->disp_cal_items);
1469 /* Sort them if necessary
1471 SortByPayload(WC->disp_cal_items, task_due_cmp);
1473 * this shouldn't be neccessary, since we sort by the start time.
1476 /* And then again, by completed */
1478 SortByPayload(WC->disp_cal_items,
1479 task_completed_cmp);
1482 Pos = GetNewHashPos();
1483 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
1484 Cal = (disp_cal*)vCal;
1485 wprintf("<tr><td>");
1486 icalproperty_status todoStatus = icalcomponent_get_status(Cal->cal);
1487 wprintf("<input type=\"checkbox\" name=\"completed\" value=\"completed\" ");
1488 if (todoStatus == ICAL_STATUS_COMPLETED) {
1489 wprintf("checked=\"checked\" ");
1491 wprintf("disabled=\"disabled\">\n</td><td>");
1492 p = icalcomponent_get_first_property(Cal->cal,
1493 ICAL_SUMMARY_PROPERTY);
1494 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1496 urlescputs(WC->wc_roomname);
1498 /* wprintf("<img align=middle "
1499 "src=\"static/taskmanag_16x.gif\" border=0> "); */
1501 escputs((char *)icalproperty_get_comment(p));
1506 due = get_task_due_date(Cal->cal);
1507 wprintf("<td><span");
1509 webcit_fmt_date(buf, due, 0);
1515 wprintf("</span></td>");
1517 p = icalcomponent_get_first_property(Cal->cal,
1518 ICAL_CATEGORIES_PROPERTY);
1520 escputs((char *)icalproperty_get_categories(p));
1526 wprintf("</tbody></table></div>\n");
1529 DeleteHash(&WC->disp_cal_items);
1530 DeleteHashPos(&Pos);