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 * \brief 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 * \brief Display one day of a whole month view of a calendar
167 * \param thetime the month we want to see
169 void calendar_month_view_display_events(int year, int month, int day)
176 icalproperty *p = NULL;
177 icalproperty *q = NULL;
178 struct icaltimetype t;
179 struct icaltimetype end_t;
180 struct icaltimetype today_start_t;
181 struct icaltimetype today_end_t;
182 struct tm starting_tm;
184 int all_day_event = 0;
187 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
190 if (GetCount(WCC->disp_cal_items) == 0) {
191 wprintf("<br /><br /><br />\n");
196 * Create an imaginary event which spans the 24 hours of today. Any events which
197 * overlap with this one take place at least partially in this day. We have to
198 * convert it from a struct tm in order to make it UTC.
200 memset(&starting_tm, 0, sizeof(struct tm));
201 starting_tm.tm_year = year - 1900;
202 starting_tm.tm_mon = month - 1;
203 starting_tm.tm_mday = day;
204 starting_tm.tm_hour = 0;
205 starting_tm.tm_min = 0;
206 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
207 today_start_t.is_utc = 1;
209 memset(&ending_tm, 0, sizeof(struct tm));
210 ending_tm.tm_year = year - 1900;
211 ending_tm.tm_mon = month - 1;
212 ending_tm.tm_mday = day;
213 ending_tm.tm_hour = 23;
214 ending_tm.tm_min = 59;
215 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
216 today_end_t.is_utc = 1;
219 * Now loop through our list of events to see which ones occur today.
221 Pos = GetNewHashPos();
222 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
223 Cal = (disp_cal*)vCal;
225 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
227 t = icalproperty_get_dtstart(q);
230 memset(&t, 0, sizeof t);
232 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
234 end_t = icalproperty_get_dtend(q);
237 memset(&end_t, 0, sizeof end_t);
239 if (t.is_date) all_day_event = 1;
243 show_event = ((t.year == year) && (t.month == month) && (t.day == day));
247 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
251 * If we determined that this event occurs today, then display it.
254 p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
258 wprintf("<table border=0 cellpadding=2><TR>"
259 "<td bgcolor=\"#CCCCDD\">"
263 wprintf("<font size=-1>"
264 "<a class=\"event%s\" href=\"display_edit_event?"
265 "msgnum=%ld&calview=month&year=%d&month=%d&day=%d\""
267 (Cal->unread)?"_unread":"_read",
272 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
273 wprintf("<i>%s</i> ", _("Summary:"));
274 escputs((char *)icalproperty_get_comment(p));
277 q = icalcomponent_get_first_property(
279 ICAL_LOCATION_PROPERTY);
281 wprintf("<i>%s</i> ", _("Location:"));
282 escputs((char *)icalproperty_get_comment(q));
287 * Only show start/end times if we're actually looking at the VEVENT
288 * component. Otherwise it shows bogus dates for e.g. timezones
290 if (icalcomponent_isa(Cal->cal) == ICAL_VEVENT_COMPONENT) {
292 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
294 t = icalproperty_get_dtstart(q);
299 memset(&d_tm, 0, sizeof d_tm);
300 d_tm.tm_year = t.year - 1900;
301 d_tm.tm_mon = t.month - 1;
302 d_tm.tm_mday = t.day;
303 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
304 wprintf("<i>%s</i> %s<br>",
308 tt = icaltime_as_timet(t);
309 webcit_fmt_date(buf, tt, 1);
310 wprintf("<i>%s</i> %s<br>",
311 _("Starting date/time:"), buf);
314 * Embed the 'show end date/time' loop inside here so it
315 * only executes if this is NOT an all day event.
317 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
319 t = icalproperty_get_dtend(q);
320 tt = icaltime_as_timet(t);
321 webcit_fmt_date(buf, tt, 1);
322 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
330 q = icalcomponent_get_first_property(Cal->cal, ICAL_DESCRIPTION_PROPERTY);
332 wprintf("<i>%s</i> ", _("Notes:"));
333 escputs((char *)icalproperty_get_comment(q));
339 icalproperty_get_comment(p));
340 wprintf("</a></font><br />\n");
343 wprintf("</td></tr></table>");
357 * \brief Display one day of a whole month view of a calendar
358 * \param thetime the month we want to see
360 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
368 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
374 struct icaltimetype t;
376 int month, day, year;
377 int all_day_event = 0;
381 time_format = get_time_format_cached ();
383 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
384 else timeformat="%I:%M %p";
386 localtime_r(&thetime, &today_tm);
387 month = today_tm.tm_mon + 1;
388 day = today_tm.tm_mday;
389 year = today_tm.tm_year + 1900;
391 Pos = GetNewHashPos();
392 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
393 Cal = (disp_cal*)vCal;
394 p = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
396 t = icalproperty_get_dtstart(p);
397 event_tt = icaltime_as_timet(t);
399 if (t.is_date) all_day_event = 1;
400 else all_day_event = 0;
403 gmtime_r(&event_tts, &event_tms);
406 localtime_r(&event_tts, &event_tms);
408 /* \todo epoch &! daymask */
409 if ((event_tms.tm_year == today_tm.tm_year)
410 && (event_tms.tm_mon == today_tm.tm_mon)
411 && (event_tms.tm_mday == today_tm.tm_mday)) {
417 p = icalcomponent_get_first_property(
419 ICAL_SUMMARY_PROPERTY);
420 e = icalcomponent_get_first_property(
422 ICAL_DTEND_PROPERTY);
423 if ((p != NULL) && (e != NULL)) {
426 t = icalproperty_get_dtend(e);
427 event_tte = icaltime_as_timet(t);
428 localtime_r(&event_tte, &event_tme);
429 difftime=(event_tte-event_tts)/60;
430 hours=(int)(difftime / 60);
431 minutes=difftime % 60;
432 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
434 "<a class=\"event%s\" href=\"display_edit_event?msgnum=%ld&calview=calbrief&year=%s&month=%s&day=%s\">",
437 (Cal->unread)?"_unread":"_read",
446 icalproperty_get_comment(p));
447 /* \todo: allso ammitime format */
448 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
449 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
451 wprintf("</a></font></td>"
452 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
469 * view one month. pretty view
471 void calendar_month_view(int year, int month, int day) {
472 struct tm starting_tm;
476 time_t previous_month;
478 time_t colheader_time;
479 struct tm colheader_tm;
480 char colheader_label[32];
485 * Determine what day to start. If an impossible value is found, start on Sunday.
487 get_pref_long("weekstart", &weekstart, 17);
488 if (weekstart > 6) weekstart = 0;
491 * Now back up to the 1st of the month...
493 memset(&starting_tm, 0, sizeof(struct tm));
495 starting_tm.tm_year = year - 1900;
496 starting_tm.tm_mon = month - 1;
497 starting_tm.tm_mday = day;
498 thetime = mktime(&starting_tm);
500 memcpy(&tm, &starting_tm, sizeof(struct tm));
501 while (tm.tm_mday != 1) {
502 thetime = thetime - (time_t)86400; /* go back 24 hours */
503 localtime_r(&thetime, &tm);
506 /* Determine previous and next months ... for links */
507 previous_month = thetime - (time_t)864000L; /* back 10 days */
508 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
510 /* Now back up until we're on the user's preferred start day */
511 localtime_r(&thetime, &tm);
512 while (tm.tm_wday != weekstart) {
513 thetime = thetime - (time_t)86400; /* go back 24 hours */
514 localtime_r(&thetime, &tm);
517 /* Outer table (to get the background color) */
518 wprintf("<div class=\"fix_scrollbar_bug\">"
519 "<table class=\"calendar\"> \n <tr><td>");
521 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
523 wprintf("<td align=center>");
525 localtime_r(&previous_month, &tm);
526 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
527 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
528 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
530 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
531 wprintf(" "
532 "<font size=+1 color=\"#FFFFFF\">"
535 " ", colheader_label, year);
537 localtime_r(&next_month, &tm);
538 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
539 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
540 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
542 wprintf("</td></tr></table>\n");
544 /* Inner table (the real one) */
545 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
546 "bgcolor=#204B78 id=\"inner_month\"><tr>");
547 colheader_time = thetime;
548 for (i=0; i<7; ++i) {
549 colheader_time = thetime + (i * 86400) ;
550 localtime_r(&colheader_time, &colheader_tm);
551 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
552 wprintf("<th align=center width=14%%>"
553 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
559 /* Now do 35 or 42 days */
560 for (i = 0; i < 42; ++i) {
561 localtime_r(&thetime, &tm);
563 if ((i < 35) || (chg_month == 0)) {
565 if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) {
572 /* Before displaying the first day of the week, start a new row */
577 wprintf("<td class=\"cal%s\"><div class=\"day\">",
578 ((tm.tm_mon != month-1) ? "out" :
579 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
582 if ((i==0) || (tm.tm_mday == 1)) {
583 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
584 wprintf("%s ", colheader_label);
586 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
593 /** put the data here, stupid */
594 calendar_month_view_display_events(
602 /* After displaying the last day of the week, end the row */
609 thetime += (time_t)86400; /* ahead 24 hours */
612 wprintf("</table>" /* end of inner table */
613 "</td></tr></table>" /* end of outer table */
617 * Initialize the bubble tooltips.
619 * Yes, this is as stupid as it looks. Instead of just making the call
620 * to btt_enableTooltips() straight away, we have to create a timer event
621 * and let it initialize as an event after 1 millisecond. This is to
622 * work around a bug in Internet Explorer that causes it to crash if we
623 * manipulate the innerHTML of various DOM nodes while the page is still
624 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
625 * for more information.
627 wprintf("<script type=\"text/javascript\">"
628 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
634 * view one month. brief view
636 void calendar_brief_month_view(int year, int month, int day) {
637 struct tm starting_tm;
641 time_t previous_month;
643 char month_label[32];
645 /* Determine what day to start.
646 * First, back up to the 1st of the month...
648 memset(&starting_tm, 0, sizeof(struct tm));
649 starting_tm.tm_year = year - 1900;
650 starting_tm.tm_mon = month - 1;
651 starting_tm.tm_mday = day;
652 thetime = mktime(&starting_tm);
654 memcpy(&tm, &starting_tm, sizeof(struct tm));
655 while (tm.tm_mday != 1) {
656 thetime = thetime - (time_t)86400; /* go back 24 hours */
657 localtime_r(&thetime, &tm);
660 /* Determine previous and next months ... for links */
661 previous_month = thetime - (time_t)864000L; /* back 10 days */
662 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
664 /* Now back up until we're on a Sunday */
665 localtime_r(&thetime, &tm);
666 while (tm.tm_wday != 0) {
667 thetime = thetime - (time_t)86400; /* go back 24 hours */
668 localtime_r(&thetime, &tm);
671 /* Outer table (to get the background color) */
672 wprintf("<div class=\"fix_scrollbar_bug\">"
673 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
674 "bgcolor=#204B78><TR><TD>\n");
676 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
678 wprintf("<td align=center>");
680 localtime_r(&previous_month, &tm);
681 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
682 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
683 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
685 wc_strftime(month_label, sizeof month_label, "%B", &tm);
686 wprintf(" "
687 "<font size=+1 color=\"#FFFFFF\">"
690 " ", month_label, year);
692 localtime_r(&next_month, &tm);
693 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
694 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
695 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
697 wprintf("</td></tr></table>\n");
699 /* Inner table (the real one) */
700 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
701 "bgcolor=#EEEECC><TR>");
703 wprintf("<tr><td colspan=\"100%%\">\n");
706 for (i = 0; i < 35; ++i) {
707 char weeknumber[255];
708 char weekday_name[32];
710 localtime_r(&thetime, &tm);
713 /* Before displaying Sunday, start a new CELL */
715 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
716 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%%'> <tr><th colspan='4'>%s %s</th></tr>"
717 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
727 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
728 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
732 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
733 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
734 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
736 weekday_name,tm.tm_mday,
739 /* put the data of one day here, stupid */
740 calendar_month_view_brief_events(thetime, daycolor);
743 /* After displaying Saturday, end the row */
745 wprintf("</td></tr></table>\n");
748 thetime += (time_t)86400; /** ahead 24 hours */
751 wprintf("</table>" /** end of inner table */
752 "</td></tr></table>" /** end of outer table */
757 * Calendar week view -- not implemented yet, this is a stub function
759 void calendar_week_view(int year, int month, int day) {
760 wprintf("<center><i>week view FIXME</i></center><br />\n");
766 * Display events for a particular hour of a particular day.
767 * (Specify hour < 0 to show "all day" events)
769 * dstart and dend indicate which hours our "daytime" begins and end
771 void calendar_day_view_display_events(time_t thetime,
783 icalproperty *p = NULL;
784 icalproperty *q = NULL;
790 int all_day_event = 0;
791 int ongoing_event = 0;
792 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
794 struct icaltimetype t;
795 struct icaltimetype end_t;
796 struct icaltimetype today_start_t;
797 struct icaltimetype today_end_t;
798 struct tm starting_tm;
811 if (GetCount(WCC->disp_cal_items) == 0) {
812 /* nothing to display */
816 /* Create an imaginary event which spans the current day. Any events which
817 * overlap with this one take place at least partially in this day.
819 memset(&starting_tm, 0, sizeof(struct tm));
820 starting_tm.tm_year = year - 1900;
821 starting_tm.tm_mon = month - 1;
822 starting_tm.tm_mday = day;
823 starting_tm.tm_hour = 0;
824 starting_tm.tm_min = 0;
825 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
826 today_start_t.is_utc = 1;
828 memset(&ending_tm, 0, sizeof(struct tm));
829 ending_tm.tm_year = year - 1900;
830 ending_tm.tm_mon = month - 1;
831 ending_tm.tm_mday = day;
832 ending_tm.tm_hour = 23;
833 ending_tm.tm_min = 59;
834 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
835 today_end_t.is_utc = 1;
837 /* Now loop through our list of events to see which ones occur today.
839 Pos = GetNewHashPos();
840 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
841 Cal = (disp_cal*)vCal;
846 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
848 t = icalproperty_get_dtstart(q);
849 event_tt = icaltime_as_timet(t);
850 localtime_r(&event_tt, &event_te);
853 memset(&t, 0, sizeof t);
855 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
857 end_t = icalproperty_get_dtend(q);
858 event_tte = icaltime_as_timet(end_t);
859 localtime_r(&event_tte, &event_tm);
862 memset(&end_t, 0, sizeof end_t);
864 if (t.is_date) all_day_event = 1;
868 show_event = ((t.year == year) && (t.month == month) && (t.day == day) && (notime_events));
872 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
875 /* If we determined that this event occurs today, then display it.
877 p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
879 if ((show_event) && (p != NULL)) {
881 if ((event_te.tm_mday != day) || (event_tm.tm_mday != day)) ongoing_event = 1;
883 if (all_day_event && notime_events)
885 wprintf("<li class=\"event_framed%s\"> "
886 "<a href=\"display_edit_event?"
887 "msgnum=%ld&calview=day&year=%d&month=%d&day=%d\" "
888 " class=\"event_title\" "
890 (Cal->unread)?"_unread":"_read",
891 Cal->cal_msgnum, year, month, day);
892 wprintf("<i>%s</i><br />", _("All day event"));
893 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
894 wprintf("<i>%s</i> ", _("Summary:"));
895 escputs((char *) icalproperty_get_comment(p));
897 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
899 wprintf("<i>%s</i> ", _("Location:"));
900 escputs((char *)icalproperty_get_comment(q));
903 memset(&d_tm, 0, sizeof d_tm);
904 d_tm.tm_year = t.year - 1900;
905 d_tm.tm_mon = t.month - 1;
906 d_tm.tm_mday = t.day;
907 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
908 wprintf("<i>%s</i> %s<br>",_("Date:"), d_str);
909 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
911 wprintf("<i>%s</i> ", _("Notes:"));
912 escputs((char *)icalproperty_get_comment(q));
916 escputs((char *) icalproperty_get_comment(p));
917 wprintf("</a> <span>(");
918 wprintf(_("All day event"));
919 wprintf(")</span></li>\n");
921 else if (ongoing_event && notime_events)
923 wprintf("<li class=\"event_framed%s\"> "
924 "<a href=\"display_edit_event?"
925 "msgnum=%ld&calview=day&year=%d&month=%d&day=%d\" "
926 " class=\"event_title\" "
928 (Cal->unread)?"_unread":"_read",
929 Cal->cal_msgnum, year, month, day);
930 wprintf("<i>%s</i><br />", _("Ongoing event"));
931 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
932 wprintf("<i>%s</i> ", _("Summary:"));
933 escputs((char *) icalproperty_get_comment(p));
935 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
937 wprintf("<i>%s</i> ", _("Location:"));
938 escputs((char *)icalproperty_get_comment(q));
941 webcit_fmt_date(buf, event_tt, 1);
942 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
943 webcit_fmt_date(buf, event_tte, 1);
944 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
945 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
947 wprintf("<i>%s</i> ", _("Notes:"));
948 escputs((char *)icalproperty_get_comment(q));
952 escputs((char *) icalproperty_get_comment(p));
953 wprintf("</a> <span>(");
954 wprintf(_("Ongoing event"));
955 wprintf(")</span></li>\n");
957 else if (!all_day_event && !notime_events)
961 if (event_te.tm_mday != day) event_te.tm_hour = 0;
962 if (event_tm.tm_mday != day) event_tm.tm_hour = 24;
964 /* Calculate the location of the top of the box */
965 if (event_te.tm_hour < dstart) {
966 startmin = diffmin = event_te.tm_min / 6;
967 top = (event_te.tm_hour * 10) + startmin;
969 else if ((event_te.tm_hour >= dstart) && (event_te.tm_hour <= dend)) {
970 startmin = diffmin = (event_te.tm_min / 2);
971 top = (dstart * 10) + ((event_te.tm_hour - dstart) * 30) + startmin;
973 else if (event_te.tm_hour >dend) {
974 startmin = diffmin = event_te.tm_min / 6;
975 top = (dstart * 10) + ((dend - dstart - 1) * 30) + ((event_tm.tm_hour - dend + 1) * 10) + startmin ;
978 /* should never get here */
981 /* Calculate the location of the bottom of the box */
982 if (event_tm.tm_hour < dstart) {
983 endmin = diffmin = event_tm.tm_min / 6;
984 bottom = (event_tm.tm_hour * 10) + endmin;
986 else if ((event_tm.tm_hour >= dstart) && (event_tm.tm_hour <= dend)) {
987 endmin = diffmin = (event_tm.tm_min / 2);
988 bottom = (dstart * 10) + ((event_tm.tm_hour - dstart) * 30) + endmin ;
990 else if (event_tm.tm_hour >dend) {
991 endmin = diffmin = event_tm.tm_min / 6;
992 bottom = (dstart * 10) + ((dend - dstart + 1) * 30) + ((event_tm.tm_hour - dend - 1) * 10) + endmin;
995 /* should never get here */
998 wprintf("<dd class=\"event_framed%s\" "
999 "style=\"position: absolute; "
1000 "top:%dpx; left:%dpx; "
1001 "height:%dpx; \" >",
1002 (Cal->unread)?"_unread":"_read",
1003 top, (gap * 40), (bottom-top)
1005 wprintf("<a href=\"display_edit_event?"
1006 "msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\" "
1007 "class=\"event_title\" "
1009 Cal->cal_msgnum, year, month, day, t.hour);
1010 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
1011 wprintf("<i>%s</i> ", _("Summary:"));
1012 escputs((char *) icalproperty_get_comment(p));
1014 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
1016 wprintf("<i>%s</i> ", _("Location:"));
1017 escputs((char *)icalproperty_get_comment(q));
1020 webcit_fmt_date(buf, event_tt, 1);
1021 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
1022 webcit_fmt_date(buf, event_tte, 1);
1023 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
1024 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
1026 wprintf("<i>%s</i> ", _("Notes:"));
1027 escputs((char *)icalproperty_get_comment(q));
1032 escputs((char *) icalproperty_get_comment(p));
1033 wprintf("</a></dd>\n");
1037 DeleteHashPos(&Pos);
1043 void calendar_day_view(int year, int month, int day) {
1045 struct icaltimetype today, yesterday, tomorrow;
1053 int extratimeline = 0;
1056 time_format = get_time_format_cached ();
1057 get_pref_long("daystart", &daystart, 8);
1058 get_pref_long("dayend", &dayend, 17);
1060 /* when loading daystart/dayend, replace missing, corrupt, or impossible values with defaults */
1061 if ((daystart < 0) || (dayend < 2) || (daystart >= 23) || (dayend > 23) || (dayend <= daystart)) {
1067 memset(&d_tm, 0, sizeof d_tm);
1068 d_tm.tm_year = year - 1900;
1069 d_tm.tm_mon = month - 1;
1071 today_t = mktime(&d_tm);
1073 /* Figure out the dates for "yesterday" and "tomorrow" links */
1075 memset(&today, 0, sizeof(struct icaltimetype));
1077 today.month = month;
1081 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
1083 yesterday = icaltime_normalize(yesterday);
1085 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
1087 tomorrow = icaltime_normalize(tomorrow);
1089 wprintf("<div class=\"fix_scrollbar_bug\">");
1091 /* Inner table (the real one) */
1092 wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
1094 /* Innermost cell (contains hours etc.) */
1095 wprintf("<td class=\"events_of_the_day\" >");
1096 wprintf("<dl class=\"events\" >");
1098 /* Now the middle of the day... */
1100 extratimeline = timeline / 3;
1102 for (hour = 0; hour < daystart; ++hour) { /* could do HEIGHT=xx */
1103 wprintf("<dt class=\"extrahour\" "
1105 "position: absolute; "
1106 "top: %dpx; left: 0px; "
1109 "<a href=\"display_edit_event?msgnum=0"
1110 "&calview=day&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
1111 (hour * extratimeline ), extratimeline,
1112 year, month, day, hour
1115 if (time_format == WC_TIMEFORMAT_24) {
1116 wprintf("%2d:00</a> ", hour);
1119 wprintf("%d:00%s</a> ",
1120 (hour <= 12 ? hour : hour-12),
1121 (hour < 12 ? "am" : "pm")
1128 gap = daystart * extratimeline;
1130 for (hour = daystart; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
1131 wprintf("<dt class=\"hour\" "
1133 "position: absolute; "
1134 "top: %ldpx; left: 0px; "
1137 "<a href=\"display_edit_event?msgnum=0&calview=day"
1138 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
1139 gap + ((hour - daystart) * timeline ), timeline,
1140 year, month, day, hour
1143 if (time_format == WC_TIMEFORMAT_24) {
1144 wprintf("%2d:00</a> ", hour);
1147 wprintf("%d:00%s</a> ",
1148 (hour <= 12 ? hour : hour-12),
1149 (hour < 12 ? "am" : "pm")
1156 gap = gap + ((dayend - daystart + 1) * timeline);
1158 for (hour = (dayend + 1); hour < 24; ++hour) { /* could do HEIGHT=xx */
1159 wprintf("<dt class=\"extrahour\" "
1161 "position: absolute; "
1162 "top: %ldpx; left: 0px; "
1165 "<a href=\"display_edit_event?msgnum=0&calview=day"
1166 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
1167 gap + ((hour - dayend - 1) * extratimeline ), extratimeline,
1168 year, month, day, hour
1171 if (time_format == WC_TIMEFORMAT_24) {
1172 wprintf("%2d:00</a> ", hour);
1175 wprintf("%d:00%s</a> ",
1176 (hour <= 12 ? hour : hour-12),
1177 (hour < 12 ? "am" : "pm")
1184 /* Display events with start and end times on this day */
1185 calendar_day_view_display_events(today_t, year, month, day, 0, daystart, dayend);
1188 wprintf("</td>"); /* end of innermost table */
1190 /* Display extra events (start/end times not present or not today) in the middle column */
1191 wprintf("<td class=\"extra_events\">");
1195 /* Display all-day events */
1196 calendar_day_view_display_events(today_t, year, month, day, 1, daystart, dayend);
1200 wprintf("</td>"); /** end extra on the middle */
1202 wprintf("<td width=20%% align=center valign=top>"); /** begin stuff-on-the-right */
1204 /* Begin todays-date-with-left-and-right-arrows */
1205 wprintf("<table border=0 width=100%% "
1206 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
1210 wprintf("<td align=center>");
1211 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
1212 yesterday.year, yesterday.month, yesterday.day);
1213 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
1216 wc_strftime(d_str, sizeof d_str,
1218 "<font size=+2>%B</font><br />"
1219 "<font size=+3>%d</font><br />"
1220 "<font size=+2>%Y</font><br />"
1224 wprintf("%s", d_str);
1227 wprintf("<td align=center>");
1228 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
1229 tomorrow.year, tomorrow.month, tomorrow.day);
1230 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
1231 " border=0></a>\n");
1234 wprintf("</tr></table>\n");
1235 /* End todays-date-with-left-and-right-arrows */
1237 /* Embed a mini month calendar in this space */
1238 wprintf("<br />\n");
1239 embeddable_mini_calendar(year, month, "readfwd?calview=day&year=%d&month=%d&day=%d");
1241 wprintf("</font></center>\n");
1243 wprintf("</td></tr>"); /** end stuff-on-the-right */
1245 wprintf("</table>" /** end of inner table */
1248 wprintf("<script type=\"text/javascript\">"
1249 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); "
1256 * Display today's events.
1258 void calendar_summary_view(void) {
1260 const char *HashKey;
1265 struct icaltimetype t;
1270 int all_day_event = 0;
1271 char timestring[SIZ];
1272 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
1274 if (GetCount(WC->disp_cal_items) == 0) {
1279 localtime_r(&now, &today_tm);
1281 Pos = GetNewHashPos();
1282 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
1283 Cal = (disp_cal*)vCal;
1284 p = icalcomponent_get_first_property(Cal->cal,
1285 ICAL_DTSTART_PROPERTY);
1287 t = icalproperty_get_dtstart(p);
1288 event_tt = icaltime_as_timet(t);
1295 fmt_time(timestring, event_tt);
1297 if (all_day_event) {
1298 gmtime_r(&event_tt, &event_tm);
1301 localtime_r(&event_tt, &event_tm);
1304 if ( (event_tm.tm_year == today_tm.tm_year)
1305 && (event_tm.tm_mon == today_tm.tm_mon)
1306 && (event_tm.tm_mday == today_tm.tm_mday)
1310 p = icalcomponent_get_first_property(
1312 ICAL_SUMMARY_PROPERTY);
1315 icalproperty_get_comment(p));
1316 wprintf(" (%s)<br />\n", timestring);
1321 DeleteHashPos(&Pos);
1322 DeleteHash(&WC->disp_cal_items);
1327 * do the whole calendar page
1328 * view any part of the calender. decide which way, etc.
1330 void do_calendar_view(void) {
1333 int year, month, day;
1336 /* In case no date was specified, go with today */
1338 localtime_r(&now, &tm);
1339 year = tm.tm_year + 1900;
1340 month = tm.tm_mon + 1;
1343 /* Now see if a date was specified */
1344 if (havebstr("year")) year = ibstr("year");
1345 if (havebstr("month")) month = ibstr("month");
1346 if (havebstr("day")) day = ibstr("day");
1348 /* How would you like that cooked? */
1349 if (havebstr("calview")) {
1350 strcpy(calview, bstr("calview"));
1353 strcpy(calview, "month");
1356 /* Display the selected view */
1357 if (!strcasecmp(calview, "day")) {
1358 calendar_day_view(year, month, day);
1360 else if (!strcasecmp(calview, "week")) {
1361 calendar_week_view(year, month, day);
1364 if (WC->wc_view == VIEW_CALBRIEF) {
1365 calendar_brief_month_view(year, month, day);
1368 calendar_month_view(year, month, day);
1372 /* Free the in-memory list of calendar items */
1373 DeleteHash(&WC->disp_cal_items);
1378 * Helper function for do_tasks_view(). Returns the due date/time of a vtodo.
1380 time_t get_task_due_date(icalcomponent *vtodo) {
1383 if (vtodo == NULL) {
1388 * If we're looking at a fully encapsulated VCALENDAR
1389 * rather than a VTODO component, recurse into the data
1390 * structure until we get a VTODO.
1392 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1393 return get_task_due_date(
1394 icalcomponent_get_first_component(
1395 vtodo, ICAL_VTODO_COMPONENT
1400 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1402 return(icaltime_as_timet(icalproperty_get_due(p)));
1411 * Compare the due dates of two tasks (this is for sorting)
1413 int task_due_cmp(const void *vtask1, const void *vtask2) {
1414 disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
1415 disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2);
1420 t1 = get_task_due_date(Task1->cal);
1421 t2 = get_task_due_date(Task2->cal);
1422 if (t1 < t2) return(-1);
1423 if (t1 > t2) return(1);
1428 * qsort filter to move completed tasks to bottom of task list
1430 int task_completed_cmp(const void *vtask1, const void *vtask2) {
1431 disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
1432 // disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2);
1434 icalproperty_status t1 = icalcomponent_get_status((Task1)->cal);
1435 // icalproperty_status t2 = icalcomponent_get_status(((struct disp_cal *)task2)->cal);
1437 if (t1 == ICAL_STATUS_COMPLETED)
1445 * do the whole task view stuff
1447 void do_tasks_view(void) {
1449 const char *HashKey;
1457 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
1459 wprintf("<div class=\"fix_scrollbar_bug\">"
1460 "<table class=\"calendar_view_background\"><tbody id=\"taskview\">\n<tr>\n"
1462 wprintf(_("Completed?"));
1463 wprintf("</th><th>");
1464 wprintf(_("Name of task"));
1465 wprintf("</th><th>");
1466 wprintf(_("Date due"));
1467 wprintf("</th><th>");
1468 wprintf(_("Category"));
1469 wprintf(" (<select id=\"selectcategory\"><option value=\"showall\">%s</option></select>)</th></tr>\n",
1472 nItems = GetCount(WC->disp_cal_items);
1474 /* Sort them if necessary
1476 SortByPayload(WC->disp_cal_items, task_due_cmp);
1478 * this shouldn't be neccessary, since we sort by the start time.
1481 /* And then again, by completed */
1483 SortByPayload(WC->disp_cal_items,
1484 task_completed_cmp);
1487 Pos = GetNewHashPos();
1488 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
1489 Cal = (disp_cal*)vCal;
1490 wprintf("<tr><td>");
1491 icalproperty_status todoStatus = icalcomponent_get_status(Cal->cal);
1492 wprintf("<input type=\"checkbox\" name=\"completed\" value=\"completed\" ");
1493 if (todoStatus == ICAL_STATUS_COMPLETED) {
1494 wprintf("checked=\"checked\" ");
1496 wprintf("disabled=\"disabled\">\n</td><td>");
1497 p = icalcomponent_get_first_property(Cal->cal,
1498 ICAL_SUMMARY_PROPERTY);
1499 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1501 urlescputs(WC->wc_roomname);
1503 /* wprintf("<img align=middle "
1504 "src=\"static/taskmanag_16x.gif\" border=0> "); */
1506 escputs((char *)icalproperty_get_comment(p));
1511 due = get_task_due_date(Cal->cal);
1512 wprintf("<td><span");
1514 webcit_fmt_date(buf, due, 0);
1520 wprintf("</span></td>");
1522 p = icalcomponent_get_first_property(Cal->cal,
1523 ICAL_CATEGORIES_PROPERTY);
1525 escputs((char *)icalproperty_get_categories(p));
1531 wprintf("</tbody></table></div>\n");
1534 DeleteHash(&WC->disp_cal_items);
1535 DeleteHashPos(&Pos);