4 * Handles the HTML display of calendar items.
11 void embeddable_mini_calendar(int year, int month, char *urlformat)
13 struct tm starting_tm;
17 time_t previous_month;
19 time_t colheader_time;
20 struct tm colheader_tm;
21 char colheader_label[32];
25 char escaped_urlformat[256];
27 snprintf(div_id, sizeof div_id, "mini_calendar_%d", rand() );
29 /* Determine what day to start.
31 get_pref_long("weekstart", &weekstart, 17);
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, urlformat,
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 /* javascript for previous and next month */
126 len = strlen(urlformat);
127 for (i=0; i<len; ++i) {
128 sprintf(&escaped_urlformat[i*2], "%02X", urlformat[i]);
131 wprintf("<script type=\"text/javascript\"> "
132 " function minical_change_month(year, month) { "
133 " p = 'year=' + year + '&month=' + month "
134 " + '&urlformat=%s&r=' + CtdlRandomString(); "
135 " new Ajax.Updater('%s', 'mini_calendar', "
136 " { method: 'get', parameters: p, evalScripts: true } ); "
140 escaped_urlformat, div_id
146 * \brief ajax embedder for the above mini calendar
148 void ajax_mini_calendar(void) {
151 char *escaped_urlformat;
153 escaped_urlformat = bstr("urlformat");
154 len = strlen(escaped_urlformat) * 2 ;
155 for (i=0; i<len; ++i) {
156 urlformat[i] = xtoi(&escaped_urlformat[i*2], 2);
160 embeddable_mini_calendar( ibstr("year"), ibstr("month"), urlformat );
165 * \brief Display one day of a whole month view of a calendar
166 * \param thetime the month we want to see
168 void calendar_month_view_display_events(int year, int month, int day)
175 icalproperty *p = NULL;
176 icalproperty *q = NULL;
177 struct icaltimetype t;
178 struct icaltimetype end_t;
179 struct icaltimetype today_start_t;
180 struct icaltimetype today_end_t;
181 struct tm starting_tm;
183 int all_day_event = 0;
186 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
189 if (GetCount(WCC->disp_cal_items) == 0) {
190 wprintf("<br /><br /><br />\n");
195 * Create an imaginary event which spans the 24 hours of today. Any events which
196 * overlap with this one take place at least partially in this day. We have to
197 * convert it from a struct tm in order to make it UTC.
199 memset(&starting_tm, 0, sizeof(struct tm));
200 starting_tm.tm_year = year - 1900;
201 starting_tm.tm_mon = month - 1;
202 starting_tm.tm_mday = day;
203 starting_tm.tm_hour = 0;
204 starting_tm.tm_min = 0;
205 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
206 today_start_t.is_utc = 1;
208 memset(&ending_tm, 0, sizeof(struct tm));
209 ending_tm.tm_year = year - 1900;
210 ending_tm.tm_mon = month - 1;
211 ending_tm.tm_mday = day;
212 ending_tm.tm_hour = 23;
213 ending_tm.tm_min = 59;
214 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
215 today_end_t.is_utc = 1;
218 * Now loop through our list of events to see which ones occur today.
220 Pos = GetNewHashPos();
221 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
222 Cal = (disp_cal*)vCal;
224 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
226 t = icalproperty_get_dtstart(q);
229 memset(&t, 0, sizeof t);
231 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
233 end_t = icalproperty_get_dtend(q);
236 memset(&end_t, 0, sizeof end_t);
238 if (t.is_date) all_day_event = 1;
242 show_event = ((t.year == year) && (t.month == month) && (t.day == day));
246 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
250 * If we determined that this event occurs today, then display it.
253 p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
257 wprintf("<table border=0 cellpadding=2><TR>"
258 "<td bgcolor=\"#CCCCDD\">"
262 wprintf("<font size=-1>"
263 "<a class=\"event%s\" href=\"display_edit_event?"
264 "msgnum=%ld&calview=month&year=%d&month=%d&day=%d\""
266 (Cal->unread)?"_unread":"_read",
271 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
272 wprintf("<i>%s</i> ", _("Summary:"));
273 escputs((char *)icalproperty_get_comment(p));
276 q = icalcomponent_get_first_property(
278 ICAL_LOCATION_PROPERTY);
280 wprintf("<i>%s</i> ", _("Location:"));
281 escputs((char *)icalproperty_get_comment(q));
286 * Only show start/end times if we're actually looking at the VEVENT
287 * component. Otherwise it shows bogus dates for e.g. timezones
289 if (icalcomponent_isa(Cal->cal) == ICAL_VEVENT_COMPONENT) {
291 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
293 t = icalproperty_get_dtstart(q);
298 memset(&d_tm, 0, sizeof d_tm);
299 d_tm.tm_year = t.year - 1900;
300 d_tm.tm_mon = t.month - 1;
301 d_tm.tm_mday = t.day;
302 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
303 wprintf("<i>%s</i> %s<br>",
307 tt = icaltime_as_timet(t);
308 webcit_fmt_date(buf, tt, 1);
309 wprintf("<i>%s</i> %s<br>",
310 _("Starting date/time:"), buf);
313 * Embed the 'show end date/time' loop inside here so it
314 * only executes if this is NOT an all day event.
316 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
318 t = icalproperty_get_dtend(q);
319 tt = icaltime_as_timet(t);
320 webcit_fmt_date(buf, tt, 1);
321 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
329 q = icalcomponent_get_first_property(Cal->cal, ICAL_DESCRIPTION_PROPERTY);
331 wprintf("<i>%s</i> ", _("Notes:"));
332 escputs((char *)icalproperty_get_comment(q));
338 icalproperty_get_comment(p));
339 wprintf("</a></font><br />\n");
342 wprintf("</td></tr></table>");
356 * \brief Display one day of a whole month view of a calendar
357 * \param thetime the month we want to see
359 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
367 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
373 struct icaltimetype t;
375 int month, day, year;
376 int all_day_event = 0;
380 time_format = get_time_format_cached ();
382 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
383 else timeformat="%I:%M %p";
385 localtime_r(&thetime, &today_tm);
386 month = today_tm.tm_mon + 1;
387 day = today_tm.tm_mday;
388 year = today_tm.tm_year + 1900;
390 Pos = GetNewHashPos();
391 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
392 Cal = (disp_cal*)vCal;
393 p = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
395 t = icalproperty_get_dtstart(p);
396 event_tt = icaltime_as_timet(t);
398 if (t.is_date) all_day_event = 1;
399 else all_day_event = 0;
402 gmtime_r(&event_tts, &event_tms);
405 localtime_r(&event_tts, &event_tms);
407 /* \todo epoch &! daymask */
408 if ((event_tms.tm_year == today_tm.tm_year)
409 && (event_tms.tm_mon == today_tm.tm_mon)
410 && (event_tms.tm_mday == today_tm.tm_mday)) {
416 p = icalcomponent_get_first_property(
418 ICAL_SUMMARY_PROPERTY);
419 e = icalcomponent_get_first_property(
421 ICAL_DTEND_PROPERTY);
422 if ((p != NULL) && (e != NULL)) {
425 t = icalproperty_get_dtend(e);
426 event_tte = icaltime_as_timet(t);
427 localtime_r(&event_tte, &event_tme);
428 difftime=(event_tte-event_tts)/60;
429 hours=(int)(difftime / 60);
430 minutes=difftime % 60;
431 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
433 "<a class=\"event%s\" href=\"display_edit_event?msgnum=%ld&calview=calbrief&year=%s&month=%s&day=%s\">",
436 (Cal->unread)?"_unread":"_read",
445 icalproperty_get_comment(p));
446 /* \todo: allso ammitime format */
447 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
448 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
450 wprintf("</a></font></td>"
451 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
468 * view one month. pretty view
470 void calendar_month_view(int year, int month, int day) {
471 struct tm starting_tm;
475 time_t previous_month;
477 time_t colheader_time;
478 struct tm colheader_tm;
479 char colheader_label[32];
484 * Determine what day to start
486 get_pref_long("weekstart", &weekstart, 17);
489 * Now back up to the 1st of the month...
491 memset(&starting_tm, 0, sizeof(struct tm));
493 starting_tm.tm_year = year - 1900;
494 starting_tm.tm_mon = month - 1;
495 starting_tm.tm_mday = day;
496 thetime = mktime(&starting_tm);
498 memcpy(&tm, &starting_tm, sizeof(struct tm));
499 while (tm.tm_mday != 1) {
500 thetime = thetime - (time_t)86400; /* go back 24 hours */
501 localtime_r(&thetime, &tm);
504 /* Determine previous and next months ... for links */
505 previous_month = thetime - (time_t)864000L; /* back 10 days */
506 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
508 /* Now back up until we're on the user's preferred start day */
509 localtime_r(&thetime, &tm);
510 while (tm.tm_wday != weekstart) {
511 thetime = thetime - (time_t)86400; /* go back 24 hours */
512 localtime_r(&thetime, &tm);
515 /* Outer table (to get the background color) */
516 wprintf("<div class=\"fix_scrollbar_bug\">"
517 "<table class=\"calendar\"> \n <tr><td>");
519 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
521 wprintf("<td align=center>");
523 localtime_r(&previous_month, &tm);
524 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
525 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
526 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
528 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
529 wprintf(" "
530 "<font size=+1 color=\"#FFFFFF\">"
533 " ", colheader_label, year);
535 localtime_r(&next_month, &tm);
536 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
537 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
538 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
540 wprintf("</td></tr></table>\n");
542 /* Inner table (the real one) */
543 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
544 "bgcolor=#204B78 id=\"inner_month\"><tr>");
545 colheader_time = thetime;
546 for (i=0; i<7; ++i) {
547 colheader_time = thetime + (i * 86400) ;
548 localtime_r(&colheader_time, &colheader_tm);
549 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
550 wprintf("<th align=center width=14%%>"
551 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
557 /* Now do 35 or 42 days */
558 for (i = 0; i < 42; ++i) {
559 localtime_r(&thetime, &tm);
561 if ((i < 35) || (chg_month == 0)) {
563 if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) {
570 /* Before displaying the first day of the week, start a new row */
575 wprintf("<td class=\"cal%s\"><div class=\"day\">",
576 ((tm.tm_mon != month-1) ? "out" :
577 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
580 if ((i==0) || (tm.tm_mday == 1)) {
581 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
582 wprintf("%s ", colheader_label);
584 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
591 /** put the data here, stupid */
592 calendar_month_view_display_events(
600 /* After displaying the last day of the week, end the row */
607 thetime += (time_t)86400; /* ahead 24 hours */
610 wprintf("</table>" /* end of inner table */
611 "</td></tr></table>" /* end of outer table */
615 * Initialize the bubble tooltips.
617 * Yes, this is as stupid as it looks. Instead of just making the call
618 * to btt_enableTooltips() straight away, we have to create a timer event
619 * and let it initialize as an event after 1 millisecond. This is to
620 * work around a bug in Internet Explorer that causes it to crash if we
621 * manipulate the innerHTML of various DOM nodes while the page is still
622 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
623 * for more information.
625 wprintf("<script type=\"text/javascript\">"
626 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
632 * view one month. brief view
634 void calendar_brief_month_view(int year, int month, int day) {
635 struct tm starting_tm;
639 time_t previous_month;
641 char month_label[32];
643 /* Determine what day to start.
644 * First, back up to the 1st of the month...
646 memset(&starting_tm, 0, sizeof(struct tm));
647 starting_tm.tm_year = year - 1900;
648 starting_tm.tm_mon = month - 1;
649 starting_tm.tm_mday = day;
650 thetime = mktime(&starting_tm);
652 memcpy(&tm, &starting_tm, sizeof(struct tm));
653 while (tm.tm_mday != 1) {
654 thetime = thetime - (time_t)86400; /* go back 24 hours */
655 localtime_r(&thetime, &tm);
658 /* Determine previous and next months ... for links */
659 previous_month = thetime - (time_t)864000L; /* back 10 days */
660 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
662 /* Now back up until we're on a Sunday */
663 localtime_r(&thetime, &tm);
664 while (tm.tm_wday != 0) {
665 thetime = thetime - (time_t)86400; /* go back 24 hours */
666 localtime_r(&thetime, &tm);
669 /* Outer table (to get the background color) */
670 wprintf("<div class=\"fix_scrollbar_bug\">"
671 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
672 "bgcolor=#204B78><TR><TD>\n");
674 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
676 wprintf("<td align=center>");
678 localtime_r(&previous_month, &tm);
679 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
680 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
681 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
683 wc_strftime(month_label, sizeof month_label, "%B", &tm);
684 wprintf(" "
685 "<font size=+1 color=\"#FFFFFF\">"
688 " ", month_label, year);
690 localtime_r(&next_month, &tm);
691 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
692 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
693 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
695 wprintf("</td></tr></table>\n");
697 /* Inner table (the real one) */
698 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
699 "bgcolor=#EEEECC><TR>");
701 wprintf("<tr><td colspan=\"100%%\">\n");
704 for (i = 0; i < 35; ++i) {
705 char weeknumber[255];
706 char weekday_name[32];
708 localtime_r(&thetime, &tm);
711 /* Before displaying Sunday, start a new CELL */
713 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
714 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%%'> <tr><th colspan='4'>%s %s</th></tr>"
715 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
725 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
726 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
730 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
731 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
732 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
734 weekday_name,tm.tm_mday,
737 /* put the data of one day here, stupid */
738 calendar_month_view_brief_events(thetime, daycolor);
741 /* After displaying Saturday, end the row */
743 wprintf("</td></tr></table>\n");
746 thetime += (time_t)86400; /** ahead 24 hours */
749 wprintf("</table>" /** end of inner table */
750 "</td></tr></table>" /** end of outer table */
755 * Calendar week view -- not implemented yet, this is a stub function
757 void calendar_week_view(int year, int month, int day) {
758 wprintf("<center><i>week view FIXME</i></center><br />\n");
764 * Display events for a particular hour of a particular day.
765 * (Specify hour < 0 to show "all day" events)
767 * dstart and dend indicate which hours our "daytime" begins and end
769 void calendar_day_view_display_events(time_t thetime,
781 icalproperty *p = NULL;
782 icalproperty *q = NULL;
788 int all_day_event = 0;
789 int ongoing_event = 0;
790 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
792 struct icaltimetype t;
793 struct icaltimetype end_t;
794 struct icaltimetype today_start_t;
795 struct icaltimetype today_end_t;
796 struct tm starting_tm;
809 if (GetCount(WCC->disp_cal_items) == 0) {
810 /* nothing to display */
814 /* Create an imaginary event which spans the current day. Any events which
815 * overlap with this one take place at least partially in this day.
817 memset(&starting_tm, 0, sizeof(struct tm));
818 starting_tm.tm_year = year - 1900;
819 starting_tm.tm_mon = month - 1;
820 starting_tm.tm_mday = day;
821 starting_tm.tm_hour = 0;
822 starting_tm.tm_min = 0;
823 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
824 today_start_t.is_utc = 1;
826 memset(&ending_tm, 0, sizeof(struct tm));
827 ending_tm.tm_year = year - 1900;
828 ending_tm.tm_mon = month - 1;
829 ending_tm.tm_mday = day;
830 ending_tm.tm_hour = 23;
831 ending_tm.tm_min = 59;
832 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
833 today_end_t.is_utc = 1;
835 /* Now loop through our list of events to see which ones occur today.
837 Pos = GetNewHashPos();
838 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
839 Cal = (disp_cal*)vCal;
844 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
846 t = icalproperty_get_dtstart(q);
847 event_tt = icaltime_as_timet(t);
848 localtime_r(&event_tt, &event_te);
851 memset(&t, 0, sizeof t);
853 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
855 end_t = icalproperty_get_dtend(q);
856 event_tte = icaltime_as_timet(end_t);
857 localtime_r(&event_tte, &event_tm);
860 memset(&end_t, 0, sizeof end_t);
862 if (t.is_date) all_day_event = 1;
866 show_event = ((t.year == year) && (t.month == month) && (t.day == day) && (notime_events));
870 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
873 /* If we determined that this event occurs today, then display it.
875 p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
877 if ((show_event) && (p != NULL)) {
879 if ((event_te.tm_mday != day) || (event_tm.tm_mday != day)) ongoing_event = 1;
881 if (all_day_event && notime_events)
883 wprintf("<li class=\"event_framed%s\"> "
884 "<a href=\"display_edit_event?"
885 "msgnum=%ld&calview=day&year=%d&month=%d&day=%d\" "
886 " class=\"event_title\" "
888 (Cal->unread)?"_unread":"_read",
889 Cal->cal_msgnum, year, month, day);
890 wprintf("<i>%s</i><br />", _("All day event"));
891 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
892 wprintf("<i>%s</i> ", _("Summary:"));
893 escputs((char *) icalproperty_get_comment(p));
895 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
897 wprintf("<i>%s</i> ", _("Location:"));
898 escputs((char *)icalproperty_get_comment(q));
901 memset(&d_tm, 0, sizeof d_tm);
902 d_tm.tm_year = t.year - 1900;
903 d_tm.tm_mon = t.month - 1;
904 d_tm.tm_mday = t.day;
905 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
906 wprintf("<i>%s</i> %s<br>",_("Date:"), d_str);
907 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
909 wprintf("<i>%s</i> ", _("Notes:"));
910 escputs((char *)icalproperty_get_comment(q));
914 escputs((char *) icalproperty_get_comment(p));
915 wprintf("</a> <span>(");
916 wprintf(_("All day event"));
917 wprintf(")</span></li>\n");
919 else if (ongoing_event && notime_events)
921 wprintf("<li class=\"event_framed%s\"> "
922 "<a href=\"display_edit_event?"
923 "msgnum=%ld&calview=day&year=%d&month=%d&day=%d\" "
924 " class=\"event_title\" "
926 (Cal->unread)?"_unread":"_read",
927 Cal->cal_msgnum, year, month, day);
928 wprintf("<i>%s</i><br />", _("Ongoing event"));
929 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
930 wprintf("<i>%s</i> ", _("Summary:"));
931 escputs((char *) icalproperty_get_comment(p));
933 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
935 wprintf("<i>%s</i> ", _("Location:"));
936 escputs((char *)icalproperty_get_comment(q));
939 webcit_fmt_date(buf, event_tt, 1);
940 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
941 webcit_fmt_date(buf, event_tte, 1);
942 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
943 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
945 wprintf("<i>%s</i> ", _("Notes:"));
946 escputs((char *)icalproperty_get_comment(q));
950 escputs((char *) icalproperty_get_comment(p));
951 wprintf("</a> <span>(");
952 wprintf(_("Ongoing event"));
953 wprintf(")</span></li>\n");
955 else if (!all_day_event && !notime_events)
959 if (event_te.tm_mday != day) event_te.tm_hour = 0;
960 if (event_tm.tm_mday != day) event_tm.tm_hour = 24;
962 /* Calculate the location of the top of the box */
963 if (event_te.tm_hour < dstart) {
964 startmin = diffmin = event_te.tm_min / 6;
965 top = (event_te.tm_hour * 10) + startmin;
967 else if ((event_te.tm_hour >= dstart) && (event_te.tm_hour <= dend)) {
968 startmin = diffmin = (event_te.tm_min / 2);
969 top = (dstart * 10) + ((event_te.tm_hour - dstart) * 30) + startmin;
971 else if (event_te.tm_hour >dend) {
972 startmin = diffmin = event_te.tm_min / 6;
973 top = (dstart * 10) + ((dend - dstart - 1) * 30) + ((event_tm.tm_hour - dend + 1) * 10) + startmin ;
976 /* should never get here */
979 /* Calculate the location of the bottom of the box */
980 if (event_tm.tm_hour < dstart) {
981 endmin = diffmin = event_tm.tm_min / 6;
982 bottom = (event_tm.tm_hour * 10) + endmin;
984 else if ((event_tm.tm_hour >= dstart) && (event_tm.tm_hour <= dend)) {
985 endmin = diffmin = (event_tm.tm_min / 2);
986 bottom = (dstart * 10) + ((event_tm.tm_hour - dstart) * 30) + endmin ;
988 else if (event_tm.tm_hour >dend) {
989 endmin = diffmin = event_tm.tm_min / 6;
990 bottom = (dstart * 10) + ((dend - dstart + 1) * 30) + ((event_tm.tm_hour - dend - 1) * 10) + endmin;
993 /* should never get here */
996 wprintf("<dd class=\"event_framed%s\" "
997 "style=\"position: absolute; "
998 "top:%dpx; left:%dpx; "
1000 (Cal->unread)?"_unread":"_read",
1001 top, (gap * 40), (bottom-top)
1003 wprintf("<a href=\"display_edit_event?"
1004 "msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\" "
1005 "class=\"event_title\" "
1007 Cal->cal_msgnum, year, month, day, t.hour);
1008 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
1009 wprintf("<i>%s</i> ", _("Summary:"));
1010 escputs((char *) icalproperty_get_comment(p));
1012 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
1014 wprintf("<i>%s</i> ", _("Location:"));
1015 escputs((char *)icalproperty_get_comment(q));
1018 webcit_fmt_date(buf, event_tt, 1);
1019 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
1020 webcit_fmt_date(buf, event_tte, 1);
1021 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
1022 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
1024 wprintf("<i>%s</i> ", _("Notes:"));
1025 escputs((char *)icalproperty_get_comment(q));
1030 escputs((char *) icalproperty_get_comment(p));
1031 wprintf("</a></dd>\n");
1035 DeleteHashPos(&Pos);
1041 void calendar_day_view(int year, int month, int day) {
1043 struct icaltimetype today, yesterday, tomorrow;
1051 int extratimeline = 0;
1054 time_format = get_time_format_cached ();
1055 get_pref_long("daystart", &daystart, 8);
1056 get_pref_long("dayend", &dayend, 17);
1059 memset(&d_tm, 0, sizeof d_tm);
1060 d_tm.tm_year = year - 1900;
1061 d_tm.tm_mon = month - 1;
1063 today_t = mktime(&d_tm);
1065 /* Figure out the dates for "yesterday" and "tomorrow" links */
1067 memset(&today, 0, sizeof(struct icaltimetype));
1069 today.month = month;
1073 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
1075 yesterday = icaltime_normalize(yesterday);
1077 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
1079 tomorrow = icaltime_normalize(tomorrow);
1081 wprintf("<div class=\"fix_scrollbar_bug\">");
1083 /* Inner table (the real one) */
1084 wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
1086 /* Innermost cell (contains hours etc.) */
1087 wprintf("<td class=\"events_of_the_day\" >");
1088 wprintf("<dl class=\"events\" >");
1090 /* Now the middle of the day... */
1092 extratimeline = timeline / 3;
1094 for (hour = 0; hour < daystart; ++hour) { /* could do HEIGHT=xx */
1095 wprintf("<dt class=\"extrahour\" "
1097 "position: absolute; "
1098 "top: %dpx; left: 0px; "
1101 "<a href=\"display_edit_event?msgnum=0"
1102 "&calview=day&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
1103 (hour * extratimeline ), extratimeline,
1104 year, month, day, hour
1107 if (time_format == WC_TIMEFORMAT_24) {
1108 wprintf("%2d:00</a> ", hour);
1111 wprintf("%d:00%s</a> ",
1112 (hour <= 12 ? hour : hour-12),
1113 (hour < 12 ? "am" : "pm")
1120 gap = daystart * extratimeline;
1122 for (hour = daystart; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
1123 wprintf("<dt class=\"hour\" "
1125 "position: absolute; "
1126 "top: %ldpx; left: 0px; "
1129 "<a href=\"display_edit_event?msgnum=0&calview=day"
1130 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
1131 gap + ((hour - daystart) * timeline ), timeline,
1132 year, month, day, hour
1135 if (time_format == WC_TIMEFORMAT_24) {
1136 wprintf("%2d:00</a> ", hour);
1139 wprintf("%d:00%s</a> ",
1140 (hour <= 12 ? hour : hour-12),
1141 (hour < 12 ? "am" : "pm")
1148 gap = gap + ((dayend - daystart + 1) * timeline);
1150 for (hour = (dayend + 1); hour < 24; ++hour) { /* could do HEIGHT=xx */
1151 wprintf("<dt class=\"extrahour\" "
1153 "position: absolute; "
1154 "top: %ldpx; left: 0px; "
1157 "<a href=\"display_edit_event?msgnum=0&calview=day"
1158 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
1159 gap + ((hour - dayend - 1) * extratimeline ), extratimeline,
1160 year, month, day, hour
1163 if (time_format == WC_TIMEFORMAT_24) {
1164 wprintf("%2d:00</a> ", hour);
1167 wprintf("%d:00%s</a> ",
1168 (hour <= 12 ? hour : hour-12),
1169 (hour < 12 ? "am" : "pm")
1176 /* Display events with start and end times on this day */
1177 calendar_day_view_display_events(today_t, year, month, day, 0, daystart, dayend);
1180 wprintf("</td>"); /* end of innermost table */
1182 /* Display extra events (start/end times not present or not today) in the middle column */
1183 wprintf("<td class=\"extra_events\">");
1187 /* Display all-day events */
1188 calendar_day_view_display_events(today_t, year, month, day, 1, daystart, dayend);
1192 wprintf("</td>"); /** end extra on the middle */
1194 wprintf("<td width=20%% align=center valign=top>"); /** begin stuff-on-the-right */
1196 /* Begin todays-date-with-left-and-right-arrows */
1197 wprintf("<table border=0 width=100%% "
1198 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
1202 wprintf("<td align=center>");
1203 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
1204 yesterday.year, yesterday.month, yesterday.day);
1205 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
1208 wc_strftime(d_str, sizeof d_str,
1210 "<font size=+2>%B</font><br />"
1211 "<font size=+3>%d</font><br />"
1212 "<font size=+2>%Y</font><br />"
1216 wprintf("%s", d_str);
1219 wprintf("<td align=center>");
1220 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
1221 tomorrow.year, tomorrow.month, tomorrow.day);
1222 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
1223 " border=0></a>\n");
1226 wprintf("</tr></table>\n");
1227 /* End todays-date-with-left-and-right-arrows */
1229 /* Embed a mini month calendar in this space */
1230 wprintf("<br />\n");
1231 embeddable_mini_calendar(year, month, "readfwd?calview=day&year=%d&month=%d&day=%d");
1233 wprintf("</font></center>\n");
1235 wprintf("</td></tr>"); /** end stuff-on-the-right */
1237 wprintf("</table>" /** end of inner table */
1240 wprintf("<script type=\"text/javascript\">"
1241 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); "
1248 * Display today's events.
1250 void calendar_summary_view(void) {
1257 struct icaltimetype t;
1262 int all_day_event = 0;
1263 char timestring[SIZ];
1264 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
1266 if (GetCount(WC->disp_cal_items) == 0) {
1271 localtime_r(&now, &today_tm);
1273 Pos = GetNewHashPos();
1274 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
1275 Cal = (disp_cal*)vCal;
1276 p = icalcomponent_get_first_property(Cal->cal,
1277 ICAL_DTSTART_PROPERTY);
1279 t = icalproperty_get_dtstart(p);
1280 event_tt = icaltime_as_timet(t);
1287 fmt_time(timestring, event_tt);
1289 if (all_day_event) {
1290 gmtime_r(&event_tt, &event_tm);
1293 localtime_r(&event_tt, &event_tm);
1296 if ( (event_tm.tm_year == today_tm.tm_year)
1297 && (event_tm.tm_mon == today_tm.tm_mon)
1298 && (event_tm.tm_mday == today_tm.tm_mday)
1302 p = icalcomponent_get_first_property(
1304 ICAL_SUMMARY_PROPERTY);
1307 icalproperty_get_comment(p));
1308 wprintf(" (%s)<br />\n", timestring);
1313 DeleteHashPos(&Pos);
1314 DeleteHash(&WC->disp_cal_items);
1319 * do the whole calendar page
1320 * view any part of the calender. decide which way, etc.
1322 void do_calendar_view(void) {
1325 int year, month, day;
1328 /* In case no date was specified, go with today */
1330 localtime_r(&now, &tm);
1331 year = tm.tm_year + 1900;
1332 month = tm.tm_mon + 1;
1335 /* Now see if a date was specified */
1336 if (havebstr("year")) year = ibstr("year");
1337 if (havebstr("month")) month = ibstr("month");
1338 if (havebstr("day")) day = ibstr("day");
1340 /* How would you like that cooked? */
1341 if (havebstr("calview")) {
1342 strcpy(calview, bstr("calview"));
1345 strcpy(calview, "month");
1348 /* Display the selected view */
1349 if (!strcasecmp(calview, "day")) {
1350 calendar_day_view(year, month, day);
1352 else if (!strcasecmp(calview, "week")) {
1353 calendar_week_view(year, month, day);
1356 if (WC->wc_view == VIEW_CALBRIEF) {
1357 calendar_brief_month_view(year, month, day);
1360 calendar_month_view(year, month, day);
1364 /* Free the in-memory list of calendar items */
1365 DeleteHash(&WC->disp_cal_items);
1370 * Helper function for do_tasks_view(). Returns the due date/time of a vtodo.
1372 time_t get_task_due_date(icalcomponent *vtodo) {
1375 if (vtodo == NULL) {
1380 * If we're looking at a fully encapsulated VCALENDAR
1381 * rather than a VTODO component, recurse into the data
1382 * structure until we get a VTODO.
1384 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1385 return get_task_due_date(
1386 icalcomponent_get_first_component(
1387 vtodo, ICAL_VTODO_COMPONENT
1392 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1394 return(icaltime_as_timet(icalproperty_get_due(p)));
1403 * Compare the due dates of two tasks (this is for sorting)
1405 int task_due_cmp(const void *vtask1, const void *vtask2) {
1406 disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
1407 disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2);
1412 t1 = get_task_due_date(Task1->cal);
1413 t2 = get_task_due_date(Task2->cal);
1414 if (t1 < t2) return(-1);
1415 if (t1 > t2) return(1);
1420 * qsort filter to move completed tasks to bottom of task list
1422 int task_completed_cmp(const void *vtask1, const void *vtask2) {
1423 disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
1424 // disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2);
1426 icalproperty_status t1 = icalcomponent_get_status((Task1)->cal);
1427 // icalproperty_status t2 = icalcomponent_get_status(((struct disp_cal *)task2)->cal);
1429 if (t1 == ICAL_STATUS_COMPLETED)
1437 * do the whole task view stuff
1439 void do_tasks_view(void) {
1449 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
1451 wprintf("<div class=\"fix_scrollbar_bug\">"
1452 "<table class=\"calendar_view_background\"><tbody id=\"taskview\">\n<tr>\n"
1454 wprintf(_("Completed?"));
1455 wprintf("</th><th>");
1456 wprintf(_("Name of task"));
1457 wprintf("</th><th>");
1458 wprintf(_("Date due"));
1459 wprintf("</th><th>");
1460 wprintf(_("Category"));
1461 wprintf(" (<select id=\"selectcategory\"><option value=\"showall\">%s</option></select>)</th></tr>\n",
1464 nItems = GetCount(WC->disp_cal_items);
1466 /* Sort them if necessary
1468 SortByPayload(WC->disp_cal_items, task_due_cmp);
1470 * this shouldn't be neccessary, since we sort by the start time.
1473 /* And then again, by completed */
1475 SortByPayload(WC->disp_cal_items,
1476 task_completed_cmp);
1479 Pos = GetNewHashPos();
1480 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
1481 Cal = (disp_cal*)vCal;
1482 wprintf("<tr><td>");
1483 icalproperty_status todoStatus = icalcomponent_get_status(Cal->cal);
1484 wprintf("<input type=\"checkbox\" name=\"completed\" value=\"completed\" ");
1485 if (todoStatus == ICAL_STATUS_COMPLETED) {
1486 wprintf("checked=\"checked\" ");
1488 wprintf("disabled=\"disabled\">\n</td><td>");
1489 p = icalcomponent_get_first_property(Cal->cal,
1490 ICAL_SUMMARY_PROPERTY);
1491 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1493 urlescputs(WC->wc_roomname);
1495 /* wprintf("<img align=middle "
1496 "src=\"static/taskmanag_16x.gif\" border=0> "); */
1498 escputs((char *)icalproperty_get_comment(p));
1503 due = get_task_due_date(Cal->cal);
1504 wprintf("<td><span");
1506 webcit_fmt_date(buf, due, 0);
1512 wprintf("</span></td>");
1514 p = icalcomponent_get_first_property(Cal->cal,
1515 ICAL_CATEGORIES_PROPERTY);
1517 escputs((char *)icalproperty_get_categories(p));
1523 wprintf("</tbody></table></div>\n");
1526 DeleteHash(&WC->disp_cal_items);
1527 DeleteHashPos(&Pos);