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 wprintf("<script type=\"text/javascript\"> "
133 " function minical_change_month(year, month) { "
134 " p = 'year=' + year + '?month=' + month "
135 " + '&urlformat=%s&r=' + CtdlRandomString(); "
136 " new Ajax.Updater('%s', 'mini_calendar', "
137 " { method: 'get', parameters: p, evalScripts: true } ); "
141 escaped_urlformat, div_id
147 * ajax embedder for the above mini calendar
149 void ajax_mini_calendar(void) {
152 char *escaped_urlformat;
154 escaped_urlformat = bstr("urlformat");
155 len = strlen(escaped_urlformat) * 2 ;
156 for (i=0; i<len; ++i) {
157 urlformat[i] = xtoi(&escaped_urlformat[i*2], 2);
161 embeddable_mini_calendar( ibstr("year"), ibstr("month"), urlformat );
166 * Display one day of a whole month view of a calendar
168 void calendar_month_view_display_events(int year, int month, int day)
175 icalproperty *p = NULL;
176 icalproperty *q = NULL;
177 struct icaltimetype t;
178 struct icaltimetype end_t;
179 struct icaltimetype today_start_t;
180 struct icaltimetype today_end_t;
181 struct tm starting_tm;
183 int all_day_event = 0;
186 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
189 if (GetCount(WCC->disp_cal_items) == 0) {
190 wprintf("<br /><br /><br />\n");
195 * Create an imaginary event which spans the 24 hours of today. Any events which
196 * overlap with this one take place at least partially in this day. We have to
197 * convert it from a struct tm in order to make it UTC.
199 memset(&starting_tm, 0, sizeof(struct tm));
200 starting_tm.tm_year = year - 1900;
201 starting_tm.tm_mon = month - 1;
202 starting_tm.tm_mday = day;
203 starting_tm.tm_hour = 0;
204 starting_tm.tm_min = 0;
205 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
206 today_start_t.is_utc = 1;
208 memset(&ending_tm, 0, sizeof(struct tm));
209 ending_tm.tm_year = year - 1900;
210 ending_tm.tm_mon = month - 1;
211 ending_tm.tm_mday = day;
212 ending_tm.tm_hour = 23;
213 ending_tm.tm_min = 59;
214 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
215 today_end_t.is_utc = 1;
218 * Now loop through our list of events to see which ones occur today.
220 Pos = GetNewHashPos();
221 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
222 Cal = (disp_cal*)vCal;
224 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
226 t = icalproperty_get_dtstart(q);
229 memset(&t, 0, sizeof t);
231 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
233 end_t = icalproperty_get_dtend(q);
236 memset(&end_t, 0, sizeof end_t);
238 if (t.is_date) all_day_event = 1;
242 show_event = ((t.year == year) && (t.month == month) && (t.day == day));
246 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
250 * If we determined that this event occurs today, then display it.
253 p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
257 wprintf("<table border=0 cellpadding=2><TR>"
258 "<td bgcolor=\"#CCCCDD\">"
262 wprintf("<font size=\"-1\">"
263 "<a class=\"event%s\" href=\"display_edit_event?"
264 "msgnum=%ld?calview=month?year=%d?month=%d?day=%d\""
266 (Cal->unread)?"_unread":"_read",
271 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
272 wprintf("<i>%s</i> ", _("Summary:"));
273 escputs((char *)icalproperty_get_comment(p));
276 q = icalcomponent_get_first_property(
278 ICAL_LOCATION_PROPERTY);
280 wprintf("<i>%s</i> ", _("Location:"));
281 escputs((char *)icalproperty_get_comment(q));
286 * Only show start/end times if we're actually looking at the VEVENT
287 * component. Otherwise it shows bogus dates for e.g. timezones
289 if (icalcomponent_isa(Cal->cal) == ICAL_VEVENT_COMPONENT) {
291 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
293 t = icalproperty_get_dtstart(q);
298 memset(&d_tm, 0, sizeof d_tm);
299 d_tm.tm_year = t.year - 1900;
300 d_tm.tm_mon = t.month - 1;
301 d_tm.tm_mday = t.day;
302 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
303 wprintf("<i>%s</i> %s<br>",
307 tt = icaltime_as_timet(t);
308 webcit_fmt_date(buf, tt, 1);
309 wprintf("<i>%s</i> %s<br>",
310 _("Starting date/time:"), buf);
313 * Embed the 'show end date/time' loop inside here so it
314 * only executes if this is NOT an all day event.
316 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
318 t = icalproperty_get_dtend(q);
319 tt = icaltime_as_timet(t);
320 webcit_fmt_date(buf, tt, 1);
321 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
329 q = icalcomponent_get_first_property(Cal->cal, ICAL_DESCRIPTION_PROPERTY);
331 wprintf("<i>%s</i> ", _("Notes:"));
332 escputs((char *)icalproperty_get_comment(q));
338 icalproperty_get_comment(p));
339 wprintf("</a></font><br />\n");
342 wprintf("</td></tr></table>");
356 * Display one day of a whole month view of a calendar
358 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
366 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
372 struct icaltimetype t;
374 int month, day, year;
375 int all_day_event = 0;
379 time_format = get_time_format_cached ();
381 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
382 else timeformat="%I:%M %p";
384 localtime_r(&thetime, &today_tm);
385 month = today_tm.tm_mon + 1;
386 day = today_tm.tm_mday;
387 year = today_tm.tm_year + 1900;
389 Pos = GetNewHashPos();
390 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
391 Cal = (disp_cal*)vCal;
392 p = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
394 t = icalproperty_get_dtstart(p);
395 event_tt = icaltime_as_timet(t);
397 if (t.is_date) all_day_event = 1;
398 else all_day_event = 0;
401 gmtime_r(&event_tts, &event_tms);
404 localtime_r(&event_tts, &event_tms);
406 /* \todo epoch &! daymask */
407 if ((event_tms.tm_year == today_tm.tm_year)
408 && (event_tms.tm_mon == today_tm.tm_mon)
409 && (event_tms.tm_mday == today_tm.tm_mday)) {
415 p = icalcomponent_get_first_property(
417 ICAL_SUMMARY_PROPERTY);
418 e = icalcomponent_get_first_property(
420 ICAL_DTEND_PROPERTY);
421 if ((p != NULL) && (e != NULL)) {
424 t = icalproperty_get_dtend(e);
425 event_tte = icaltime_as_timet(t);
426 localtime_r(&event_tte, &event_tme);
427 difftime=(event_tte-event_tts)/60;
428 hours=(int)(difftime / 60);
429 minutes=difftime % 60;
430 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
432 "<a class=\"event%s\" href=\"display_edit_event?msgnum=%ld?calview=calbrief?year=%s?month=%s?day=%s\">",
435 (Cal->unread)?"_unread":"_read",
444 icalproperty_get_comment(p));
445 /* \todo: allso ammitime format */
446 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
447 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
449 wprintf("</a></font></td>"
450 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
467 * view one month. pretty view
469 void calendar_month_view(int year, int month, int day) {
470 struct tm starting_tm;
474 time_t previous_month;
476 time_t colheader_time;
477 struct tm colheader_tm;
478 char colheader_label[32];
483 * Determine what day to start. If an impossible value is found, start on Sunday.
485 get_pref_long("weekstart", &weekstart, 17);
486 if (weekstart > 6) weekstart = 0;
489 * Now back up to the 1st of the month...
491 memset(&starting_tm, 0, sizeof(struct tm));
493 starting_tm.tm_year = year - 1900;
494 starting_tm.tm_mon = month - 1;
495 starting_tm.tm_mday = day;
496 thetime = mktime(&starting_tm);
498 memcpy(&tm, &starting_tm, sizeof(struct tm));
499 while (tm.tm_mday != 1) {
500 thetime = thetime - (time_t)86400; /* go back 24 hours */
501 localtime_r(&thetime, &tm);
504 /* Determine previous and next months ... for links */
505 previous_month = thetime - (time_t)864000L; /* back 10 days */
506 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
508 /* Now back up until we're on the user's preferred start day */
509 localtime_r(&thetime, &tm);
510 while (tm.tm_wday != weekstart) {
511 thetime = thetime - (time_t)86400; /* go back 24 hours */
512 localtime_r(&thetime, &tm);
515 /* Outer table (to get the background color) */
516 wprintf("<div class=\"fix_scrollbar_bug\">"
517 "<table class=\"calendar\"> \n <tr><td>");
519 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
521 wprintf("<td align=center>");
523 localtime_r(&previous_month, &tm);
524 wprintf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
525 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
526 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
528 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
529 wprintf(" "
530 "<font size=+1 color=\"#FFFFFF\">"
533 " ", colheader_label, year);
535 localtime_r(&next_month, &tm);
536 wprintf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
537 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
538 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
540 wprintf("</td></tr></table>\n");
542 /* Inner table (the real one) */
543 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
544 "bgcolor=#204B78 id=\"inner_month\"><tr>");
545 colheader_time = thetime;
546 for (i=0; i<7; ++i) {
547 colheader_time = thetime + (i * 86400) ;
548 localtime_r(&colheader_time, &colheader_tm);
549 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
550 wprintf("<th align=center width=14%%>"
551 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
557 /* Now do 35 or 42 days */
558 for (i = 0; i < 42; ++i) {
559 localtime_r(&thetime, &tm);
561 if ((i < 35) || (chg_month == 0)) {
563 if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) {
570 /* Before displaying the first day of the week, start a new row */
575 wprintf("<td class=\"cal%s\"><div class=\"day\">",
576 ((tm.tm_mon != month-1) ? "out" :
577 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
580 if ((i==0) || (tm.tm_mday == 1)) {
581 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
582 wprintf("%s ", colheader_label);
584 wprintf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">"
591 /* put the data here, stupid */
592 calendar_month_view_display_events(
600 /* After displaying the last day of the week, end the row */
607 thetime += (time_t)86400; /* ahead 24 hours */
610 wprintf("</table>" /* end of inner table */
611 "</td></tr></table>" /* end of outer table */
615 * Initialize the bubble tooltips.
617 * Yes, this is as stupid as it looks. Instead of just making the call
618 * to btt_enableTooltips() straight away, we have to create a timer event
619 * and let it initialize as an event after 1 millisecond. This is to
620 * work around a bug in Internet Explorer that causes it to crash if we
621 * manipulate the innerHTML of various DOM nodes while the page is still
622 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
623 * for more information.
625 StrBufAppendPrintf(WC->trailing_javascript,
626 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); \n"
631 * view one month. brief view
633 void calendar_brief_month_view(int year, int month, int day) {
634 struct tm starting_tm;
638 time_t previous_month;
640 char month_label[32];
642 /* Determine what day to start.
643 * First, back up to the 1st of the month...
645 memset(&starting_tm, 0, sizeof(struct tm));
646 starting_tm.tm_year = year - 1900;
647 starting_tm.tm_mon = month - 1;
648 starting_tm.tm_mday = day;
649 thetime = mktime(&starting_tm);
651 memcpy(&tm, &starting_tm, sizeof(struct tm));
652 while (tm.tm_mday != 1) {
653 thetime = thetime - (time_t)86400; /* go back 24 hours */
654 localtime_r(&thetime, &tm);
657 /* Determine previous and next months ... for links */
658 previous_month = thetime - (time_t)864000L; /* back 10 days */
659 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
661 /* Now back up until we're on a Sunday */
662 localtime_r(&thetime, &tm);
663 while (tm.tm_wday != 0) {
664 thetime = thetime - (time_t)86400; /* go back 24 hours */
665 localtime_r(&thetime, &tm);
668 /* Outer table (to get the background color) */
669 wprintf("<div class=\"fix_scrollbar_bug\">"
670 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
671 "bgcolor=#204B78><TR><TD>\n");
673 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
675 wprintf("<td align=center>");
677 localtime_r(&previous_month, &tm);
678 wprintf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
679 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
680 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
682 wc_strftime(month_label, sizeof month_label, "%B", &tm);
683 wprintf(" "
684 "<font size=+1 color=\"#FFFFFF\">"
687 " ", month_label, year);
689 localtime_r(&next_month, &tm);
690 wprintf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
691 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
692 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
694 wprintf("</td></tr></table>\n");
696 /* Inner table (the real one) */
697 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
698 "bgcolor=#EEEECC><TR>");
700 wprintf("<tr><td colspan=\"100%%\">\n");
703 for (i = 0; i < 35; ++i) {
704 char weeknumber[255];
705 char weekday_name[32];
707 localtime_r(&thetime, &tm);
710 /* Before displaying Sunday, start a new CELL */
712 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
713 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%%'> <tr><th colspan='4'>%s %s</th></tr>"
714 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
724 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
725 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
729 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
730 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
731 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
733 weekday_name,tm.tm_mday,
736 /* put the data of one day here, stupid */
737 calendar_month_view_brief_events(thetime, daycolor);
740 /* After displaying Saturday, end the row */
742 wprintf("</td></tr></table>\n");
745 thetime += (time_t)86400; /* ahead 24 hours */
748 wprintf("</table>" /* end of inner table */
749 "</td></tr></table>" /* end of outer table */
754 * Calendar week view -- not implemented yet, this is a stub function
756 void calendar_week_view(int year, int month, int day) {
757 wprintf("<center><i>week view FIXME</i></center><br />\n");
763 * Display events for a particular hour of a particular day.
764 * (Specify hour < 0 to show "all day" events)
766 * dstart and dend indicate which hours our "daytime" begins and end
768 void calendar_day_view_display_events(time_t thetime,
780 icalproperty *p = NULL;
781 icalproperty *q = NULL;
787 int all_day_event = 0;
788 int ongoing_event = 0;
789 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
791 struct icaltimetype t;
792 struct icaltimetype end_t;
793 struct icaltimetype today_start_t;
794 struct icaltimetype today_end_t;
795 struct tm starting_tm;
808 if (GetCount(WCC->disp_cal_items) == 0) {
809 /* nothing to display */
813 /* Create an imaginary event which spans the current day. Any events which
814 * overlap with this one take place at least partially in this day.
816 memset(&starting_tm, 0, sizeof(struct tm));
817 starting_tm.tm_year = year - 1900;
818 starting_tm.tm_mon = month - 1;
819 starting_tm.tm_mday = day;
820 starting_tm.tm_hour = 0;
821 starting_tm.tm_min = 0;
822 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
823 today_start_t.is_utc = 1;
825 memset(&ending_tm, 0, sizeof(struct tm));
826 ending_tm.tm_year = year - 1900;
827 ending_tm.tm_mon = month - 1;
828 ending_tm.tm_mday = day;
829 ending_tm.tm_hour = 23;
830 ending_tm.tm_min = 59;
831 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
832 today_end_t.is_utc = 1;
834 /* Now loop through our list of events to see which ones occur today.
836 Pos = GetNewHashPos();
837 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
838 Cal = (disp_cal*)vCal;
843 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
845 t = icalproperty_get_dtstart(q);
846 event_tt = icaltime_as_timet(t);
847 localtime_r(&event_tt, &event_te);
850 memset(&t, 0, sizeof t);
852 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
854 end_t = icalproperty_get_dtend(q);
855 event_tte = icaltime_as_timet(end_t);
856 localtime_r(&event_tte, &event_tm);
859 memset(&end_t, 0, sizeof end_t);
861 if (t.is_date) all_day_event = 1;
865 show_event = ((t.year == year) && (t.month == month) && (t.day == day) && (notime_events));
869 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
872 /* If we determined that this event occurs today, then display it.
874 p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
876 if ((show_event) && (p != NULL)) {
878 if ((event_te.tm_mday != day) || (event_tm.tm_mday != day)) ongoing_event = 1;
880 if (all_day_event && notime_events)
882 wprintf("<li class=\"event_framed%s\"> "
883 "<a href=\"display_edit_event?"
884 "msgnum=%ld?calview=day?year=%d?month=%d?day=%d\" "
885 " class=\"event_title\" "
887 (Cal->unread)?"_unread":"_read",
888 Cal->cal_msgnum, year, month, day);
889 wprintf("<i>%s</i><br />", _("All day event"));
890 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
891 wprintf("<i>%s</i> ", _("Summary:"));
892 escputs((char *) icalproperty_get_comment(p));
894 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
896 wprintf("<i>%s</i> ", _("Location:"));
897 escputs((char *)icalproperty_get_comment(q));
900 memset(&d_tm, 0, sizeof d_tm);
901 d_tm.tm_year = t.year - 1900;
902 d_tm.tm_mon = t.month - 1;
903 d_tm.tm_mday = t.day;
904 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
905 wprintf("<i>%s</i> %s<br>",_("Date:"), d_str);
906 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
908 wprintf("<i>%s</i> ", _("Notes:"));
909 escputs((char *)icalproperty_get_comment(q));
913 escputs((char *) icalproperty_get_comment(p));
914 wprintf("</a> <span>(");
915 wprintf(_("All day event"));
916 wprintf(")</span></li>\n");
918 else if (ongoing_event && notime_events)
920 wprintf("<li class=\"event_framed%s\"> "
921 "<a href=\"display_edit_event?"
922 "msgnum=%ld&calview=day?year=%d?month=%d?day=%d\" "
923 " class=\"event_title\" "
925 (Cal->unread)?"_unread":"_read",
926 Cal->cal_msgnum, year, month, day);
927 wprintf("<i>%s</i><br />", _("Ongoing event"));
928 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
929 wprintf("<i>%s</i> ", _("Summary:"));
930 escputs((char *) icalproperty_get_comment(p));
932 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
934 wprintf("<i>%s</i> ", _("Location:"));
935 escputs((char *)icalproperty_get_comment(q));
938 webcit_fmt_date(buf, event_tt, 1);
939 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
940 webcit_fmt_date(buf, event_tte, 1);
941 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
942 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
944 wprintf("<i>%s</i> ", _("Notes:"));
945 escputs((char *)icalproperty_get_comment(q));
949 escputs((char *) icalproperty_get_comment(p));
950 wprintf("</a> <span>(");
951 wprintf(_("Ongoing event"));
952 wprintf(")</span></li>\n");
954 else if (!all_day_event && !notime_events)
958 if (event_te.tm_mday != day) event_te.tm_hour = 0;
959 if (event_tm.tm_mday != day) event_tm.tm_hour = 24;
961 /* Calculate the location of the top of the box */
962 if (event_te.tm_hour < dstart) {
963 startmin = diffmin = event_te.tm_min / 6;
964 top = (event_te.tm_hour * 10) + startmin;
966 else if ((event_te.tm_hour >= dstart) && (event_te.tm_hour <= dend)) {
967 startmin = diffmin = (event_te.tm_min / 2);
968 top = (dstart * 10) + ((event_te.tm_hour - dstart) * 30) + startmin;
970 else if (event_te.tm_hour >dend) {
971 startmin = diffmin = event_te.tm_min / 6;
972 top = (dstart * 10) + ((dend - dstart - 1) * 30) + ((event_tm.tm_hour - dend + 1) * 10) + startmin ;
975 /* should never get here */
978 /* Calculate the location of the bottom of the box */
979 if (event_tm.tm_hour < dstart) {
980 endmin = diffmin = event_tm.tm_min / 6;
981 bottom = (event_tm.tm_hour * 10) + endmin;
983 else if ((event_tm.tm_hour >= dstart) && (event_tm.tm_hour <= dend)) {
984 endmin = diffmin = (event_tm.tm_min / 2);
985 bottom = (dstart * 10) + ((event_tm.tm_hour - dstart) * 30) + endmin ;
987 else if (event_tm.tm_hour >dend) {
988 endmin = diffmin = event_tm.tm_min / 6;
989 bottom = (dstart * 10) + ((dend - dstart + 1) * 30) + ((event_tm.tm_hour - dend - 1) * 10) + endmin;
992 /* should never get here */
995 wprintf("<dd class=\"event_framed%s\" "
996 "style=\"position: absolute; "
997 "top:%dpx; left:%dpx; "
999 (Cal->unread)?"_unread":"_read",
1000 top, (gap * 40), (bottom-top)
1002 wprintf("<a href=\"display_edit_event?"
1003 "msgnum=%ld?calview=day?year=%d?month=%d?day=%d?hour=%d\" "
1004 "class=\"event_title\" "
1006 Cal->cal_msgnum, year, month, day, t.hour);
1007 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
1008 wprintf("<i>%s</i> ", _("Summary:"));
1009 escputs((char *) icalproperty_get_comment(p));
1011 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
1013 wprintf("<i>%s</i> ", _("Location:"));
1014 escputs((char *)icalproperty_get_comment(q));
1017 webcit_fmt_date(buf, event_tt, 1);
1018 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
1019 webcit_fmt_date(buf, event_tte, 1);
1020 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
1021 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
1023 wprintf("<i>%s</i> ", _("Notes:"));
1024 escputs((char *)icalproperty_get_comment(q));
1029 escputs((char *) icalproperty_get_comment(p));
1030 wprintf("</a></dd>\n");
1034 DeleteHashPos(&Pos);
1040 void calendar_day_view(int year, int month, int day) {
1042 struct icaltimetype today, yesterday, tomorrow;
1050 int extratimeline = 0;
1053 time_format = get_time_format_cached ();
1054 get_pref_long("daystart", &daystart, 8);
1055 get_pref_long("dayend", &dayend, 17);
1057 /* when loading daystart/dayend, replace missing, corrupt, or impossible values with defaults */
1058 if ((daystart < 0) || (dayend < 2) || (daystart >= 23) || (dayend > 23) || (dayend <= daystart)) {
1064 memset(&d_tm, 0, sizeof d_tm);
1065 d_tm.tm_year = year - 1900;
1066 d_tm.tm_mon = month - 1;
1068 today_t = mktime(&d_tm);
1070 /* Figure out the dates for "yesterday" and "tomorrow" links */
1072 memset(&today, 0, sizeof(struct icaltimetype));
1074 today.month = month;
1078 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
1080 yesterday = icaltime_normalize(yesterday);
1082 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
1084 tomorrow = icaltime_normalize(tomorrow);
1086 wprintf("<div class=\"fix_scrollbar_bug\">");
1088 /* Inner table (the real one) */
1089 wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
1091 /* Innermost cell (contains hours etc.) */
1092 wprintf("<td class=\"events_of_the_day\" >");
1093 wprintf("<dl class=\"events\" >");
1095 /* Now the middle of the day... */
1097 extratimeline = timeline / 3;
1099 for (hour = 0; hour < daystart; ++hour) { /* could do HEIGHT=xx */
1100 wprintf("<dt class=\"extrahour\" "
1102 "position: absolute; "
1103 "top: %dpx; left: 0px; "
1106 "<a href=\"display_edit_event?msgnum=0"
1107 "?calview=day?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
1108 (hour * extratimeline ), extratimeline,
1109 year, month, day, hour
1112 if (time_format == WC_TIMEFORMAT_24) {
1113 wprintf("%2d:00</a> ", hour);
1116 wprintf("%d:00%s</a> ",
1117 (hour <= 12 ? hour : hour-12),
1118 (hour < 12 ? "am" : "pm")
1125 gap = daystart * extratimeline;
1127 for (hour = daystart; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
1128 wprintf("<dt class=\"hour\" "
1130 "position: absolute; "
1131 "top: %ldpx; left: 0px; "
1134 "<a href=\"display_edit_event?msgnum=0?calview=day"
1135 "?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
1136 gap + ((hour - daystart) * timeline ), timeline,
1137 year, month, day, hour
1140 if (time_format == WC_TIMEFORMAT_24) {
1141 wprintf("%2d:00</a> ", hour);
1144 wprintf("%d:00%s</a> ",
1145 (hour <= 12 ? hour : hour-12),
1146 (hour < 12 ? "am" : "pm")
1153 gap = gap + ((dayend - daystart + 1) * timeline);
1155 for (hour = (dayend + 1); hour < 24; ++hour) { /* could do HEIGHT=xx */
1156 wprintf("<dt class=\"extrahour\" "
1158 "position: absolute; "
1159 "top: %ldpx; left: 0px; "
1162 "<a href=\"display_edit_event?msgnum=0?calview=day"
1163 "?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
1164 gap + ((hour - dayend - 1) * extratimeline ), extratimeline,
1165 year, month, day, hour
1168 if (time_format == WC_TIMEFORMAT_24) {
1169 wprintf("%2d:00</a> ", hour);
1172 wprintf("%d:00%s</a> ",
1173 (hour <= 12 ? hour : hour-12),
1174 (hour < 12 ? "am" : "pm")
1181 /* Display events with start and end times on this day */
1182 calendar_day_view_display_events(today_t, year, month, day, 0, daystart, dayend);
1185 wprintf("</td>"); /* end of innermost table */
1187 /* Display extra events (start/end times not present or not today) in the middle column */
1188 wprintf("<td class=\"extra_events\">");
1192 /* Display all-day events */
1193 calendar_day_view_display_events(today_t, year, month, day, 1, daystart, dayend);
1197 wprintf("</td>"); /* end extra on the middle */
1199 wprintf("<td width=20%% align=center valign=top>"); /* begin stuff-on-the-right */
1201 /* Begin todays-date-with-left-and-right-arrows */
1202 wprintf("<table border=0 width=100%% "
1203 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
1207 wprintf("<td align=center>");
1208 wprintf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">",
1209 yesterday.year, yesterday.month, yesterday.day);
1210 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
1213 wc_strftime(d_str, sizeof d_str,
1215 "<font size=+2>%B</font><br />"
1216 "<font size=+3>%d</font><br />"
1217 "<font size=+2>%Y</font><br />"
1221 wprintf("%s", d_str);
1224 wprintf("<td align=center>");
1225 wprintf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">",
1226 tomorrow.year, tomorrow.month, tomorrow.day);
1227 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
1228 " border=0></a>\n");
1231 wprintf("</tr></table>\n");
1232 /* End todays-date-with-left-and-right-arrows */
1234 /* Embed a mini month calendar in this space */
1235 wprintf("<br />\n");
1236 embeddable_mini_calendar(year, month, "readfwd?calview=day?year=%d?month=%d?day=%d");
1238 wprintf("</font></center>\n");
1240 wprintf("</td></tr>"); /* end stuff-on-the-right */
1242 wprintf("</table>" /* end of inner table */
1245 StrBufAppendPrintf(WC->trailing_javascript,
1246 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); \n"
1252 * Display today's events.
1254 void calendar_summary_view(void) {
1256 const char *HashKey;
1261 struct icaltimetype t;
1266 int all_day_event = 0;
1267 char timestring[SIZ];
1268 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
1270 if (GetCount(WC->disp_cal_items) == 0) {
1275 localtime_r(&now, &today_tm);
1277 Pos = GetNewHashPos();
1278 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
1279 Cal = (disp_cal*)vCal;
1280 p = icalcomponent_get_first_property(Cal->cal,
1281 ICAL_DTSTART_PROPERTY);
1283 t = icalproperty_get_dtstart(p);
1284 event_tt = icaltime_as_timet(t);
1291 fmt_time(timestring, event_tt);
1293 if (all_day_event) {
1294 gmtime_r(&event_tt, &event_tm);
1297 localtime_r(&event_tt, &event_tm);
1300 if ( (event_tm.tm_year == today_tm.tm_year)
1301 && (event_tm.tm_mon == today_tm.tm_mon)
1302 && (event_tm.tm_mday == today_tm.tm_mday)
1306 p = icalcomponent_get_first_property(
1308 ICAL_SUMMARY_PROPERTY);
1311 icalproperty_get_comment(p));
1312 wprintf(" (%s)<br />\n", timestring);
1317 DeleteHashPos(&Pos);
1318 DeleteHash(&WC->disp_cal_items);
1323 * do the whole calendar page
1324 * view any part of the calender. decide which way, etc.
1326 void do_calendar_view(void) {
1329 int year, month, day;
1332 /* In case no date was specified, go with today */
1334 localtime_r(&now, &tm);
1335 year = tm.tm_year + 1900;
1336 month = tm.tm_mon + 1;
1339 /* Now see if a date was specified */
1340 if (havebstr("year")) year = ibstr("year");
1341 if (havebstr("month")) month = ibstr("month");
1342 if (havebstr("day")) day = ibstr("day");
1344 /* How would you like that cooked? */
1345 if (havebstr("calview")) {
1346 strcpy(calview, bstr("calview"));
1349 strcpy(calview, "month");
1352 /* Display the selected view */
1353 if (!strcasecmp(calview, "day")) {
1354 calendar_day_view(year, month, day);
1356 else if (!strcasecmp(calview, "week")) {
1357 calendar_week_view(year, month, day);
1360 if (WC->wc_view == VIEW_CALBRIEF) {
1361 calendar_brief_month_view(year, month, day);
1364 calendar_month_view(year, month, day);
1368 /* Free the in-memory list of calendar items */
1369 DeleteHash(&WC->disp_cal_items);
1374 * Helper function for do_tasks_view(). Returns the due date/time of a vtodo.
1376 time_t get_task_due_date(icalcomponent *vtodo) {
1379 if (vtodo == NULL) {
1384 * If we're looking at a fully encapsulated VCALENDAR
1385 * rather than a VTODO component, recurse into the data
1386 * structure until we get a VTODO.
1388 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1389 return get_task_due_date(
1390 icalcomponent_get_first_component(
1391 vtodo, ICAL_VTODO_COMPONENT
1396 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1398 return(icaltime_as_timet(icalproperty_get_due(p)));
1407 * Compare the due dates of two tasks (this is for sorting)
1409 int task_due_cmp(const void *vtask1, const void *vtask2) {
1410 disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
1411 disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2);
1416 t1 = get_task_due_date(Task1->cal);
1417 t2 = get_task_due_date(Task2->cal);
1418 if (t1 < t2) return(-1);
1419 if (t1 > t2) return(1);
1424 * qsort filter to move completed tasks to bottom of task list
1426 int task_completed_cmp(const void *vtask1, const void *vtask2) {
1427 disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
1428 // disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2);
1430 icalproperty_status t1 = icalcomponent_get_status((Task1)->cal);
1431 // icalproperty_status t2 = icalcomponent_get_status(((struct disp_cal *)task2)->cal);
1433 if (t1 == ICAL_STATUS_COMPLETED)
1441 * do the whole task view stuff
1443 void do_tasks_view(void) {
1445 const char *HashKey;
1453 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
1455 wprintf("<div class=\"fix_scrollbar_bug\">"
1456 "<table class=\"calendar_view_background\"><tbody id=\"taskview\">\n<tr>\n"
1458 wprintf(_("Completed?"));
1459 wprintf("</th><th>");
1460 wprintf(_("Name of task"));
1461 wprintf("</th><th>");
1462 wprintf(_("Date due"));
1463 wprintf("</th><th>");
1464 wprintf(_("Category"));
1465 wprintf(" (<select id=\"selectcategory\"><option value=\"showall\">%s</option></select>)</th></tr>\n",
1468 nItems = GetCount(WC->disp_cal_items);
1470 /* Sort them if necessary
1472 SortByPayload(WC->disp_cal_items, task_due_cmp);
1474 * this shouldn't be neccessary, since we sort by the start time.
1477 /* And then again, by completed */
1479 SortByPayload(WC->disp_cal_items,
1480 task_completed_cmp);
1483 Pos = GetNewHashPos();
1484 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
1485 Cal = (disp_cal*)vCal;
1486 wprintf("<tr><td>");
1487 icalproperty_status todoStatus = icalcomponent_get_status(Cal->cal);
1488 wprintf("<input type=\"checkbox\" name=\"completed\" value=\"completed\" ");
1489 if (todoStatus == ICAL_STATUS_COMPLETED) {
1490 wprintf("checked=\"checked\" ");
1492 wprintf("disabled=\"disabled\">\n</td><td>");
1493 p = icalcomponent_get_first_property(Cal->cal,
1494 ICAL_SUMMARY_PROPERTY);
1495 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1497 urlescputs(WC->wc_roomname);
1499 /* wprintf("<img align=middle "
1500 "src=\"static/taskmanag_16x.gif\" border=0> "); */
1502 escputs((char *)icalproperty_get_comment(p));
1507 due = get_task_due_date(Cal->cal);
1508 wprintf("<td><span");
1510 webcit_fmt_date(buf, due, 0);
1516 wprintf("</span></td>");
1518 p = icalcomponent_get_first_property(Cal->cal,
1519 ICAL_CATEGORIES_PROPERTY);
1521 escputs((char *)icalproperty_get_categories(p));
1527 wprintf("</tbody></table></div>\n");
1530 DeleteHash(&WC->disp_cal_items);
1531 DeleteHashPos(&Pos);