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];
23 char weekstart_buf[16];
26 char escaped_urlformat[256];
28 snprintf(div_id, sizeof div_id, "mini_calendar_%d", rand() );
30 /* Determine what day to start.
32 get_preference("weekstart", weekstart_buf, sizeof weekstart_buf);
33 weekstart = atoi(weekstart_buf);
36 * Now back up to the 1st of the month...
38 memset(&starting_tm, 0, sizeof(struct tm));
40 starting_tm.tm_year = year - 1900;
41 starting_tm.tm_mon = month - 1;
42 starting_tm.tm_mday = 1;
43 thetime = mktime(&starting_tm);
45 memcpy(&tm, &starting_tm, sizeof(struct tm));
46 while (tm.tm_mday != 1) {
47 thetime = thetime - (time_t)86400; /* go back 24 hours */
48 localtime_r(&thetime, &tm);
51 /** Determine previous and next months ... for links */
52 previous_month = thetime - (time_t)864000L; /* back 10 days */
53 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
55 /** Now back up until we're on the user's preferred start day */
56 localtime_r(&thetime, &tm);
57 while (tm.tm_wday != weekstart) {
58 thetime = thetime - (time_t)86400; /* go back 24 hours */
59 localtime_r(&thetime, &tm);
62 wprintf("<div class=\"mini_calendar\" id=\"%s\">\n", div_id);
64 /* Previous month link */
65 localtime_r(&previous_month, &tm);
66 wprintf("<a href=\"javascript:minical_change_month(%d,%d);\">«</a>",
67 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
69 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
70 wprintf(" "
71 "<span class=\"mini_calendar_month_label\">"
74 " ", colheader_label, year);
77 localtime_r(&next_month, &tm);
78 wprintf("<a href=\"javascript:minical_change_month(%d,%d);\">»</a>",
79 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
81 wprintf("<table border=0 cellpadding=1 cellspacing=1 class=\"mini_calendar_days\">"
83 colheader_time = thetime;
85 colheader_time = thetime + (i * 86400) ;
86 localtime_r(&colheader_time, &colheader_tm);
87 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
88 wprintf("<th>%c</th>", colheader_label[0]);
94 /** Now do 35 or 42 days */
95 for (i = 0; i < 42; ++i) {
96 localtime_r(&thetime, &tm);
100 /** Before displaying Sunday, start a new row */
105 if (tm.tm_mon == month-1) {
106 snprintf(url, sizeof url, urlformat,
107 tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday);
108 wprintf("<td><a href=\"%s\">%d</a></td>", url, tm.tm_mday);
111 wprintf("<td> </td>");
114 /** After displaying one week, end the row */
121 thetime += (time_t)86400; /** ahead 24 hours */
124 wprintf("</table>" /** end of inner table */
127 /* javascript for previous and next month */
128 len = strlen(urlformat);
129 for (i=0; i<len; ++i) {
130 sprintf(&escaped_urlformat[i*2], "%02X", urlformat[i]);
133 wprintf("<script type=\"text/javascript\"> "
134 " function minical_change_month(year, month) { "
135 " p = 'year=' + year + '&month=' + month "
136 " + '&urlformat=%s&r=' + CtdlRandomString(); "
137 " new Ajax.Updater('%s', 'mini_calendar', "
138 " { method: 'get', parameters: p, evalScripts: true } ); "
142 escaped_urlformat, div_id
148 * \brief ajax embedder for the above mini calendar
150 void ajax_mini_calendar(void) {
153 char *escaped_urlformat;
155 escaped_urlformat = bstr("urlformat");
156 len = strlen(escaped_urlformat) * 2 ;
157 for (i=0; i<len; ++i) {
158 urlformat[i] = xtoi(&escaped_urlformat[i*2], 2);
162 embeddable_mini_calendar( ibstr("year"), ibstr("month"), urlformat );
167 * \brief Display one day of a whole month view of a calendar
168 * \param thetime the month we want to see
170 void calendar_month_view_display_events(int year, int month, int day)
177 icalproperty *p = NULL;
178 icalproperty *q = NULL;
179 struct icaltimetype t;
180 struct icaltimetype end_t;
181 struct icaltimetype today_start_t;
182 struct icaltimetype today_end_t;
183 struct tm starting_tm;
185 int all_day_event = 0;
188 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
191 if (GetCount(WCC->disp_cal_items) == 0) {
192 wprintf("<br /><br /><br />\n");
197 * Create an imaginary event which spans the 24 hours of today. Any events which
198 * overlap with this one take place at least partially in this day. We have to
199 * convert it from a struct tm in order to make it UTC.
201 memset(&starting_tm, 0, sizeof(struct tm));
202 starting_tm.tm_year = year - 1900;
203 starting_tm.tm_mon = month - 1;
204 starting_tm.tm_mday = day;
205 starting_tm.tm_hour = 0;
206 starting_tm.tm_min = 0;
207 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
208 today_start_t.is_utc = 1;
210 memset(&ending_tm, 0, sizeof(struct tm));
211 ending_tm.tm_year = year - 1900;
212 ending_tm.tm_mon = month - 1;
213 ending_tm.tm_mday = day;
214 ending_tm.tm_hour = 23;
215 ending_tm.tm_min = 59;
216 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
217 today_end_t.is_utc = 1;
220 * Now loop through our list of events to see which ones occur today.
222 Pos = GetNewHashPos();
223 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
224 Cal = (disp_cal*)vCal;
226 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
228 t = icalproperty_get_dtstart(q);
231 memset(&t, 0, sizeof t);
233 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
235 end_t = icalproperty_get_dtend(q);
238 memset(&end_t, 0, sizeof end_t);
240 if (t.is_date) all_day_event = 1;
244 show_event = ((t.year == year) && (t.month == month) && (t.day == day));
248 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
252 * If we determined that this event occurs today, then display it.
255 p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
259 wprintf("<table border=0 cellpadding=2><TR>"
260 "<td bgcolor=\"#CCCCDD\">"
264 wprintf("<font size=-1>"
265 "<a class=\"event%s\" href=\"display_edit_event?"
266 "msgnum=%ld&calview=month&year=%d&month=%d&day=%d\""
268 (Cal->unread)?"_unread":"_read",
273 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
274 wprintf("<i>%s</i> ", _("Summary:"));
275 escputs((char *)icalproperty_get_comment(p));
278 q = icalcomponent_get_first_property(
280 ICAL_LOCATION_PROPERTY);
282 wprintf("<i>%s</i> ", _("Location:"));
283 escputs((char *)icalproperty_get_comment(q));
288 * Only show start/end times if we're actually looking at the VEVENT
289 * component. Otherwise it shows bogus dates for e.g. timezones
291 if (icalcomponent_isa(Cal->cal) == ICAL_VEVENT_COMPONENT) {
293 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
295 t = icalproperty_get_dtstart(q);
300 memset(&d_tm, 0, sizeof d_tm);
301 d_tm.tm_year = t.year - 1900;
302 d_tm.tm_mon = t.month - 1;
303 d_tm.tm_mday = t.day;
304 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
305 wprintf("<i>%s</i> %s<br>",
309 tt = icaltime_as_timet(t);
310 webcit_fmt_date(buf, tt, 1);
311 wprintf("<i>%s</i> %s<br>",
312 _("Starting date/time:"), buf);
315 * Embed the 'show end date/time' loop inside here so it
316 * only executes if this is NOT an all day event.
318 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
320 t = icalproperty_get_dtend(q);
321 tt = icaltime_as_timet(t);
322 webcit_fmt_date(buf, tt, 1);
323 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
331 q = icalcomponent_get_first_property(Cal->cal, ICAL_DESCRIPTION_PROPERTY);
333 wprintf("<i>%s</i> ", _("Notes:"));
334 escputs((char *)icalproperty_get_comment(q));
340 icalproperty_get_comment(p));
341 wprintf("</a></font><br />\n");
344 wprintf("</td></tr></table>");
358 * \brief Display one day of a whole month view of a calendar
359 * \param thetime the month we want to see
361 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
369 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
375 struct icaltimetype t;
377 int month, day, year;
378 int all_day_event = 0;
382 time_format = get_time_format_cached ();
384 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
385 else timeformat="%I:%M %p";
387 localtime_r(&thetime, &today_tm);
388 month = today_tm.tm_mon + 1;
389 day = today_tm.tm_mday;
390 year = today_tm.tm_year + 1900;
392 Pos = GetNewHashPos();
393 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
394 Cal = (disp_cal*)vCal;
395 p = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
397 t = icalproperty_get_dtstart(p);
398 event_tt = icaltime_as_timet(t);
400 if (t.is_date) all_day_event = 1;
401 else all_day_event = 0;
404 gmtime_r(&event_tts, &event_tms);
407 localtime_r(&event_tts, &event_tms);
409 /* \todo epoch &! daymask */
410 if ((event_tms.tm_year == today_tm.tm_year)
411 && (event_tms.tm_mon == today_tm.tm_mon)
412 && (event_tms.tm_mday == today_tm.tm_mday)) {
418 p = icalcomponent_get_first_property(
420 ICAL_SUMMARY_PROPERTY);
421 e = icalcomponent_get_first_property(
423 ICAL_DTEND_PROPERTY);
424 if ((p != NULL) && (e != NULL)) {
427 t = icalproperty_get_dtend(e);
428 event_tte = icaltime_as_timet(t);
429 localtime_r(&event_tte, &event_tme);
430 difftime=(event_tte-event_tts)/60;
431 hours=(int)(difftime / 60);
432 minutes=difftime % 60;
433 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
435 "<a class=\"event%s\" href=\"display_edit_event?msgnum=%ld&calview=calbrief&year=%s&month=%s&day=%s\">",
438 (Cal->unread)?"_unread":"_read",
447 icalproperty_get_comment(p));
448 /* \todo: allso ammitime format */
449 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
450 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
452 wprintf("</a></font></td>"
453 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
470 * view one month. pretty view
472 void calendar_month_view(int year, int month, int day) {
473 struct tm starting_tm;
477 time_t previous_month;
479 time_t colheader_time;
480 struct tm colheader_tm;
481 char colheader_label[32];
484 char weekstart_buf[16];
487 * Determine what day to start
489 get_preference("weekstart", weekstart_buf, sizeof weekstart_buf);
490 weekstart = atoi(weekstart_buf);
493 * Now back up to the 1st of the month...
495 memset(&starting_tm, 0, sizeof(struct tm));
497 starting_tm.tm_year = year - 1900;
498 starting_tm.tm_mon = month - 1;
499 starting_tm.tm_mday = day;
500 thetime = mktime(&starting_tm);
502 memcpy(&tm, &starting_tm, sizeof(struct tm));
503 while (tm.tm_mday != 1) {
504 thetime = thetime - (time_t)86400; /* go back 24 hours */
505 localtime_r(&thetime, &tm);
508 /* Determine previous and next months ... for links */
509 previous_month = thetime - (time_t)864000L; /* back 10 days */
510 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
512 /* Now back up until we're on the user's preferred start day */
513 localtime_r(&thetime, &tm);
514 while (tm.tm_wday != weekstart) {
515 thetime = thetime - (time_t)86400; /* go back 24 hours */
516 localtime_r(&thetime, &tm);
519 /* Outer table (to get the background color) */
520 wprintf("<div class=\"fix_scrollbar_bug\">"
521 "<table class=\"calendar\"> \n <tr><td>");
523 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
525 wprintf("<td align=center>");
527 localtime_r(&previous_month, &tm);
528 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
529 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
530 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
532 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
533 wprintf(" "
534 "<font size=+1 color=\"#FFFFFF\">"
537 " ", colheader_label, year);
539 localtime_r(&next_month, &tm);
540 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
541 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
542 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
544 wprintf("</td></tr></table>\n");
546 /* Inner table (the real one) */
547 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
548 "bgcolor=#204B78 id=\"inner_month\"><tr>");
549 colheader_time = thetime;
550 for (i=0; i<7; ++i) {
551 colheader_time = thetime + (i * 86400) ;
552 localtime_r(&colheader_time, &colheader_tm);
553 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
554 wprintf("<th align=center width=14%%>"
555 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
561 /* Now do 35 or 42 days */
562 for (i = 0; i < 42; ++i) {
563 localtime_r(&thetime, &tm);
565 if ((i < 35) || (chg_month == 0)) {
567 if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) {
574 /* Before displaying the first day of the week, start a new row */
579 wprintf("<td class=\"cal%s\"><div class=\"day\">",
580 ((tm.tm_mon != month-1) ? "out" :
581 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
584 if ((i==0) || (tm.tm_mday == 1)) {
585 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
586 wprintf("%s ", colheader_label);
588 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
595 /** put the data here, stupid */
596 calendar_month_view_display_events(
604 /* After displaying the last day of the week, end the row */
611 thetime += (time_t)86400; /* ahead 24 hours */
614 wprintf("</table>" /* end of inner table */
615 "</td></tr></table>" /* end of outer table */
619 * Initialize the bubble tooltips.
621 * Yes, this is as stupid as it looks. Instead of just making the call
622 * to btt_enableTooltips() straight away, we have to create a timer event
623 * and let it initialize as an event after 1 millisecond. This is to
624 * work around a bug in Internet Explorer that causes it to crash if we
625 * manipulate the innerHTML of various DOM nodes while the page is still
626 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
627 * for more information.
629 wprintf("<script type=\"text/javascript\">"
630 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
636 * view one month. brief view
638 void calendar_brief_month_view(int year, int month, int day) {
639 struct tm starting_tm;
643 time_t previous_month;
645 char month_label[32];
647 /* Determine what day to start.
648 * First, back up to the 1st of the month...
650 memset(&starting_tm, 0, sizeof(struct tm));
651 starting_tm.tm_year = year - 1900;
652 starting_tm.tm_mon = month - 1;
653 starting_tm.tm_mday = day;
654 thetime = mktime(&starting_tm);
656 memcpy(&tm, &starting_tm, sizeof(struct tm));
657 while (tm.tm_mday != 1) {
658 thetime = thetime - (time_t)86400; /* go back 24 hours */
659 localtime_r(&thetime, &tm);
662 /* Determine previous and next months ... for links */
663 previous_month = thetime - (time_t)864000L; /* back 10 days */
664 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
666 /* Now back up until we're on a Sunday */
667 localtime_r(&thetime, &tm);
668 while (tm.tm_wday != 0) {
669 thetime = thetime - (time_t)86400; /* go back 24 hours */
670 localtime_r(&thetime, &tm);
673 /* Outer table (to get the background color) */
674 wprintf("<div class=\"fix_scrollbar_bug\">"
675 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
676 "bgcolor=#204B78><TR><TD>\n");
678 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
680 wprintf("<td align=center>");
682 localtime_r(&previous_month, &tm);
683 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
684 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
685 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
687 wc_strftime(month_label, sizeof month_label, "%B", &tm);
688 wprintf(" "
689 "<font size=+1 color=\"#FFFFFF\">"
692 " ", month_label, year);
694 localtime_r(&next_month, &tm);
695 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
696 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
697 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
699 wprintf("</td></tr></table>\n");
701 /* Inner table (the real one) */
702 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
703 "bgcolor=#EEEECC><TR>");
705 wprintf("<tr><td colspan=\"100%\">\n");
708 for (i = 0; i < 35; ++i) {
709 char weeknumber[255];
710 char weekday_name[32];
712 localtime_r(&thetime, &tm);
715 /* Before displaying Sunday, start a new CELL */
717 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
718 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
719 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
729 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
730 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
734 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
735 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
736 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
738 weekday_name,tm.tm_mday,
741 /* put the data of one day here, stupid */
742 calendar_month_view_brief_events(thetime, daycolor);
745 /* After displaying Saturday, end the row */
747 wprintf("</td></tr></table>\n");
750 thetime += (time_t)86400; /** ahead 24 hours */
753 wprintf("</table>" /** end of inner table */
754 "</td></tr></table>" /** end of outer table */
759 * Calendar week view -- not implemented yet, this is a stub function
761 void calendar_week_view(int year, int month, int day) {
762 wprintf("<center><i>week view FIXME</i></center><br />\n");
768 * Display events for a particular hour of a particular day.
769 * (Specify hour < 0 to show "all day" events)
771 * dstart and dend indicate which hours our "daytime" begins and end
773 void calendar_day_view_display_events(time_t thetime,
785 icalproperty *p = NULL;
786 icalproperty *q = NULL;
792 int all_day_event = 0;
793 int ongoing_event = 0;
794 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
796 struct icaltimetype t;
797 struct icaltimetype end_t;
798 struct icaltimetype today_start_t;
799 struct icaltimetype today_end_t;
800 struct tm starting_tm;
813 if (GetCount(WCC->disp_cal_items) == 0) {
814 /* nothing to display */
818 /* Create an imaginary event which spans the current day. Any events which
819 * overlap with this one take place at least partially in this day.
821 memset(&starting_tm, 0, sizeof(struct tm));
822 starting_tm.tm_year = year - 1900;
823 starting_tm.tm_mon = month - 1;
824 starting_tm.tm_mday = day;
825 starting_tm.tm_hour = 0;
826 starting_tm.tm_min = 0;
827 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
828 today_start_t.is_utc = 1;
830 memset(&ending_tm, 0, sizeof(struct tm));
831 ending_tm.tm_year = year - 1900;
832 ending_tm.tm_mon = month - 1;
833 ending_tm.tm_mday = day;
834 ending_tm.tm_hour = 23;
835 ending_tm.tm_min = 59;
836 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
837 today_end_t.is_utc = 1;
839 /* Now loop through our list of events to see which ones occur today.
841 Pos = GetNewHashPos();
842 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
843 Cal = (disp_cal*)vCal;
848 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
850 t = icalproperty_get_dtstart(q);
851 event_tt = icaltime_as_timet(t);
852 localtime_r(&event_tt, &event_te);
855 memset(&t, 0, sizeof t);
857 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
859 end_t = icalproperty_get_dtend(q);
860 event_tte = icaltime_as_timet(end_t);
861 localtime_r(&event_tte, &event_tm);
864 memset(&end_t, 0, sizeof end_t);
866 if (t.is_date) all_day_event = 1;
870 show_event = ((t.year == year) && (t.month == month) && (t.day == day) && (notime_events));
874 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
877 /* If we determined that this event occurs today, then display it.
879 p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
881 if ((show_event) && (p != NULL)) {
883 if ((event_te.tm_mday != day) || (event_tm.tm_mday != day)) ongoing_event = 1;
885 if (all_day_event && notime_events)
887 wprintf("<li class=\"event_framed%s\"> "
888 "<a href=\"display_edit_event?"
889 "msgnum=%ld&calview=day&year=%d&month=%d&day=%d\" "
890 " class=\"event_title\" "
892 (Cal->unread)?"_unread":"_read",
893 Cal->cal_msgnum, year, month, day);
894 wprintf("<i>%s</i><br />", _("All day event"));
895 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
896 wprintf("<i>%s</i> ", _("Summary:"));
897 escputs((char *) icalproperty_get_comment(p));
899 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
901 wprintf("<i>%s</i> ", _("Location:"));
902 escputs((char *)icalproperty_get_comment(q));
905 memset(&d_tm, 0, sizeof d_tm);
906 d_tm.tm_year = t.year - 1900;
907 d_tm.tm_mon = t.month - 1;
908 d_tm.tm_mday = t.day;
909 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
910 wprintf("<i>%s</i> %s<br>",_("Date:"), d_str);
911 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
913 wprintf("<i>%s</i> ", _("Notes:"));
914 escputs((char *)icalproperty_get_comment(q));
918 escputs((char *) icalproperty_get_comment(p));
919 wprintf("</a> <span>(");
920 wprintf(_("All day event"));
921 wprintf(")</span></li>\n");
923 else if (ongoing_event && notime_events)
925 wprintf("<li class=\"event_framed%s\"> "
926 "<a href=\"display_edit_event?"
927 "msgnum=%ld&calview=day&year=%d&month=%d&day=%d\" "
928 " class=\"event_title\" "
930 (Cal->unread)?"_unread":"_read",
931 Cal->cal_msgnum, year, month, day);
932 wprintf("<i>%s</i><br />", _("Ongoing event"));
933 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
934 wprintf("<i>%s</i> ", _("Summary:"));
935 escputs((char *) icalproperty_get_comment(p));
937 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
939 wprintf("<i>%s</i> ", _("Location:"));
940 escputs((char *)icalproperty_get_comment(q));
943 webcit_fmt_date(buf, event_tt, 1);
944 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
945 webcit_fmt_date(buf, event_tte, 1);
946 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
947 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
949 wprintf("<i>%s</i> ", _("Notes:"));
950 escputs((char *)icalproperty_get_comment(q));
954 escputs((char *) icalproperty_get_comment(p));
955 wprintf("</a> <span>(");
956 wprintf(_("Ongoing event"));
957 wprintf(")</span></li>\n");
959 else if (!all_day_event && !notime_events)
963 if (event_te.tm_mday != day) event_te.tm_hour = 0;
964 if (event_tm.tm_mday != day) event_tm.tm_hour = 24;
966 /* Calculate the location of the top of the box */
967 if (event_te.tm_hour < dstart) {
968 startmin = diffmin = event_te.tm_min / 6;
969 top = (event_te.tm_hour * 10) + startmin;
971 else if ((event_te.tm_hour >= dstart) && (event_te.tm_hour <= dend)) {
972 startmin = diffmin = (event_te.tm_min / 2);
973 top = (dstart * 10) + ((event_te.tm_hour - dstart) * 30) + startmin;
975 else if (event_te.tm_hour >dend) {
976 startmin = diffmin = event_te.tm_min / 6;
977 top = (dstart * 10) + ((dend - dstart - 1) * 30) + ((event_tm.tm_hour - dend + 1) * 10) + startmin ;
980 /* should never get here */
983 /* Calculate the location of the bottom of the box */
984 if (event_tm.tm_hour < dstart) {
985 endmin = diffmin = event_tm.tm_min / 6;
986 bottom = (event_tm.tm_hour * 10) + endmin;
988 else if ((event_tm.tm_hour >= dstart) && (event_tm.tm_hour <= dend)) {
989 endmin = diffmin = (event_tm.tm_min / 2);
990 bottom = (dstart * 10) + ((event_tm.tm_hour - dstart) * 30) + endmin ;
992 else if (event_tm.tm_hour >dend) {
993 endmin = diffmin = event_tm.tm_min / 6;
994 bottom = (dstart * 10) + ((dend - dstart + 1) * 30) + ((event_tm.tm_hour - dend - 1) * 10) + endmin;
997 /* should never get here */
1000 wprintf("<dd class=\"event_framed%s\" "
1001 "style=\"position: absolute; "
1002 "top:%dpx; left:%dpx; "
1003 "height:%dpx; \" >",
1004 (Cal->unread)?"_unread":"_read",
1005 top, (gap * 40), (bottom-top)
1007 wprintf("<a href=\"display_edit_event?"
1008 "msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\" "
1009 "class=\"event_title\" "
1011 Cal->cal_msgnum, year, month, day, t.hour);
1012 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
1013 wprintf("<i>%s</i> ", _("Summary:"));
1014 escputs((char *) icalproperty_get_comment(p));
1016 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
1018 wprintf("<i>%s</i> ", _("Location:"));
1019 escputs((char *)icalproperty_get_comment(q));
1022 webcit_fmt_date(buf, event_tt, 1);
1023 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
1024 webcit_fmt_date(buf, event_tte, 1);
1025 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
1026 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
1028 wprintf("<i>%s</i> ", _("Notes:"));
1029 escputs((char *)icalproperty_get_comment(q));
1034 escputs((char *) icalproperty_get_comment(p));
1035 wprintf("</a></dd>\n");
1039 DeleteHashPos(&Pos);
1045 void calendar_day_view(int year, int month, int day) {
1047 struct icaltimetype today, yesterday, tomorrow;
1050 char daystart_str[16], dayend_str[16];
1056 int extratimeline = 0;
1059 time_format = get_time_format_cached ();
1060 get_preference("daystart", daystart_str, sizeof daystart_str);
1061 if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
1062 get_preference("dayend", dayend_str, sizeof dayend_str);
1063 if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str);
1066 memset(&d_tm, 0, sizeof d_tm);
1067 d_tm.tm_year = year - 1900;
1068 d_tm.tm_mon = month - 1;
1070 today_t = mktime(&d_tm);
1072 /* Figure out the dates for "yesterday" and "tomorrow" links */
1074 memset(&today, 0, sizeof(struct icaltimetype));
1076 today.month = month;
1080 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
1082 yesterday = icaltime_normalize(yesterday);
1084 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
1086 tomorrow = icaltime_normalize(tomorrow);
1088 wprintf("<div class=\"fix_scrollbar_bug\">");
1090 /* Inner table (the real one) */
1091 wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
1093 /* Innermost cell (contains hours etc.) */
1094 wprintf("<td class=\"events_of_the_day\" >");
1095 wprintf("<dl class=\"events\" >");
1097 /* Now the middle of the day... */
1099 extratimeline = timeline / 3;
1101 for (hour = 0; hour < daystart; ++hour) { /* could do HEIGHT=xx */
1102 wprintf("<dt class=\"extrahour\" "
1104 "position: absolute; "
1105 "top: %dpx; left: 0px; "
1108 "<a href=\"display_edit_event?msgnum=0"
1109 "&calview=day&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
1110 (hour * extratimeline ), extratimeline,
1111 year, month, day, hour
1114 if (time_format == WC_TIMEFORMAT_24) {
1115 wprintf("%2d:00</a> ", hour);
1118 wprintf("%d:00%s</a> ",
1119 (hour <= 12 ? hour : hour-12),
1120 (hour < 12 ? "am" : "pm")
1127 gap = daystart * extratimeline;
1129 for (hour = daystart; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
1130 wprintf("<dt class=\"hour\" "
1132 "position: absolute; "
1133 "top: %dpx; left: 0px; "
1136 "<a href=\"display_edit_event?msgnum=0&calview=day"
1137 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
1138 gap + ((hour - daystart) * timeline ), timeline,
1139 year, month, day, hour
1142 if (time_format == WC_TIMEFORMAT_24) {
1143 wprintf("%2d:00</a> ", hour);
1146 wprintf("%d:00%s</a> ",
1147 (hour <= 12 ? hour : hour-12),
1148 (hour < 12 ? "am" : "pm")
1155 gap = gap + ((dayend - daystart + 1) * timeline);
1157 for (hour = (dayend + 1); hour < 24; ++hour) { /* could do HEIGHT=xx */
1158 wprintf("<dt class=\"extrahour\" "
1160 "position: absolute; "
1161 "top: %dpx; left: 0px; "
1164 "<a href=\"display_edit_event?msgnum=0&calview=day"
1165 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
1166 gap + ((hour - dayend - 1) * extratimeline ), extratimeline,
1167 year, month, day, hour
1170 if (time_format == WC_TIMEFORMAT_24) {
1171 wprintf("%2d:00</a> ", hour);
1174 wprintf("%d:00%s</a> ",
1175 (hour <= 12 ? hour : hour-12),
1176 (hour < 12 ? "am" : "pm")
1183 /* Display events with start and end times on this day */
1184 calendar_day_view_display_events(today_t, year, month, day, 0, daystart, dayend);
1187 wprintf("</td>"); /* end of innermost table */
1189 /* Display extra events (start/end times not present or not today) in the middle column */
1190 wprintf("<td class=\"extra_events\">");
1194 /* Display all-day events */
1195 calendar_day_view_display_events(today_t, year, month, day, 1, daystart, dayend);
1199 wprintf("</td>"); /** end extra on the middle */
1201 wprintf("<td width=20%% align=center valign=top>"); /** begin stuff-on-the-right */
1203 /* Begin todays-date-with-left-and-right-arrows */
1204 wprintf("<table border=0 width=100%% "
1205 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
1209 wprintf("<td align=center>");
1210 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
1211 yesterday.year, yesterday.month, yesterday.day);
1212 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
1215 wc_strftime(d_str, sizeof d_str,
1217 "<font size=+2>%B</font><br />"
1218 "<font size=+3>%d</font><br />"
1219 "<font size=+2>%Y</font><br />"
1223 wprintf("%s", d_str);
1226 wprintf("<td align=center>");
1227 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
1228 tomorrow.year, tomorrow.month, tomorrow.day);
1229 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
1230 " border=0></a>\n");
1233 wprintf("</tr></table>\n");
1234 /* End todays-date-with-left-and-right-arrows */
1236 /* Embed a mini month calendar in this space */
1237 wprintf("<br />\n");
1238 embeddable_mini_calendar(year, month, "readfwd?calview=day&year=%d&month=%d&day=%d");
1240 wprintf("</font></center>\n");
1242 wprintf("</td></tr>"); /** end stuff-on-the-right */
1244 wprintf("</table>" /** end of inner table */
1247 wprintf("<script type=\"text/javascript\">"
1248 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); "
1255 * Display today's events.
1257 void calendar_summary_view(void) {
1264 struct icaltimetype t;
1269 int all_day_event = 0;
1270 char timestring[SIZ];
1271 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
1273 if (GetCount(WC->disp_cal_items) == 0) {
1278 localtime_r(&now, &today_tm);
1280 Pos = GetNewHashPos();
1281 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
1282 Cal = (disp_cal*)vCal;
1283 p = icalcomponent_get_first_property(Cal->cal,
1284 ICAL_DTSTART_PROPERTY);
1286 t = icalproperty_get_dtstart(p);
1287 event_tt = icaltime_as_timet(t);
1294 fmt_time(timestring, event_tt);
1296 if (all_day_event) {
1297 gmtime_r(&event_tt, &event_tm);
1300 localtime_r(&event_tt, &event_tm);
1303 if ( (event_tm.tm_year == today_tm.tm_year)
1304 && (event_tm.tm_mon == today_tm.tm_mon)
1305 && (event_tm.tm_mday == today_tm.tm_mday)
1309 p = icalcomponent_get_first_property(
1311 ICAL_SUMMARY_PROPERTY);
1314 icalproperty_get_comment(p));
1315 wprintf(" (%s)<br />\n", timestring);
1320 DeleteHashPos(&Pos);
1321 DeleteHash(&WC->disp_cal_items);
1326 * do the whole calendar page
1327 * view any part of the calender. decide which way, etc.
1329 void do_calendar_view(void) {
1332 int year, month, day;
1335 /* In case no date was specified, go with today */
1337 localtime_r(&now, &tm);
1338 year = tm.tm_year + 1900;
1339 month = tm.tm_mon + 1;
1342 /* Now see if a date was specified */
1343 if (havebstr("year")) year = ibstr("year");
1344 if (havebstr("month")) month = ibstr("month");
1345 if (havebstr("day")) day = ibstr("day");
1347 /* How would you like that cooked? */
1348 if (havebstr("calview")) {
1349 strcpy(calview, bstr("calview"));
1352 strcpy(calview, "month");
1355 /* Display the selected view */
1356 if (!strcasecmp(calview, "day")) {
1357 calendar_day_view(year, month, day);
1359 else if (!strcasecmp(calview, "week")) {
1360 calendar_week_view(year, month, day);
1363 if (WC->wc_view == VIEW_CALBRIEF) {
1364 calendar_brief_month_view(year, month, day);
1367 calendar_month_view(year, month, day);
1371 /* Free the in-memory list of calendar items */
1372 DeleteHash(&WC->disp_cal_items);
1377 * Helper function for do_tasks_view(). Returns the due date/time of a vtodo.
1379 time_t get_task_due_date(icalcomponent *vtodo) {
1382 if (vtodo == NULL) {
1387 * If we're looking at a fully encapsulated VCALENDAR
1388 * rather than a VTODO component, recurse into the data
1389 * structure until we get a VTODO.
1391 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1392 return get_task_due_date(
1393 icalcomponent_get_first_component(
1394 vtodo, ICAL_VTODO_COMPONENT
1399 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1401 return(icaltime_as_timet(icalproperty_get_due(p)));
1410 * Compare the due dates of two tasks (this is for sorting)
1412 int task_due_cmp(const void *vtask1, const void *vtask2) {
1413 disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
1414 disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2);
1419 t1 = get_task_due_date(Task1->cal);
1420 t2 = get_task_due_date(Task2->cal);
1421 if (t1 < t2) return(-1);
1422 if (t1 > t2) return(1);
1427 * qsort filter to move completed tasks to bottom of task list
1429 int task_completed_cmp(const void *vtask1, const void *vtask2) {
1430 disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
1431 // disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2);
1433 icalproperty_status t1 = icalcomponent_get_status((Task1)->cal);
1434 // icalproperty_status t2 = icalcomponent_get_status(((struct disp_cal *)task2)->cal);
1436 if (t1 == ICAL_STATUS_COMPLETED)
1444 * do the whole task view stuff
1446 void do_tasks_view(void) {
1456 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
1458 wprintf("<div class=\"fix_scrollbar_bug\">"
1459 "<table class=\"calendar_view_background\"><tbody id=\"taskview\">\n<tr>\n"
1461 wprintf(_("Completed?"));
1462 wprintf("</th><th>");
1463 wprintf(_("Name of task"));
1464 wprintf("</th><th>");
1465 wprintf(_("Date due"));
1466 wprintf("</th><th>");
1467 wprintf(_("Category"));
1468 wprintf(" (<select id=\"selectcategory\"><option value=\"showall\">%s</option></select>)</th></tr>\n",
1471 nItems = GetCount(WC->disp_cal_items);
1473 /* Sort them if necessary
1475 SortByPayload(WC->disp_cal_items, task_due_cmp);
1477 * this shouldn't be neccessary, since we sort by the start time.
1480 /* And then again, by completed */
1482 SortByPayload(WC->disp_cal_items,
1483 task_completed_cmp);
1486 Pos = GetNewHashPos();
1487 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
1488 Cal = (disp_cal*)vCal;
1489 wprintf("<tr><td>");
1490 icalproperty_status todoStatus = icalcomponent_get_status(Cal->cal);
1491 wprintf("<input type=\"checkbox\" name=\"completed\" value=\"completed\" ");
1492 if (todoStatus == ICAL_STATUS_COMPLETED) {
1493 wprintf("checked=\"checked\" ");
1495 wprintf("disabled=\"disabled\">\n</td><td>");
1496 p = icalcomponent_get_first_property(Cal->cal,
1497 ICAL_SUMMARY_PROPERTY);
1498 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1500 urlescputs(WC->wc_roomname);
1502 /* wprintf("<img align=middle "
1503 "src=\"static/taskmanag_16x.gif\" border=0> "); */
1505 escputs((char *)icalproperty_get_comment(p));
1510 due = get_task_due_date(Cal->cal);
1511 wprintf("<td><span");
1513 webcit_fmt_date(buf, due, 0);
1519 wprintf("</span></td>");
1521 p = icalcomponent_get_first_property(Cal->cal,
1522 ICAL_CATEGORIES_PROPERTY);
1524 escputs((char *)icalproperty_get_categories(p));
1530 wprintf("</tbody></table></div>\n");
1533 DeleteHash(&WC->disp_cal_items);
1534 DeleteHashPos(&Pos);