4 * Handles the HTML display of calendar items.
11 /* These define how high the hour rows are in the day view */
13 #define EXTRATIMELINE (TIMELINE / 2)
15 void embeddable_mini_calendar(int year, int month)
17 struct tm starting_tm;
21 time_t previous_month;
23 time_t colheader_time;
24 struct tm colheader_tm;
25 char colheader_label[32];
30 snprintf(div_id, sizeof div_id, "mini_calendar_%d", rand() );
32 /* Determine what day to start. If an impossible value is found, start on Sunday.
34 get_pref_long("weekstart", &weekstart, 17);
35 if (weekstart > 6) weekstart = 0;
38 * Now back up to the 1st of the month...
40 memset(&starting_tm, 0, sizeof(struct tm));
42 starting_tm.tm_year = year - 1900;
43 starting_tm.tm_mon = month - 1;
44 starting_tm.tm_mday = 1;
45 thetime = mktime(&starting_tm);
47 memcpy(&tm, &starting_tm, sizeof(struct tm));
48 while (tm.tm_mday != 1) {
49 thetime = thetime - (time_t)86400; /* go back 24 hours */
50 localtime_r(&thetime, &tm);
53 /* Determine previous and next months ... for links */
54 previous_month = thetime - (time_t)864000L; /* back 10 days */
55 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
57 /* Now back up until we're on the user's preferred start day */
58 localtime_r(&thetime, &tm);
59 while (tm.tm_wday != weekstart) {
60 thetime = thetime - (time_t)86400; /* go back 24 hours */
61 localtime_r(&thetime, &tm);
64 wc_printf("<div class=\"mini_calendar\" id=\"%s\">\n", div_id);
66 /* Previous month link */
67 localtime_r(&previous_month, &tm);
68 wc_printf("<a href=\"javascript:minical_change_month(%d,%d);\">«</a>",
69 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
71 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
72 wc_printf(" "
73 "<span class=\"mini_calendar_month_label\">"
76 " ", colheader_label, year);
79 localtime_r(&next_month, &tm);
80 wc_printf("<a href=\"javascript:minical_change_month(%d,%d);\">»</a>",
81 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
83 wc_printf("<table border=0 cellpadding=1 cellspacing=1 class=\"mini_calendar_days\">"
85 colheader_time = thetime;
87 colheader_time = thetime + (i * 86400) ;
88 localtime_r(&colheader_time, &colheader_tm);
89 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
90 wc_printf("<th>%c</th>", colheader_label[0]);
96 /* Now do 35 or 42 days */
97 for (i = 0; i < 42; ++i) {
98 localtime_r(&thetime, &tm);
102 /* Before displaying Sunday, start a new row */
107 if (tm.tm_mon == month-1) {
108 snprintf(url, sizeof url, "readfwd?calview=day&year=%d&month=%d&day=%d",
109 tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday);
110 wc_printf("<td><a href=\"%s\">%d</a></td>", url, tm.tm_mday);
113 wc_printf("<td> </td>");
116 /* After displaying one week, end the row */
118 wc_printf("</tr>\n");
123 thetime += (time_t)86400; /* ahead 24 hours */
126 wc_printf("</table>" /* end of inner table */
129 StrBufAppendPrintf(WC->trailing_javascript,
130 " function minical_change_month(year, month) { \n"
131 " p = 'year=' + year + '&month=' + month \n"
132 " + '&r=' + CtdlRandomString(); \n"
133 " new Ajax.Updater('%s', 'mini_calendar', \n"
134 " { method: 'get', parameters: p, evalScripts: true } ); \n"
143 * ajax embedder for the above mini calendar
145 void ajax_mini_calendar(void)
147 embeddable_mini_calendar( ibstr("year"), ibstr("month"));
152 * Display one day of a whole month view of a calendar
154 void calendar_month_view_display_events(int year, int month, int day)
161 icalproperty *p = NULL;
162 icalproperty *q = NULL;
163 struct icaltimetype t;
164 struct icaltimetype end_t;
165 struct icaltimetype today_start_t;
166 struct icaltimetype today_end_t;
167 struct icaltimetype today_t;
168 struct tm starting_tm;
170 int all_day_event = 0;
176 if (GetCount(WCC->disp_cal_items) == 0) {
177 wc_printf("<br /><br /><br />\n");
182 * Create an imaginary event which spans the 24 hours of today. Any events which
183 * overlap with this one take place at least partially in this day. We have to
184 * convert it from a struct tm in order to make it UTC.
186 memset(&starting_tm, 0, sizeof(struct tm));
187 starting_tm.tm_year = year - 1900;
188 starting_tm.tm_mon = month - 1;
189 starting_tm.tm_mday = day;
190 starting_tm.tm_hour = 0;
191 starting_tm.tm_min = 0;
192 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
193 today_start_t.is_utc = 1;
195 memset(&ending_tm, 0, sizeof(struct tm));
196 ending_tm.tm_year = year - 1900;
197 ending_tm.tm_mon = month - 1;
198 ending_tm.tm_mday = day;
199 ending_tm.tm_hour = 23;
200 ending_tm.tm_min = 59;
201 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
202 today_end_t.is_utc = 1;
205 * Create another one without caring about the timezone for all day events.
207 today_t = icaltime_null_date();
209 today_t.month = month;
213 * Now loop through our list of events to see which ones occur today.
215 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
216 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
217 Cal = (disp_cal*)vCal;
219 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
221 t = icalproperty_get_dtstart(q);
224 memset(&t, 0, sizeof t);
226 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
228 end_t = icalproperty_get_dtend(q);
231 memset(&end_t, 0, sizeof end_t);
233 if (t.is_date) all_day_event = 1;
237 show_event = ical_ctdl_is_overlap(t, end_t, today_t, icaltime_null_time());
241 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
245 * If we determined that this event occurs today, then display it.
248 p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
250 p = icalproperty_new_summary(_("Untitled Event"));
251 icalcomponent_add_property(Cal->cal, p);
256 wc_printf("<table border=0 cellpadding=2><TR>"
257 "<td bgcolor=\"#CCCCDD\">"
261 wc_printf("<font size=\"-1\">"
262 "<a class=\"event%s\" href=\"display_edit_event?"
263 "msgnum=%ld?calview=month?year=%d?month=%d?day=%d\""
265 (Cal->unread)?"_unread":"_read",
270 wc_printf("<i>%s: %s</i><br />", _("From"), Cal->from);
271 wc_printf("<i>%s</i> ", _("Summary:"));
272 escputs((char *)icalproperty_get_comment(p));
275 q = icalcomponent_get_first_property(
277 ICAL_LOCATION_PROPERTY);
279 wc_printf("<i>%s</i> ", _("Location:"));
280 escputs((char *)icalproperty_get_comment(q));
285 * Only show start/end times if we're actually looking at the VEVENT
286 * component. Otherwise it shows bogus dates for e.g. timezones
288 if (icalcomponent_isa(Cal->cal) == ICAL_VEVENT_COMPONENT) {
290 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
294 t = icalproperty_get_dtstart(q);
295 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
297 end_t = icalproperty_get_dtend(q);
301 * events with starting date/time equal
302 * ending date/time might get only
303 * DTSTART but no DTEND
313 /* end given, have to adjust it */
314 icaltime_adjust(&end_t, -1, 0, 0, 0);
316 memset(&d_tm, 0, sizeof d_tm);
317 d_tm.tm_year = t.year - 1900;
318 d_tm.tm_mon = t.month - 1;
319 d_tm.tm_mday = t.day;
320 wc_strftime(buf, sizeof buf, "%x", &d_tm);
322 if (no_end || !icaltime_compare(t, end_t)) {
323 wc_printf("<i>%s</i> %s<br>",
327 wc_printf("<i>%s</i> %s<br>",
328 _("Starting date:"), buf);
329 d_tm.tm_year = end_t.year - 1900;
330 d_tm.tm_mon = end_t.month - 1;
331 d_tm.tm_mday = end_t.day;
332 wc_strftime(buf, sizeof buf, "%x", &d_tm);
333 wc_printf("<i>%s</i> %s<br>",
334 _("Ending date:"), buf);
338 tt = icaltime_as_timet(t);
339 webcit_fmt_date(buf, 256, tt, DATEFMT_BRIEF);
340 if (no_end || !icaltime_compare(t, end_t)) {
341 wc_printf("<i>%s</i> %s<br>",
342 _("Date/time:"), buf);
345 wc_printf("<i>%s</i> %s<br>",
346 _("Starting date/time:"), buf);
347 tt = icaltime_as_timet(end_t);
348 webcit_fmt_date(buf, 256, tt, DATEFMT_BRIEF);
349 wc_printf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
357 q = icalcomponent_get_first_property(Cal->cal, ICAL_DESCRIPTION_PROPERTY);
359 wc_printf("<i>%s</i> ", _("Notes:"));
360 escputs((char *)icalproperty_get_comment(q));
366 icalproperty_get_comment(p));
367 wc_printf("</a></font><br />\n");
370 wc_printf("</td></tr></table>");
384 * Display one day of a whole month view of a calendar
386 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
400 struct icaltimetype t;
402 int month, day, year;
403 int all_day_event = 0;
407 time_format = get_time_format_cached ();
409 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
410 else timeformat="%I:%M %p";
412 localtime_r(&thetime, &today_tm);
413 month = today_tm.tm_mon + 1;
414 day = today_tm.tm_mday;
415 year = today_tm.tm_year + 1900;
417 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
418 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
419 Cal = (disp_cal*)vCal;
420 p = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
422 t = icalproperty_get_dtstart(p);
423 event_tt = icaltime_as_timet(t);
425 if (t.is_date) all_day_event = 1;
426 else all_day_event = 0;
429 gmtime_r(&event_tts, &event_tms);
432 localtime_r(&event_tts, &event_tms);
434 /* \todo epoch &! daymask */
435 if ((event_tms.tm_year == today_tm.tm_year)
436 && (event_tms.tm_mon == today_tm.tm_mon)
437 && (event_tms.tm_mday == today_tm.tm_mday)) {
443 p = icalcomponent_get_first_property(
445 ICAL_SUMMARY_PROPERTY);
447 p = icalproperty_new_summary(_("Untitled Event"));
448 icalcomponent_add_property(Cal->cal, p);
450 e = icalcomponent_get_first_property(
452 ICAL_DTEND_PROPERTY);
453 if ((p != NULL) && (e != NULL)) {
456 t = icalproperty_get_dtend(e);
457 event_tte = icaltime_as_timet(t);
458 localtime_r(&event_tte, &event_tme);
459 difftime=(event_tte-event_tts)/60;
460 hours=(int)(difftime / 60);
461 minutes=difftime % 60;
462 wc_printf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
464 "<a class=\"event%s\" href=\"display_edit_event?msgnum=%ld?calview=calbrief?year=%s?month=%s?day=%s\">",
467 (Cal->unread)?"_unread":"_read",
476 icalproperty_get_comment(p));
477 /* \todo: allso ammitime format */
478 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
479 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
481 wc_printf("</a></font></td>"
482 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
499 * view one month. pretty view
501 void calendar_month_view(int year, int month, int day) {
502 struct tm starting_tm;
507 time_t previous_month;
509 time_t colheader_time;
511 struct tm colheader_tm;
512 char colheader_label[32];
516 * Make sure we know which day is today.
518 today_timet = time(NULL);
519 localtime_r(&today_timet, &today_tm);
522 * Determine what day to start. If an impossible value is found, start on Sunday.
524 get_pref_long("weekstart", &weekstart, 17);
525 if (weekstart > 6) weekstart = 0;
528 * Now back up to the 1st of the month...
530 memset(&starting_tm, 0, sizeof(struct tm));
532 starting_tm.tm_year = year - 1900;
533 starting_tm.tm_mon = month - 1;
534 starting_tm.tm_mday = day;
535 thetime = mktime(&starting_tm);
537 memcpy(&tm, &starting_tm, sizeof(struct tm));
538 while (tm.tm_mday != 1) {
539 thetime = thetime - (time_t)86400; /* go back 24 hours */
540 localtime_r(&thetime, &tm);
543 /* Determine previous and next months ... for links */
544 previous_month = thetime - (time_t)864000L; /* back 10 days */
545 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
547 /* Now back up until we're on the user's preferred start day */
548 localtime_r(&thetime, &tm);
549 while (tm.tm_wday != weekstart) {
550 thetime = thetime - (time_t)86400; /* go back 24 hours */
551 localtime_r(&thetime, &tm);
554 /* Outer table (to get the background color) */
555 wc_printf("<div class=\"fix_scrollbar_bug\">"
556 "<table class=\"calendar\"> \n <tr><td>");
558 wc_printf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
560 wc_printf("<td align=center>");
562 localtime_r(&previous_month, &tm);
563 wc_printf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
564 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
565 wc_printf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
567 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
568 wc_printf(" "
569 "<font size=+1 color=\"#FFFFFF\">"
572 " ", colheader_label, year);
574 localtime_r(&next_month, &tm);
575 wc_printf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
576 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
577 wc_printf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
579 wc_printf("</td></tr></table>\n");
581 /* Inner table (the real one) */
582 wc_printf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
583 "bgcolor=#204B78 id=\"inner_month\"><tr>");
584 wc_printf("<th align=center width=2%%></th>");
585 colheader_time = thetime;
586 for (i=0; i<7; ++i) {
587 colheader_time = thetime + (i * 86400) ;
588 localtime_r(&colheader_time, &colheader_tm);
589 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
590 wc_printf("<th align=center width=14%%>"
591 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
594 wc_printf("</tr>\n");
597 /* Now do 35 or 42 days */
598 localtime_r(&thetime, &tm);
599 for (i = 0; i<42; ++i) {
601 /* Before displaying the first day of the week, start a new row */
603 wc_printf("<tr><td class=\"week_of_year\">");
604 wc_strftime(colheader_label, sizeof colheader_label, "%V", &tm);
605 wc_printf("%s ", colheader_label);
608 wc_printf("<td class=\"cal%s\"><div class=\"day\">",
609 ((tm.tm_mon != month-1) ? "out" :
610 (((tm.tm_year == today_tm.tm_year) && (tm.tm_mon == today_tm.tm_mon) && (tm.tm_mday == today_tm.tm_mday)) ? "today" :
611 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
614 if ((i==0) || (tm.tm_mday == 1)) {
615 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
616 wc_printf("%s ", colheader_label);
618 wc_printf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">"
625 /* put the data here, stupid */
626 calendar_month_view_display_events(
634 /* After displaying the last day of the week, end the row */
636 wc_printf("</tr>\n");
639 thetime += (time_t)86400; /* ahead 24 hours */
640 localtime_r(&thetime, &tm);
642 if ( ((i % 7) == 6) && (tm.tm_mon != month-1) && (tm.tm_mday < 15) ) {
643 i = 100; /* break out of the loop */
647 wc_printf("</table>" /* end of inner table */
648 "</td></tr></table>" /* end of outer table */
652 * Initialize the bubble tooltips.
654 * Yes, this is as stupid as it looks. Instead of just making the call
655 * to btt_enableTooltips() straight away, we have to create a timer event
656 * and let it initialize as an event after 1 millisecond. This is to
657 * work around a bug in Internet Explorer that causes it to crash if we
658 * manipulate the innerHTML of various DOM nodes while the page is still
659 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
660 * for more information.
662 StrBufAppendPrintf(WC->trailing_javascript,
663 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); \n"
668 * view one month. brief view
670 void calendar_brief_month_view(int year, int month, int day) {
671 struct tm starting_tm;
675 time_t previous_month;
677 char month_label[32];
679 /* Determine what day to start.
680 * First, back up to the 1st of the month...
682 memset(&starting_tm, 0, sizeof(struct tm));
683 starting_tm.tm_year = year - 1900;
684 starting_tm.tm_mon = month - 1;
685 starting_tm.tm_mday = day;
686 thetime = mktime(&starting_tm);
688 memcpy(&tm, &starting_tm, sizeof(struct tm));
689 while (tm.tm_mday != 1) {
690 thetime = thetime - (time_t)86400; /* go back 24 hours */
691 localtime_r(&thetime, &tm);
694 /* Determine previous and next months ... for links */
695 previous_month = thetime - (time_t)864000L; /* back 10 days */
696 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
698 /* Now back up until we're on a Sunday */
699 localtime_r(&thetime, &tm);
700 while (tm.tm_wday != 0) {
701 thetime = thetime - (time_t)86400; /* go back 24 hours */
702 localtime_r(&thetime, &tm);
705 /* Outer table (to get the background color) */
706 wc_printf("<div class=\"fix_scrollbar_bug\">"
707 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
708 "bgcolor=#204B78><TR><TD>\n");
710 wc_printf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
712 wc_printf("<td align=center>");
714 localtime_r(&previous_month, &tm);
715 wc_printf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
716 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
717 wc_printf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
719 wc_strftime(month_label, sizeof month_label, "%B", &tm);
720 wc_printf(" "
721 "<font size=+1 color=\"#FFFFFF\">"
724 " ", month_label, year);
726 localtime_r(&next_month, &tm);
727 wc_printf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
728 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
729 wc_printf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
731 wc_printf("</td></tr></table>\n");
733 /* Inner table (the real one) */
734 wc_printf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
735 "bgcolor=#EEEECC><TR>");
736 wc_printf("</tr>\n");
737 wc_printf("<tr><td colspan=\"100%%\">\n");
740 for (i = 0; i < 35; ++i) {
741 char weeknumber[255];
742 char weekday_name[32];
744 localtime_r(&thetime, &tm);
747 /* Before displaying Sunday, start a new CELL */
749 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
750 wc_printf("<table border='0' bgcolor=\"#EEEECC\" width='100%%'> <tr><th colspan='4'>%s %s</th></tr>"
751 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
761 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
762 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
766 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
767 wc_printf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
768 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
770 weekday_name,tm.tm_mday,
773 /* put the data of one day here, stupid */
774 calendar_month_view_brief_events(thetime, daycolor);
777 /* After displaying Saturday, end the row */
779 wc_printf("</td></tr></table>\n");
782 thetime += (time_t)86400; /* ahead 24 hours */
785 wc_printf("</table>" /* end of inner table */
786 "</td></tr></table>" /* end of outer table */
791 * Calendar week view -- not implemented yet, this is a stub function
793 void calendar_week_view(int year, int month, int day) {
794 wc_printf("<center><i>week view FIXME</i></center><br />\n");
800 * Display events for a particular hour of a particular day.
801 * (Specify hour < 0 to show "all day" events)
803 * dstart and dend indicate which hours our "daytime" begins and end
805 void calendar_day_view_display_events(time_t thetime,
817 icalproperty *p = NULL;
818 icalproperty *q = NULL;
824 int all_day_event = 0;
825 int ongoing_event = 0;
828 struct icaltimetype t;
829 struct icaltimetype end_t;
830 struct icaltimetype today_start_t;
831 struct icaltimetype today_end_t;
832 struct icaltimetype today_t;
833 struct tm starting_tm;
844 if (GetCount(WCC->disp_cal_items) == 0) {
845 /* nothing to display */
849 /* Create an imaginary event which spans the current day. Any events which
850 * overlap with this one take place at least partially in this day.
852 memset(&starting_tm, 0, sizeof(struct tm));
853 starting_tm.tm_year = year - 1900;
854 starting_tm.tm_mon = month - 1;
855 starting_tm.tm_mday = day;
856 starting_tm.tm_hour = 0;
857 starting_tm.tm_min = 0;
858 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
859 today_start_t.is_utc = 1;
861 memset(&ending_tm, 0, sizeof(struct tm));
862 ending_tm.tm_year = year - 1900;
863 ending_tm.tm_mon = month - 1;
864 ending_tm.tm_mday = day;
865 ending_tm.tm_hour = 23;
866 ending_tm.tm_min = 59;
867 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
868 today_end_t.is_utc = 1;
871 * Create another one without caring about the timezone for all day events.
873 today_t = icaltime_null_date();
875 today_t.month = month;
878 /* Now loop through our list of events to see which ones occur today.
880 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
881 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
882 Cal = (disp_cal*)vCal;
887 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
889 t = icalproperty_get_dtstart(q);
890 event_tt = icaltime_as_timet(t);
891 localtime_r(&event_tt, &event_te);
894 memset(&t, 0, sizeof t);
897 if (t.is_date) all_day_event = 1;
899 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
901 end_t = icalproperty_get_dtend(q);
904 /* no end given means end = start */
905 memcpy(&end_t, &t, sizeof(struct icaltimetype));
910 show_event = ical_ctdl_is_overlap(t, end_t, today_t, icaltime_null_time());
911 if (icaltime_compare(t, end_t)) {
913 * the end date is non-inclusive so adjust it by one
914 * day because our test is inclusive, note that a day is
915 * not to much because we are talking about all day
918 icaltime_adjust(&end_t, -1, 0, 0, 0);
923 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
926 event_tte = icaltime_as_timet(end_t);
927 localtime_r(&event_tte, &event_tm);
929 /* If we determined that this event occurs today, then display it.
931 p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
933 p = icalproperty_new_summary(_("Untitled Event"));
934 icalcomponent_add_property(Cal->cal, p);
937 if ((show_event) && (p != NULL)) {
939 if ((event_te.tm_mday != day) || (event_tm.tm_mday != day)) ongoing_event = 1;
941 if (all_day_event && notime_events)
943 wc_printf("<li class=\"event_framed%s\"> "
944 "<a href=\"display_edit_event?"
945 "msgnum=%ld?calview=day?year=%d?month=%d?day=%d\" "
946 " class=\"event_title\" "
948 (Cal->unread)?"_unread":"_read",
949 Cal->cal_msgnum, year, month, day);
950 wc_printf("<i>%s</i><br />", _("All day event"));
951 wc_printf("<i>%s: %s</i><br />", _("From"), Cal->from);
952 wc_printf("<i>%s</i> ", _("Summary:"));
953 escputs((char *) icalproperty_get_comment(p));
955 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
957 wc_printf("<i>%s</i> ", _("Location:"));
958 escputs((char *)icalproperty_get_comment(q));
961 if (!icaltime_compare(t, end_t)) { /* one day only */
962 webcit_fmt_date(buf, 256, event_tt, DATEFMT_LOCALEDATE);
963 wc_printf("<i>%s</i> %s<br>", _("Date:"), buf);
966 webcit_fmt_date(buf, 256, event_tt, DATEFMT_LOCALEDATE);
967 wc_printf("<i>%s</i> %s<br>", _("Starting date:"), buf);
968 webcit_fmt_date(buf, 256, event_tte, DATEFMT_LOCALEDATE);
969 wc_printf("<i>%s</i> %s<br>", _("Ending date:"), buf);
971 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
973 wc_printf("<i>%s</i> ", _("Notes:"));
974 escputs((char *)icalproperty_get_comment(q));
978 escputs((char *) icalproperty_get_comment(p));
979 wc_printf("</a> <span>(");
980 wc_printf(_("All day event"));
981 wc_printf(")</span></li>\n");
983 else if (ongoing_event && notime_events)
985 wc_printf("<li class=\"event_framed%s\"> "
986 "<a href=\"display_edit_event?"
987 "msgnum=%ld&calview=day?year=%d?month=%d?day=%d\" "
988 " class=\"event_title\" "
990 (Cal->unread)?"_unread":"_read",
991 Cal->cal_msgnum, year, month, day);
992 wc_printf("<i>%s</i><br />", _("Ongoing event"));
993 wc_printf("<i>%s: %s</i><br />", _("From"), Cal->from);
994 wc_printf("<i>%s</i> ", _("Summary:"));
995 escputs((char *) icalproperty_get_comment(p));
997 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
999 wc_printf("<i>%s</i> ", _("Location:"));
1000 escputs((char *)icalproperty_get_comment(q));
1001 wc_printf("<br />");
1003 webcit_fmt_date(buf, 256, event_tt, DATEFMT_BRIEF);
1004 wc_printf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
1005 webcit_fmt_date(buf, 256, event_tte, DATEFMT_BRIEF);
1006 wc_printf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
1007 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
1009 wc_printf("<i>%s</i> ", _("Notes:"));
1010 escputs((char *)icalproperty_get_comment(q));
1011 wc_printf("<br />");
1014 escputs((char *) icalproperty_get_comment(p));
1015 wc_printf("</a> <span>(");
1016 wc_printf(_("Ongoing event"));
1017 wc_printf(")</span></li>\n");
1019 else if (!all_day_event && !notime_events)
1023 if (event_te.tm_mday != day) event_te.tm_hour = 0;
1024 if (event_tm.tm_mday != day) event_tm.tm_hour = 24;
1026 /* Calculate the location of the top of the box */
1027 if (event_te.tm_hour < dstart) {
1028 startmin = diffmin = event_te.tm_min / 6;
1029 top = (event_te.tm_hour * EXTRATIMELINE) + startmin;
1031 else if ((event_te.tm_hour >= dstart) && (event_te.tm_hour <= dend)) {
1032 startmin = diffmin = (event_te.tm_min / 2);
1033 top = (dstart * EXTRATIMELINE) + ((event_te.tm_hour - dstart) * TIMELINE) + startmin;
1035 else if (event_te.tm_hour >dend) {
1036 startmin = diffmin = event_te.tm_min / 6;
1037 top = (dstart * EXTRATIMELINE) + ((dend - dstart - 1) * TIMELINE) + ((event_tm.tm_hour - dend + 1) * EXTRATIMELINE) + startmin ;
1040 /* should never get here */
1043 /* Calculate the location of the bottom of the box */
1044 if (event_tm.tm_hour < dstart) {
1045 endmin = diffmin = event_tm.tm_min / 6;
1046 bottom = (event_tm.tm_hour * EXTRATIMELINE) + endmin;
1048 else if ((event_tm.tm_hour >= dstart) && (event_tm.tm_hour <= dend)) {
1049 endmin = diffmin = (event_tm.tm_min / 2);
1050 bottom = (dstart * EXTRATIMELINE) + ((event_tm.tm_hour - dstart) * TIMELINE) + endmin ;
1052 else if (event_tm.tm_hour >dend) {
1053 endmin = diffmin = event_tm.tm_min / 6;
1054 bottom = (dstart * EXTRATIMELINE) + ((dend - dstart + 1) * TIMELINE) + ((event_tm.tm_hour - dend - 1) * EXTRATIMELINE) + endmin;
1057 /* should never get here */
1060 wc_printf("<dd class=\"event_framed%s\" "
1061 "style=\"position: absolute; "
1062 "top:%dpx; left:%dpx; "
1063 "height:%dpx; \" >",
1064 (Cal->unread)?"_unread":"_read",
1065 top, (gap * 40), (bottom-top)
1067 wc_printf("<a href=\"display_edit_event?"
1068 "msgnum=%ld?calview=day?year=%d?month=%d?day=%d?hour=%d\" "
1069 "class=\"event_title\" "
1071 Cal->cal_msgnum, year, month, day, t.hour);
1072 wc_printf("<i>%s: %s</i><br />", _("From"), Cal->from);
1073 wc_printf("<i>%s</i> ", _("Summary:"));
1074 escputs((char *) icalproperty_get_comment(p));
1075 wc_printf("<br />");
1076 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
1078 wc_printf("<i>%s</i> ", _("Location:"));
1079 escputs((char *)icalproperty_get_comment(q));
1080 wc_printf("<br />");
1082 if (!icaltime_compare(t, end_t)) { /* one day only */
1083 webcit_fmt_date(buf, 256, event_tt, DATEFMT_BRIEF);
1084 wc_printf("<i>%s</i> %s<br>", _("Date/time:"), buf);
1087 webcit_fmt_date(buf, 256, event_tt, DATEFMT_BRIEF);
1088 wc_printf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
1089 webcit_fmt_date(buf, 256, event_tte, DATEFMT_BRIEF);
1090 wc_printf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
1092 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
1094 wc_printf("<i>%s</i> ", _("Notes:"));
1095 escputs((char *)icalproperty_get_comment(q));
1096 wc_printf("<br />");
1100 escputs((char *) icalproperty_get_comment(p));
1101 wc_printf("</a></dd>\n");
1105 DeleteHashPos(&Pos);
1111 void calendar_day_view(int year, int month, int day) {
1113 struct icaltimetype today, yesterday, tomorrow;
1120 int timeline = TIMELINE;
1121 int extratimeline = EXTRATIMELINE;
1126 time_format = get_time_format_cached ();
1127 get_pref_long("daystart", &daystart, 8);
1128 get_pref_long("dayend", &dayend, 17);
1130 /* when loading daystart/dayend, replace missing, corrupt, or impossible values with defaults */
1131 if ((daystart < 0) || (dayend < 2) || (daystart >= 23) || (dayend > 23) || (dayend <= daystart)) {
1137 memset(&d_tm, 0, sizeof d_tm);
1138 d_tm.tm_year = year - 1900;
1139 d_tm.tm_mon = month - 1;
1141 today_t = mktime(&d_tm);
1143 /* Figure out the dates for "yesterday" and "tomorrow" links */
1145 memset(&today, 0, sizeof(struct icaltimetype));
1147 today.month = month;
1151 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
1153 yesterday = icaltime_normalize(yesterday);
1155 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
1157 tomorrow = icaltime_normalize(tomorrow);
1159 wc_printf("<div class=\"fix_scrollbar_bug\">");
1161 /* Inner table (the real one) */
1162 wc_printf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
1164 /* Innermost cell (contains hours etc.) */
1165 wc_printf("<td class=\"events_of_the_day\" >");
1166 wc_printf("<dl class=\"events\" >");
1168 /* Now the middle of the day... */
1170 extrahourlabel = extratimeline - 2;
1171 hourlabel = extrahourlabel * 150 / 100;
1172 if (hourlabel > (timeline - 2)) hourlabel = timeline - 2;
1174 for (hour = 0; hour < daystart; ++hour) { /* could do HEIGHT=xx */
1175 wc_printf("<dt class=\"extrahour\" "
1177 "position: absolute; "
1178 "top: %dpx; left: 0px; "
1182 "<a href=\"display_edit_event?msgnum=0"
1183 "?calview=day?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
1184 (hour * extratimeline ),
1187 year, month, day, hour
1190 if (time_format == WC_TIMEFORMAT_24) {
1191 wc_printf("%2d:00</a> ", hour);
1194 wc_printf("%d:00%s</a> ",
1195 ((hour == 0) ? 12 : (hour <= 12 ? hour : hour-12)),
1196 (hour < 12 ? "am" : "pm")
1203 gap = daystart * extratimeline;
1205 for (hour = daystart; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
1206 wc_printf("<dt class=\"hour\" "
1208 "position: absolute; "
1209 "top: %ldpx; left: 0px; "
1213 "<a href=\"display_edit_event?msgnum=0?calview=day"
1214 "?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
1215 gap + ((hour - daystart) * timeline ),
1218 year, month, day, hour
1221 if (time_format == WC_TIMEFORMAT_24) {
1222 wc_printf("%2d:00</a> ", hour);
1225 wc_printf("%d:00%s</a> ",
1226 (hour <= 12 ? hour : hour-12),
1227 (hour < 12 ? "am" : "pm")
1234 gap = gap + ((dayend - daystart + 1) * timeline);
1236 for (hour = (dayend + 1); hour < 24; ++hour) { /* could do HEIGHT=xx */
1237 wc_printf("<dt class=\"extrahour\" "
1239 "position: absolute; "
1240 "top: %ldpx; left: 0px; "
1244 "<a href=\"display_edit_event?msgnum=0?calview=day"
1245 "?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
1246 gap + ((hour - dayend - 1) * extratimeline ),
1249 year, month, day, hour
1252 if (time_format == WC_TIMEFORMAT_24) {
1253 wc_printf("%2d:00</a> ", hour);
1256 wc_printf("%d:00%s</a> ",
1257 (hour <= 12 ? hour : hour-12),
1258 (hour < 12 ? "am" : "pm")
1265 /* Display events with start and end times on this day */
1266 calendar_day_view_display_events(today_t, year, month, day, 0, daystart, dayend);
1269 wc_printf("</td>"); /* end of innermost table */
1271 /* Display extra events (start/end times not present or not today) in the middle column */
1272 wc_printf("<td class=\"extra_events\">");
1276 /* Display all-day events */
1277 calendar_day_view_display_events(today_t, year, month, day, 1, daystart, dayend);
1281 wc_printf("</td>"); /* end extra on the middle */
1283 wc_printf("<td width=20%% align=center valign=top>"); /* begin stuff-on-the-right */
1285 /* Begin todays-date-with-left-and-right-arrows */
1286 wc_printf("<table border=0 width=100%% "
1287 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
1291 wc_printf("<td align=center>");
1292 wc_printf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">",
1293 yesterday.year, yesterday.month, yesterday.day);
1294 wc_printf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
1297 wc_strftime(d_str, sizeof d_str,
1299 "<font size=+2>%A</font><br />"
1300 "<font size=+2>%B</font><br />"
1301 "<font size=+3>%d</font><br />"
1302 "<font size=+2>%Y</font><br />"
1306 wc_printf("%s", d_str);
1309 wc_printf("<td align=center>");
1310 wc_printf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">",
1311 tomorrow.year, tomorrow.month, tomorrow.day);
1312 wc_printf("<img align=middle src=\"static/nextdate_32x.gif\""
1313 " border=0></a>\n");
1316 wc_printf("</tr></table>\n");
1317 /* End todays-date-with-left-and-right-arrows */
1319 /* Embed a mini month calendar in this space */
1320 wc_printf("<br />\n");
1321 embeddable_mini_calendar(year, month);
1323 wc_printf("</font></center>\n");
1325 wc_printf("</td></tr>"); /* end stuff-on-the-right */
1327 wc_printf("</table>" /* end of inner table */
1330 StrBufAppendPrintf(WC->trailing_javascript,
1331 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); \n"
1337 * Display today's events. Returns the number of items displayed.
1339 int calendar_summary_view(void) {
1341 const char *HashKey;
1346 struct icaltimetype t;
1351 int all_day_event = 0;
1352 char timestring[SIZ];
1353 wcsession *WCC = WC;
1354 int num_displayed = 0;
1356 if (GetCount(WC->disp_cal_items) == 0) {
1361 localtime_r(&now, &today_tm);
1363 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
1364 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
1365 Cal = (disp_cal*)vCal;
1366 p = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
1368 t = icalproperty_get_dtstart(p);
1369 event_tt = icaltime_as_timet(t);
1376 fmt_time(timestring, SIZ, event_tt);
1378 if (all_day_event) {
1379 gmtime_r(&event_tt, &event_tm);
1382 localtime_r(&event_tt, &event_tm);
1385 if ( (event_tm.tm_year == today_tm.tm_year)
1386 && (event_tm.tm_mon == today_tm.tm_mon)
1387 && (event_tm.tm_mday == today_tm.tm_mday)
1390 p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
1392 p = icalproperty_new_summary(_("Untitled Task"));
1393 icalcomponent_add_property(Cal->cal, p);
1398 if (WCC->wc_view == VIEW_TASKS) {
1399 wc_printf("<a href=\"display_edit_task"
1401 "?return_to_summary=1"
1405 escputs(ChrPtr(WCC->wc_roomname));
1409 wc_printf("<a href=\"display_edit_event"
1417 today_tm.tm_year + 1900,
1418 today_tm.tm_mon + 1,
1421 escputs(ChrPtr(WCC->wc_roomname));
1424 escputs((char *) icalproperty_get_comment(p));
1425 if (!all_day_event) {
1426 wc_printf(" (%s)", timestring);
1428 wc_printf("</a><br />\n");
1434 DeleteHashPos(&Pos);
1435 DeleteHash(&WC->disp_cal_items);
1436 return(num_displayed);
1440 * Parse the URL variables in order to determine the scope and display of a calendar view
1442 int calendar_GetParamsGetServerCall(SharedMessageStatus *Stat,
1443 void **ViewSpecific,
1455 c = (calview*) malloc(sizeof(calview));
1456 memset(c, 0, sizeof(calview));
1457 *ViewSpecific = (void*)c;
1459 Stat->load_seen = 1;
1460 strcpy(cmd, "MSGS ALL");
1461 Stat->maxmsgs = 32767;
1463 /* In case no date was specified, go with today */
1465 localtime_r(&now, &tm);
1466 c->year = tm.tm_year + 1900;
1467 c->month = tm.tm_mon + 1;
1468 c->day = tm.tm_mday;
1470 /* Now see if a date was specified */
1471 if (havebstr("year")) c->year = ibstr("year");
1472 if (havebstr("month")) c->month = ibstr("month");
1473 if (havebstr("day")) c->day = ibstr("day");
1475 /* How would you like that cooked? */
1476 if (havebstr("calview")) {
1477 strcpy(cv, bstr("calview"));
1480 strcpy(cv, "month");
1483 /* Display the selected view */
1484 if (!strcasecmp(cv, "day")) {
1485 c->view = calview_day;
1487 else if (!strcasecmp(cv, "week")) {
1488 c->view = calview_week;
1490 else if (!strcasecmp(cv, "summary")) { /* shouldn't ever happen, but just in case */
1491 c->view = calview_day;
1494 if (WC->wc_view == VIEW_CALBRIEF) {
1495 c->view = calview_brief;
1498 c->view = calview_month;
1502 /* Now try and set the lower and upper bounds so that we don't
1503 * burn too many cpu cycles parsing data way in the past or future
1506 tm.tm_year = c->year - 1900;
1507 tm.tm_mon = c->month - 1;
1508 tm.tm_mday = c->day;
1511 if (c->view == calview_month) span = 3888000;
1512 if (c->view == calview_brief) span = 3888000;
1513 if (c->view == calview_week) span = 604800;
1514 if (c->view == calview_day) span = 86400;
1515 if (c->view == calview_summary) span = 86400;
1517 c->lower_bound = now - span;
1518 c->upper_bound = now + span;
1525 * Render a calendar view from data previously loaded into memory
1527 int calendar_RenderView_or_Tail(SharedMessageStatus *Stat,
1528 void **ViewSpecific,
1531 calview *c = (calview*) *ViewSpecific;
1533 if (c->view == calview_day) {
1534 calendar_day_view(c->year, c->month, c->day);
1536 else if (c->view == calview_week) {
1537 calendar_week_view(c->year, c->month, c->day);
1540 if (WC->wc_view == VIEW_CALBRIEF) {
1541 calendar_brief_month_view(c->year, c->month, c->day);
1544 calendar_month_view(c->year, c->month, c->day);
1548 /* Free the in-memory list of calendar items */
1549 DeleteHash(&WC->disp_cal_items);