4 * Handles the HTML display of calendar items.
11 void embeddable_mini_calendar(int year, int month)
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];
26 snprintf(div_id, sizeof div_id, "mini_calendar_%d", rand() );
28 /* Determine what day to start. If an impossible value is found, start on Sunday.
30 get_pref_long("weekstart", &weekstart, 17);
31 if (weekstart > 6) weekstart = 0;
34 * Now back up to the 1st of the month...
36 memset(&starting_tm, 0, sizeof(struct tm));
38 starting_tm.tm_year = year - 1900;
39 starting_tm.tm_mon = month - 1;
40 starting_tm.tm_mday = 1;
41 thetime = mktime(&starting_tm);
43 memcpy(&tm, &starting_tm, sizeof(struct tm));
44 while (tm.tm_mday != 1) {
45 thetime = thetime - (time_t)86400; /* go back 24 hours */
46 localtime_r(&thetime, &tm);
49 /* Determine previous and next months ... for links */
50 previous_month = thetime - (time_t)864000L; /* back 10 days */
51 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
53 /* Now back up until we're on the user's preferred start day */
54 localtime_r(&thetime, &tm);
55 while (tm.tm_wday != weekstart) {
56 thetime = thetime - (time_t)86400; /* go back 24 hours */
57 localtime_r(&thetime, &tm);
60 wprintf("<div class=\"mini_calendar\" id=\"%s\">\n", div_id);
62 /* Previous month link */
63 localtime_r(&previous_month, &tm);
64 wprintf("<a href=\"javascript:minical_change_month(%d,%d);\">«</a>",
65 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
67 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
68 wprintf(" "
69 "<span class=\"mini_calendar_month_label\">"
72 " ", colheader_label, year);
75 localtime_r(&next_month, &tm);
76 wprintf("<a href=\"javascript:minical_change_month(%d,%d);\">»</a>",
77 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
79 wprintf("<table border=0 cellpadding=1 cellspacing=1 class=\"mini_calendar_days\">"
81 colheader_time = thetime;
83 colheader_time = thetime + (i * 86400) ;
84 localtime_r(&colheader_time, &colheader_tm);
85 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
86 wprintf("<th>%c</th>", colheader_label[0]);
92 /* Now do 35 or 42 days */
93 for (i = 0; i < 42; ++i) {
94 localtime_r(&thetime, &tm);
98 /* Before displaying Sunday, start a new row */
103 if (tm.tm_mon == month-1) {
104 snprintf(url, sizeof url, "readfwd?calview=day&year=%d&month=%d&day=%d",
105 tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday);
106 wprintf("<td><a href=\"%s\">%d</a></td>", url, tm.tm_mday);
109 wprintf("<td> </td>");
112 /* After displaying one week, end the row */
119 thetime += (time_t)86400; /* ahead 24 hours */
122 wprintf("</table>" /* end of inner table */
125 StrBufAppendPrintf(WC->trailing_javascript,
126 " function minical_change_month(year, month) { \n"
127 " p = 'year=' + year + '&month=' + month \n"
128 " + '&r=' + CtdlRandomString(); \n"
129 " new Ajax.Updater('%s', 'mini_calendar', \n"
130 " { method: 'get', parameters: p, evalScripts: true } ); \n"
139 * ajax embedder for the above mini calendar
141 void ajax_mini_calendar(void)
143 embeddable_mini_calendar( ibstr("year"), ibstr("month"));
148 * Display one day of a whole month view of a calendar
150 void calendar_month_view_display_events(int year, int month, int day)
157 icalproperty *p = NULL;
158 icalproperty *q = NULL;
159 struct icaltimetype t;
160 struct icaltimetype end_t;
161 struct icaltimetype today_start_t;
162 struct icaltimetype today_end_t;
163 struct tm starting_tm;
165 int all_day_event = 0;
171 if (GetCount(WCC->disp_cal_items) == 0) {
172 wprintf("<br /><br /><br />\n");
177 * Create an imaginary event which spans the 24 hours of today. Any events which
178 * overlap with this one take place at least partially in this day. We have to
179 * convert it from a struct tm in order to make it UTC.
181 memset(&starting_tm, 0, sizeof(struct tm));
182 starting_tm.tm_year = year - 1900;
183 starting_tm.tm_mon = month - 1;
184 starting_tm.tm_mday = day;
185 starting_tm.tm_hour = 0;
186 starting_tm.tm_min = 0;
187 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
188 today_start_t.is_utc = 1;
190 memset(&ending_tm, 0, sizeof(struct tm));
191 ending_tm.tm_year = year - 1900;
192 ending_tm.tm_mon = month - 1;
193 ending_tm.tm_mday = day;
194 ending_tm.tm_hour = 23;
195 ending_tm.tm_min = 59;
196 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
197 today_end_t.is_utc = 1;
200 * Now loop through our list of events to see which ones occur today.
202 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
203 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
204 Cal = (disp_cal*)vCal;
206 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
208 t = icalproperty_get_dtstart(q);
211 memset(&t, 0, sizeof t);
213 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
215 end_t = icalproperty_get_dtend(q);
218 memset(&end_t, 0, sizeof end_t);
220 if (t.is_date) all_day_event = 1;
224 show_event = ((t.year == year) && (t.month == month) && (t.day == day));
228 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
232 * If we determined that this event occurs today, then display it.
235 p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
239 wprintf("<table border=0 cellpadding=2><TR>"
240 "<td bgcolor=\"#CCCCDD\">"
244 wprintf("<font size=\"-1\">"
245 "<a class=\"event%s\" href=\"display_edit_event?"
246 "msgnum=%ld?calview=month?year=%d?month=%d?day=%d\""
248 (Cal->unread)?"_unread":"_read",
253 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
254 wprintf("<i>%s</i> ", _("Summary:"));
255 escputs((char *)icalproperty_get_comment(p));
258 q = icalcomponent_get_first_property(
260 ICAL_LOCATION_PROPERTY);
262 wprintf("<i>%s</i> ", _("Location:"));
263 escputs((char *)icalproperty_get_comment(q));
268 * Only show start/end times if we're actually looking at the VEVENT
269 * component. Otherwise it shows bogus dates for e.g. timezones
271 if (icalcomponent_isa(Cal->cal) == ICAL_VEVENT_COMPONENT) {
273 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
275 t = icalproperty_get_dtstart(q);
280 memset(&d_tm, 0, sizeof d_tm);
281 d_tm.tm_year = t.year - 1900;
282 d_tm.tm_mon = t.month - 1;
283 d_tm.tm_mday = t.day;
284 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
285 wprintf("<i>%s</i> %s<br>",
289 tt = icaltime_as_timet(t);
290 webcit_fmt_date(buf, tt, 1);
291 wprintf("<i>%s</i> %s<br>",
292 _("Starting date/time:"), buf);
295 * Embed the 'show end date/time' loop inside here so it
296 * only executes if this is NOT an all day event.
298 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
300 t = icalproperty_get_dtend(q);
301 tt = icaltime_as_timet(t);
302 webcit_fmt_date(buf, tt, 1);
303 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
311 q = icalcomponent_get_first_property(Cal->cal, ICAL_DESCRIPTION_PROPERTY);
313 wprintf("<i>%s</i> ", _("Notes:"));
314 escputs((char *)icalproperty_get_comment(q));
320 icalproperty_get_comment(p));
321 wprintf("</a></font><br />\n");
324 wprintf("</td></tr></table>");
338 * Display one day of a whole month view of a calendar
340 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
354 struct icaltimetype t;
356 int month, day, year;
357 int all_day_event = 0;
361 time_format = get_time_format_cached ();
363 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
364 else timeformat="%I:%M %p";
366 localtime_r(&thetime, &today_tm);
367 month = today_tm.tm_mon + 1;
368 day = today_tm.tm_mday;
369 year = today_tm.tm_year + 1900;
371 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
372 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
373 Cal = (disp_cal*)vCal;
374 p = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
376 t = icalproperty_get_dtstart(p);
377 event_tt = icaltime_as_timet(t);
379 if (t.is_date) all_day_event = 1;
380 else all_day_event = 0;
383 gmtime_r(&event_tts, &event_tms);
386 localtime_r(&event_tts, &event_tms);
388 /* \todo epoch &! daymask */
389 if ((event_tms.tm_year == today_tm.tm_year)
390 && (event_tms.tm_mon == today_tm.tm_mon)
391 && (event_tms.tm_mday == today_tm.tm_mday)) {
397 p = icalcomponent_get_first_property(
399 ICAL_SUMMARY_PROPERTY);
400 e = icalcomponent_get_first_property(
402 ICAL_DTEND_PROPERTY);
403 if ((p != NULL) && (e != NULL)) {
406 t = icalproperty_get_dtend(e);
407 event_tte = icaltime_as_timet(t);
408 localtime_r(&event_tte, &event_tme);
409 difftime=(event_tte-event_tts)/60;
410 hours=(int)(difftime / 60);
411 minutes=difftime % 60;
412 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
414 "<a class=\"event%s\" href=\"display_edit_event?msgnum=%ld?calview=calbrief?year=%s?month=%s?day=%s\">",
417 (Cal->unread)?"_unread":"_read",
426 icalproperty_get_comment(p));
427 /* \todo: allso ammitime format */
428 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
429 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
431 wprintf("</a></font></td>"
432 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
449 * view one month. pretty view
451 void calendar_month_view(int year, int month, int day) {
452 struct tm starting_tm;
456 time_t previous_month;
458 time_t colheader_time;
459 struct tm colheader_tm;
460 char colheader_label[32];
464 * Determine what day to start. If an impossible value is found, start on Sunday.
466 get_pref_long("weekstart", &weekstart, 17);
467 if (weekstart > 6) weekstart = 0;
470 * Now back up to the 1st of the month...
472 memset(&starting_tm, 0, sizeof(struct tm));
474 starting_tm.tm_year = year - 1900;
475 starting_tm.tm_mon = month - 1;
476 starting_tm.tm_mday = day;
477 thetime = mktime(&starting_tm);
479 memcpy(&tm, &starting_tm, sizeof(struct tm));
480 while (tm.tm_mday != 1) {
481 thetime = thetime - (time_t)86400; /* go back 24 hours */
482 localtime_r(&thetime, &tm);
485 /* Determine previous and next months ... for links */
486 previous_month = thetime - (time_t)864000L; /* back 10 days */
487 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
489 /* Now back up until we're on the user's preferred start day */
490 localtime_r(&thetime, &tm);
491 while (tm.tm_wday != weekstart) {
492 thetime = thetime - (time_t)86400; /* go back 24 hours */
493 localtime_r(&thetime, &tm);
496 /* Outer table (to get the background color) */
497 wprintf("<div class=\"fix_scrollbar_bug\">"
498 "<table class=\"calendar\"> \n <tr><td>");
500 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
502 wprintf("<td align=center>");
504 localtime_r(&previous_month, &tm);
505 wprintf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
506 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
507 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
509 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
510 wprintf(" "
511 "<font size=+1 color=\"#FFFFFF\">"
514 " ", colheader_label, year);
516 localtime_r(&next_month, &tm);
517 wprintf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
518 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
519 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
521 wprintf("</td></tr></table>\n");
523 /* Inner table (the real one) */
524 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
525 "bgcolor=#204B78 id=\"inner_month\"><tr>");
526 colheader_time = thetime;
527 for (i=0; i<7; ++i) {
528 colheader_time = thetime + (i * 86400) ;
529 localtime_r(&colheader_time, &colheader_tm);
530 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
531 wprintf("<th align=center width=14%%>"
532 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
538 /* Now do 35 or 42 days */
539 localtime_r(&thetime, &tm);
540 for (i = 0; i<42; ++i) {
542 /* Before displaying the first day of the week, start a new row */
547 wprintf("<td class=\"cal%s\"><div class=\"day\">",
548 ((tm.tm_mon != month-1) ? "out" :
549 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
552 if ((i==0) || (tm.tm_mday == 1)) {
553 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
554 wprintf("%s ", colheader_label);
556 wprintf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">"
563 /* put the data here, stupid */
564 calendar_month_view_display_events(
572 /* After displaying the last day of the week, end the row */
577 thetime += (time_t)86400; /* ahead 24 hours */
578 localtime_r(&thetime, &tm);
580 if ( ((i % 7) == 6) && (tm.tm_mon != month-1) && (tm.tm_mday < 15) ) {
581 i = 100; /* break out of the loop */
585 wprintf("</table>" /* end of inner table */
586 "</td></tr></table>" /* end of outer table */
590 * Initialize the bubble tooltips.
592 * Yes, this is as stupid as it looks. Instead of just making the call
593 * to btt_enableTooltips() straight away, we have to create a timer event
594 * and let it initialize as an event after 1 millisecond. This is to
595 * work around a bug in Internet Explorer that causes it to crash if we
596 * manipulate the innerHTML of various DOM nodes while the page is still
597 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
598 * for more information.
600 StrBufAppendPrintf(WC->trailing_javascript,
601 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); \n"
606 * view one month. brief view
608 void calendar_brief_month_view(int year, int month, int day) {
609 struct tm starting_tm;
613 time_t previous_month;
615 char month_label[32];
617 /* Determine what day to start.
618 * First, back up to the 1st of the month...
620 memset(&starting_tm, 0, sizeof(struct tm));
621 starting_tm.tm_year = year - 1900;
622 starting_tm.tm_mon = month - 1;
623 starting_tm.tm_mday = day;
624 thetime = mktime(&starting_tm);
626 memcpy(&tm, &starting_tm, sizeof(struct tm));
627 while (tm.tm_mday != 1) {
628 thetime = thetime - (time_t)86400; /* go back 24 hours */
629 localtime_r(&thetime, &tm);
632 /* Determine previous and next months ... for links */
633 previous_month = thetime - (time_t)864000L; /* back 10 days */
634 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
636 /* Now back up until we're on a Sunday */
637 localtime_r(&thetime, &tm);
638 while (tm.tm_wday != 0) {
639 thetime = thetime - (time_t)86400; /* go back 24 hours */
640 localtime_r(&thetime, &tm);
643 /* Outer table (to get the background color) */
644 wprintf("<div class=\"fix_scrollbar_bug\">"
645 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
646 "bgcolor=#204B78><TR><TD>\n");
648 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
650 wprintf("<td align=center>");
652 localtime_r(&previous_month, &tm);
653 wprintf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
654 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
655 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
657 wc_strftime(month_label, sizeof month_label, "%B", &tm);
658 wprintf(" "
659 "<font size=+1 color=\"#FFFFFF\">"
662 " ", month_label, year);
664 localtime_r(&next_month, &tm);
665 wprintf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
666 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
667 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
669 wprintf("</td></tr></table>\n");
671 /* Inner table (the real one) */
672 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
673 "bgcolor=#EEEECC><TR>");
675 wprintf("<tr><td colspan=\"100%%\">\n");
678 for (i = 0; i < 35; ++i) {
679 char weeknumber[255];
680 char weekday_name[32];
682 localtime_r(&thetime, &tm);
685 /* Before displaying Sunday, start a new CELL */
687 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
688 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%%'> <tr><th colspan='4'>%s %s</th></tr>"
689 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
699 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
700 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
704 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
705 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
706 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
708 weekday_name,tm.tm_mday,
711 /* put the data of one day here, stupid */
712 calendar_month_view_brief_events(thetime, daycolor);
715 /* After displaying Saturday, end the row */
717 wprintf("</td></tr></table>\n");
720 thetime += (time_t)86400; /* ahead 24 hours */
723 wprintf("</table>" /* end of inner table */
724 "</td></tr></table>" /* end of outer table */
729 * Calendar week view -- not implemented yet, this is a stub function
731 void calendar_week_view(int year, int month, int day) {
732 wprintf("<center><i>week view FIXME</i></center><br />\n");
738 * Display events for a particular hour of a particular day.
739 * (Specify hour < 0 to show "all day" events)
741 * dstart and dend indicate which hours our "daytime" begins and end
743 void calendar_day_view_display_events(time_t thetime,
755 icalproperty *p = NULL;
756 icalproperty *q = NULL;
762 int all_day_event = 0;
763 int ongoing_event = 0;
766 struct icaltimetype t;
767 struct icaltimetype end_t;
768 struct icaltimetype today_start_t;
769 struct icaltimetype today_end_t;
770 struct tm starting_tm;
783 if (GetCount(WCC->disp_cal_items) == 0) {
784 /* nothing to display */
788 /* Create an imaginary event which spans the current day. Any events which
789 * overlap with this one take place at least partially in this day.
791 memset(&starting_tm, 0, sizeof(struct tm));
792 starting_tm.tm_year = year - 1900;
793 starting_tm.tm_mon = month - 1;
794 starting_tm.tm_mday = day;
795 starting_tm.tm_hour = 0;
796 starting_tm.tm_min = 0;
797 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
798 today_start_t.is_utc = 1;
800 memset(&ending_tm, 0, sizeof(struct tm));
801 ending_tm.tm_year = year - 1900;
802 ending_tm.tm_mon = month - 1;
803 ending_tm.tm_mday = day;
804 ending_tm.tm_hour = 23;
805 ending_tm.tm_min = 59;
806 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
807 today_end_t.is_utc = 1;
809 /* Now loop through our list of events to see which ones occur today.
811 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
812 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
813 Cal = (disp_cal*)vCal;
818 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
820 t = icalproperty_get_dtstart(q);
821 event_tt = icaltime_as_timet(t);
822 localtime_r(&event_tt, &event_te);
825 memset(&t, 0, sizeof t);
827 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
829 end_t = icalproperty_get_dtend(q);
830 event_tte = icaltime_as_timet(end_t);
831 localtime_r(&event_tte, &event_tm);
834 memset(&end_t, 0, sizeof end_t);
836 if (t.is_date) all_day_event = 1;
840 show_event = ((t.year == year) && (t.month == month) && (t.day == day) && (notime_events));
844 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
847 /* If we determined that this event occurs today, then display it.
849 p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
851 if ((show_event) && (p != NULL)) {
853 if ((event_te.tm_mday != day) || (event_tm.tm_mday != day)) ongoing_event = 1;
855 if (all_day_event && notime_events)
857 wprintf("<li class=\"event_framed%s\"> "
858 "<a href=\"display_edit_event?"
859 "msgnum=%ld?calview=day?year=%d?month=%d?day=%d\" "
860 " class=\"event_title\" "
862 (Cal->unread)?"_unread":"_read",
863 Cal->cal_msgnum, year, month, day);
864 wprintf("<i>%s</i><br />", _("All day event"));
865 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
866 wprintf("<i>%s</i> ", _("Summary:"));
867 escputs((char *) icalproperty_get_comment(p));
869 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
871 wprintf("<i>%s</i> ", _("Location:"));
872 escputs((char *)icalproperty_get_comment(q));
875 memset(&d_tm, 0, sizeof d_tm);
876 d_tm.tm_year = t.year - 1900;
877 d_tm.tm_mon = t.month - 1;
878 d_tm.tm_mday = t.day;
879 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
880 wprintf("<i>%s</i> %s<br>",_("Date:"), d_str);
881 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
883 wprintf("<i>%s</i> ", _("Notes:"));
884 escputs((char *)icalproperty_get_comment(q));
888 escputs((char *) icalproperty_get_comment(p));
889 wprintf("</a> <span>(");
890 wprintf(_("All day event"));
891 wprintf(")</span></li>\n");
893 else if (ongoing_event && notime_events)
895 wprintf("<li class=\"event_framed%s\"> "
896 "<a href=\"display_edit_event?"
897 "msgnum=%ld&calview=day?year=%d?month=%d?day=%d\" "
898 " class=\"event_title\" "
900 (Cal->unread)?"_unread":"_read",
901 Cal->cal_msgnum, year, month, day);
902 wprintf("<i>%s</i><br />", _("Ongoing event"));
903 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
904 wprintf("<i>%s</i> ", _("Summary:"));
905 escputs((char *) icalproperty_get_comment(p));
907 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
909 wprintf("<i>%s</i> ", _("Location:"));
910 escputs((char *)icalproperty_get_comment(q));
913 webcit_fmt_date(buf, event_tt, 1);
914 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
915 webcit_fmt_date(buf, event_tte, 1);
916 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
917 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
919 wprintf("<i>%s</i> ", _("Notes:"));
920 escputs((char *)icalproperty_get_comment(q));
924 escputs((char *) icalproperty_get_comment(p));
925 wprintf("</a> <span>(");
926 wprintf(_("Ongoing event"));
927 wprintf(")</span></li>\n");
929 else if (!all_day_event && !notime_events)
933 if (event_te.tm_mday != day) event_te.tm_hour = 0;
934 if (event_tm.tm_mday != day) event_tm.tm_hour = 24;
936 /* Calculate the location of the top of the box */
937 if (event_te.tm_hour < dstart) {
938 startmin = diffmin = event_te.tm_min / 6;
939 top = (event_te.tm_hour * 10) + startmin;
941 else if ((event_te.tm_hour >= dstart) && (event_te.tm_hour <= dend)) {
942 startmin = diffmin = (event_te.tm_min / 2);
943 top = (dstart * 10) + ((event_te.tm_hour - dstart) * 30) + startmin;
945 else if (event_te.tm_hour >dend) {
946 startmin = diffmin = event_te.tm_min / 6;
947 top = (dstart * 10) + ((dend - dstart - 1) * 30) + ((event_tm.tm_hour - dend + 1) * 10) + startmin ;
950 /* should never get here */
953 /* Calculate the location of the bottom of the box */
954 if (event_tm.tm_hour < dstart) {
955 endmin = diffmin = event_tm.tm_min / 6;
956 bottom = (event_tm.tm_hour * 10) + endmin;
958 else if ((event_tm.tm_hour >= dstart) && (event_tm.tm_hour <= dend)) {
959 endmin = diffmin = (event_tm.tm_min / 2);
960 bottom = (dstart * 10) + ((event_tm.tm_hour - dstart) * 30) + endmin ;
962 else if (event_tm.tm_hour >dend) {
963 endmin = diffmin = event_tm.tm_min / 6;
964 bottom = (dstart * 10) + ((dend - dstart + 1) * 30) + ((event_tm.tm_hour - dend - 1) * 10) + endmin;
967 /* should never get here */
970 wprintf("<dd class=\"event_framed%s\" "
971 "style=\"position: absolute; "
972 "top:%dpx; left:%dpx; "
974 (Cal->unread)?"_unread":"_read",
975 top, (gap * 40), (bottom-top)
977 wprintf("<a href=\"display_edit_event?"
978 "msgnum=%ld?calview=day?year=%d?month=%d?day=%d?hour=%d\" "
979 "class=\"event_title\" "
981 Cal->cal_msgnum, year, month, day, t.hour);
982 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
983 wprintf("<i>%s</i> ", _("Summary:"));
984 escputs((char *) icalproperty_get_comment(p));
986 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
988 wprintf("<i>%s</i> ", _("Location:"));
989 escputs((char *)icalproperty_get_comment(q));
992 webcit_fmt_date(buf, event_tt, 1);
993 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
994 webcit_fmt_date(buf, event_tte, 1);
995 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
996 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
998 wprintf("<i>%s</i> ", _("Notes:"));
999 escputs((char *)icalproperty_get_comment(q));
1004 escputs((char *) icalproperty_get_comment(p));
1005 wprintf("</a></dd>\n");
1009 DeleteHashPos(&Pos);
1015 void calendar_day_view(int year, int month, int day) {
1017 struct icaltimetype today, yesterday, tomorrow;
1025 int extratimeline = 0;
1028 time_format = get_time_format_cached ();
1029 get_pref_long("daystart", &daystart, 8);
1030 get_pref_long("dayend", &dayend, 17);
1032 /* when loading daystart/dayend, replace missing, corrupt, or impossible values with defaults */
1033 if ((daystart < 0) || (dayend < 2) || (daystart >= 23) || (dayend > 23) || (dayend <= daystart)) {
1039 memset(&d_tm, 0, sizeof d_tm);
1040 d_tm.tm_year = year - 1900;
1041 d_tm.tm_mon = month - 1;
1043 today_t = mktime(&d_tm);
1045 /* Figure out the dates for "yesterday" and "tomorrow" links */
1047 memset(&today, 0, sizeof(struct icaltimetype));
1049 today.month = month;
1053 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
1055 yesterday = icaltime_normalize(yesterday);
1057 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
1059 tomorrow = icaltime_normalize(tomorrow);
1061 wprintf("<div class=\"fix_scrollbar_bug\">");
1063 /* Inner table (the real one) */
1064 wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
1066 /* Innermost cell (contains hours etc.) */
1067 wprintf("<td class=\"events_of_the_day\" >");
1068 wprintf("<dl class=\"events\" >");
1070 /* Now the middle of the day... */
1072 extratimeline = timeline / 3;
1074 for (hour = 0; hour < daystart; ++hour) { /* could do HEIGHT=xx */
1075 wprintf("<dt class=\"extrahour\" "
1077 "position: absolute; "
1078 "top: %dpx; left: 0px; "
1081 "<a href=\"display_edit_event?msgnum=0"
1082 "?calview=day?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
1083 (hour * extratimeline ), extratimeline,
1084 year, month, day, hour
1087 if (time_format == WC_TIMEFORMAT_24) {
1088 wprintf("%2d:00</a> ", hour);
1091 wprintf("%d:00%s</a> ",
1092 (hour <= 12 ? hour : hour-12),
1093 (hour < 12 ? "am" : "pm")
1100 gap = daystart * extratimeline;
1102 for (hour = daystart; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
1103 wprintf("<dt class=\"hour\" "
1105 "position: absolute; "
1106 "top: %ldpx; left: 0px; "
1109 "<a href=\"display_edit_event?msgnum=0?calview=day"
1110 "?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
1111 gap + ((hour - daystart) * timeline ), timeline,
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 = gap + ((dayend - daystart + 1) * timeline);
1130 for (hour = (dayend + 1); hour < 24; ++hour) { /* could do HEIGHT=xx */
1131 wprintf("<dt class=\"extrahour\" "
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 - dayend - 1) * extratimeline ), extratimeline,
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 /* Display events with start and end times on this day */
1157 calendar_day_view_display_events(today_t, year, month, day, 0, daystart, dayend);
1160 wprintf("</td>"); /* end of innermost table */
1162 /* Display extra events (start/end times not present or not today) in the middle column */
1163 wprintf("<td class=\"extra_events\">");
1167 /* Display all-day events */
1168 calendar_day_view_display_events(today_t, year, month, day, 1, daystart, dayend);
1172 wprintf("</td>"); /* end extra on the middle */
1174 wprintf("<td width=20%% align=center valign=top>"); /* begin stuff-on-the-right */
1176 /* Begin todays-date-with-left-and-right-arrows */
1177 wprintf("<table border=0 width=100%% "
1178 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
1182 wprintf("<td align=center>");
1183 wprintf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">",
1184 yesterday.year, yesterday.month, yesterday.day);
1185 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
1188 wc_strftime(d_str, sizeof d_str,
1190 "<font size=+2>%B</font><br />"
1191 "<font size=+3>%d</font><br />"
1192 "<font size=+2>%Y</font><br />"
1196 wprintf("%s", d_str);
1199 wprintf("<td align=center>");
1200 wprintf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">",
1201 tomorrow.year, tomorrow.month, tomorrow.day);
1202 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
1203 " border=0></a>\n");
1206 wprintf("</tr></table>\n");
1207 /* End todays-date-with-left-and-right-arrows */
1209 /* Embed a mini month calendar in this space */
1210 wprintf("<br />\n");
1211 embeddable_mini_calendar(year, month);
1213 wprintf("</font></center>\n");
1215 wprintf("</td></tr>"); /* end stuff-on-the-right */
1217 wprintf("</table>" /* end of inner table */
1220 StrBufAppendPrintf(WC->trailing_javascript,
1221 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); \n"
1227 * Display today's events. Returns the number of items displayed.
1229 int calendar_summary_view(void) {
1231 const char *HashKey;
1236 struct icaltimetype t;
1241 int all_day_event = 0;
1242 char timestring[SIZ];
1243 wcsession *WCC = WC;
1244 int num_displayed = 0;
1246 if (GetCount(WC->disp_cal_items) == 0) {
1251 localtime_r(&now, &today_tm);
1253 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
1254 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
1255 Cal = (disp_cal*)vCal;
1256 p = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
1258 t = icalproperty_get_dtstart(p);
1259 event_tt = icaltime_as_timet(t);
1266 fmt_time(timestring, event_tt);
1268 if (all_day_event) {
1269 gmtime_r(&event_tt, &event_tm);
1272 localtime_r(&event_tt, &event_tm);
1275 if ( (event_tm.tm_year == today_tm.tm_year)
1276 && (event_tm.tm_mon == today_tm.tm_mon)
1277 && (event_tm.tm_mday == today_tm.tm_mday)
1280 p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
1284 if (WCC->wc_view == VIEW_TASKS) {
1285 wprintf("<a href=\"display_edit_task"
1287 "?return_to_summary=1"
1291 escputs(ChrPtr(WCC->wc_roomname));
1295 wprintf("<a href=\"display_edit_event"
1303 today_tm.tm_year + 1900,
1304 today_tm.tm_mon + 1,
1307 escputs(ChrPtr(WCC->wc_roomname));
1310 escputs((char *) icalproperty_get_comment(p));
1311 if (!all_day_event) {
1312 wprintf(" (%s)", timestring);
1314 wprintf("</a><br />\n");
1320 DeleteHashPos(&Pos);
1321 DeleteHash(&WC->disp_cal_items);
1322 return(num_displayed);
1326 * Parse the URL variables in order to determine the scope and display of a calendar view
1328 void parse_calendar_view_request(struct calview *c) {
1334 /* In case no date was specified, go with today */
1336 localtime_r(&now, &tm);
1337 c->year = tm.tm_year + 1900;
1338 c->month = tm.tm_mon + 1;
1339 c->day = tm.tm_mday;
1341 /* Now see if a date was specified */
1342 if (havebstr("year")) c->year = ibstr("year");
1343 if (havebstr("month")) c->month = ibstr("month");
1344 if (havebstr("day")) c->day = ibstr("day");
1346 /* How would you like that cooked? */
1347 if (havebstr("calview")) {
1348 strcpy(calview, bstr("calview"));
1351 strcpy(calview, "month");
1354 /* Display the selected view */
1355 if (!strcasecmp(calview, "day")) {
1356 c->view = calview_day;
1358 else if (!strcasecmp(calview, "week")) {
1359 c->view = calview_week;
1361 else if (!strcasecmp(calview, "summary")) { /* shouldn't ever happen, but just in case */
1362 c->view = calview_day;
1365 if (WC->wc_view == VIEW_CALBRIEF) {
1366 c->view = calview_brief;
1369 c->view = calview_month;
1373 /* Now try and set the lower and upper bounds so that we don't
1374 * burn too many cpu cycles parsing data way in the past or future
1377 tm.tm_year = c->year - 1900;
1378 tm.tm_mon = c->month - 1;
1379 tm.tm_mday = c->day;
1382 if (c->view == calview_month) span = 3888000;
1383 if (c->view == calview_brief) span = 3888000;
1384 if (c->view == calview_week) span = 604800;
1385 if (c->view == calview_day) span = 86400;
1386 if (c->view == calview_summary) span = 86400;
1388 c->lower_bound = now - span;
1389 c->upper_bound = now + span;
1395 * Render a calendar view from data previously loaded into memory
1397 void render_calendar_view(struct calview *c)
1399 if (c->view == calview_day) {
1400 calendar_day_view(c->year, c->month, c->day);
1402 else if (c->view == calview_week) {
1403 calendar_week_view(c->year, c->month, c->day);
1406 if (WC->wc_view == VIEW_CALBRIEF) {
1407 calendar_brief_month_view(c->year, c->month, c->day);
1410 calendar_month_view(c->year, c->month, c->day);
1414 /* Free the in-memory list of calendar items */
1415 DeleteHash(&WC->disp_cal_items);
1420 * Helper function for do_tasks_view(). Returns the due date/time of a vtodo.
1422 time_t get_task_due_date(icalcomponent *vtodo) {
1425 if (vtodo == NULL) {
1430 * If we're looking at a fully encapsulated VCALENDAR
1431 * rather than a VTODO component, recurse into the data
1432 * structure until we get a VTODO.
1434 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1435 return get_task_due_date(
1436 icalcomponent_get_first_component(
1437 vtodo, ICAL_VTODO_COMPONENT
1442 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1444 return(icaltime_as_timet(icalproperty_get_due(p)));
1453 * Compare the due dates of two tasks (this is for sorting)
1455 int task_due_cmp(const void *vtask1, const void *vtask2) {
1456 disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
1457 disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2);
1462 t1 = get_task_due_date(Task1->cal);
1463 t2 = get_task_due_date(Task2->cal);
1464 if (t1 < t2) return(-1);
1465 if (t1 > t2) return(1);
1470 * qsort filter to move completed tasks to bottom of task list
1472 int task_completed_cmp(const void *vtask1, const void *vtask2) {
1473 disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
1474 /* disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2); */
1476 icalproperty_status t1 = icalcomponent_get_status((Task1)->cal);
1477 /* icalproperty_status t2 = icalcomponent_get_status(((struct disp_cal *)task2)->cal); */
1479 if (t1 == ICAL_STATUS_COMPLETED)
1487 * do the whole task view stuff
1489 void do_tasks_view(void) {
1491 const char *HashKey;
1499 wcsession *WCC = WC;
1501 wprintf("<div class=\"fix_scrollbar_bug\">"
1502 "<table class=\"calendar_view_background\"><tbody id=\"taskview\">\n<tr>\n"
1504 wprintf(_("Completed?"));
1505 wprintf("</th><th>");
1506 wprintf(_("Name of task"));
1507 wprintf("</th><th>");
1508 wprintf(_("Date due"));
1509 wprintf("</th><th>");
1510 wprintf(_("Category"));
1511 wprintf(" (<select id=\"selectcategory\"><option value=\"showall\">%s</option></select>)</th></tr>\n",
1514 nItems = GetCount(WC->disp_cal_items);
1516 /* Sort them if necessary
1518 SortByPayload(WC->disp_cal_items, task_due_cmp);
1520 * this shouldn't be neccessary, since we sort by the start time.
1523 /* And then again, by completed */
1525 SortByPayload(WC->disp_cal_items,
1526 task_completed_cmp);
1529 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
1530 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
1531 icalproperty_status todoStatus;
1533 Cal = (disp_cal*)vCal;
1534 wprintf("<tr><td>");
1535 todoStatus = icalcomponent_get_status(Cal->cal);
1536 wprintf("<input type=\"checkbox\" name=\"completed\" value=\"completed\" ");
1537 if (todoStatus == ICAL_STATUS_COMPLETED) {
1538 wprintf("checked=\"checked\" ");
1540 wprintf("disabled=\"disabled\">\n</td><td>");
1541 p = icalcomponent_get_first_property(Cal->cal,
1542 ICAL_SUMMARY_PROPERTY);
1543 wprintf("<a href=\"display_edit_task?msgnum=%ld?taskrm=", Cal->cal_msgnum);
1544 urlescputs(ChrPtr(WC->wc_roomname));
1546 /* wprintf("<img align=middle "
1547 "src=\"static/taskmanag_16x.gif\" border=0> "); */
1549 escputs((char *)icalproperty_get_comment(p));
1554 due = get_task_due_date(Cal->cal);
1555 wprintf("<td><span");
1557 webcit_fmt_date(buf, due, 0);
1563 wprintf("</span></td>");
1565 p = icalcomponent_get_first_property(Cal->cal,
1566 ICAL_CATEGORIES_PROPERTY);
1568 escputs((char *)icalproperty_get_categories(p));
1574 wprintf("</tbody></table></div>\n");
1577 DeleteHash(&WC->disp_cal_items);
1578 DeleteHashPos(&Pos);