4 * Handles the HTML display of calendar items.
11 void embeddable_mini_calendar(int year, int month, char *urlformat)
13 struct tm starting_tm;
17 time_t previous_month;
19 time_t colheader_time;
20 struct tm colheader_tm;
21 char colheader_label[32];
25 char escaped_urlformat[256];
27 snprintf(div_id, sizeof div_id, "mini_calendar_%d", rand() );
29 /* Determine what day to start. If an impossible value is found, start on Sunday.
31 get_pref_long("weekstart", &weekstart, 17);
32 if (weekstart > 6) weekstart = 0;
35 * Now back up to the 1st of the month...
37 memset(&starting_tm, 0, sizeof(struct tm));
39 starting_tm.tm_year = year - 1900;
40 starting_tm.tm_mon = month - 1;
41 starting_tm.tm_mday = 1;
42 thetime = mktime(&starting_tm);
44 memcpy(&tm, &starting_tm, sizeof(struct tm));
45 while (tm.tm_mday != 1) {
46 thetime = thetime - (time_t)86400; /* go back 24 hours */
47 localtime_r(&thetime, &tm);
50 /** Determine previous and next months ... for links */
51 previous_month = thetime - (time_t)864000L; /* back 10 days */
52 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
54 /** Now back up until we're on the user's preferred start day */
55 localtime_r(&thetime, &tm);
56 while (tm.tm_wday != weekstart) {
57 thetime = thetime - (time_t)86400; /* go back 24 hours */
58 localtime_r(&thetime, &tm);
61 wprintf("<div class=\"mini_calendar\" id=\"%s\">\n", div_id);
63 /* Previous month link */
64 localtime_r(&previous_month, &tm);
65 wprintf("<a href=\"javascript:minical_change_month(%d,%d);\">«</a>",
66 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
68 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
69 wprintf(" "
70 "<span class=\"mini_calendar_month_label\">"
73 " ", colheader_label, year);
76 localtime_r(&next_month, &tm);
77 wprintf("<a href=\"javascript:minical_change_month(%d,%d);\">»</a>",
78 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
80 wprintf("<table border=0 cellpadding=1 cellspacing=1 class=\"mini_calendar_days\">"
82 colheader_time = thetime;
84 colheader_time = thetime + (i * 86400) ;
85 localtime_r(&colheader_time, &colheader_tm);
86 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
87 wprintf("<th>%c</th>", colheader_label[0]);
93 /** Now do 35 or 42 days */
94 for (i = 0; i < 42; ++i) {
95 localtime_r(&thetime, &tm);
99 /** Before displaying Sunday, start a new row */
104 if (tm.tm_mon == month-1) {
105 snprintf(url, sizeof url, urlformat,
106 tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday);
107 wprintf("<td><a href=\"%s\">%d</a></td>", url, tm.tm_mday);
110 wprintf("<td> </td>");
113 /** After displaying one week, end the row */
120 thetime += (time_t)86400; /** ahead 24 hours */
123 wprintf("</table>" /** end of inner table */
126 /* javascript for previous and next month */
127 len = strlen(urlformat);
128 for (i=0; i<len; ++i) {
129 sprintf(&escaped_urlformat[i*2], "%02X", urlformat[i]);
132 wprintf("<script type=\"text/javascript\"> "
133 " function minical_change_month(year, month) { "
134 " p = 'year=' + year + '&month=' + month "
135 " + '&urlformat=%s&r=' + CtdlRandomString(); "
136 " new Ajax.Updater('%s', 'mini_calendar', "
137 " { method: 'get', parameters: p, evalScripts: true } ); "
141 escaped_urlformat, div_id
147 * \brief ajax embedder for the above mini calendar
149 void ajax_mini_calendar(void) {
152 char *escaped_urlformat;
154 escaped_urlformat = bstr("urlformat");
155 len = strlen(escaped_urlformat) * 2 ;
156 for (i=0; i<len; ++i) {
157 urlformat[i] = xtoi(&escaped_urlformat[i*2], 2);
161 embeddable_mini_calendar( ibstr("year"), ibstr("month"), urlformat );
166 * \brief Display one day of a whole month view of a calendar
167 * \param thetime the month we want to see
169 void calendar_month_view_display_events(int year, int month, int day)
176 icalproperty *p = NULL;
177 icalproperty *q = NULL;
178 struct icaltimetype t;
179 struct icaltimetype end_t;
180 struct icaltimetype today_start_t;
181 struct icaltimetype today_end_t;
182 struct tm starting_tm;
184 int all_day_event = 0;
187 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
190 if (GetCount(WCC->disp_cal_items) == 0) {
191 wprintf("<br /><br /><br />\n");
196 * Create an imaginary event which spans the 24 hours of today. Any events which
197 * overlap with this one take place at least partially in this day. We have to
198 * convert it from a struct tm in order to make it UTC.
200 memset(&starting_tm, 0, sizeof(struct tm));
201 starting_tm.tm_year = year - 1900;
202 starting_tm.tm_mon = month - 1;
203 starting_tm.tm_mday = day;
204 starting_tm.tm_hour = 0;
205 starting_tm.tm_min = 0;
206 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
207 today_start_t.is_utc = 1;
209 memset(&ending_tm, 0, sizeof(struct tm));
210 ending_tm.tm_year = year - 1900;
211 ending_tm.tm_mon = month - 1;
212 ending_tm.tm_mday = day;
213 ending_tm.tm_hour = 23;
214 ending_tm.tm_min = 59;
215 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
216 today_end_t.is_utc = 1;
219 * Now loop through our list of events to see which ones occur today.
221 Pos = GetNewHashPos();
222 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
223 Cal = (disp_cal*)vCal;
225 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
227 t = icalproperty_get_dtstart(q);
230 memset(&t, 0, sizeof t);
232 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
234 end_t = icalproperty_get_dtend(q);
237 memset(&end_t, 0, sizeof end_t);
239 if (t.is_date) all_day_event = 1;
243 show_event = ((t.year == year) && (t.month == month) && (t.day == day));
247 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
251 * If we determined that this event occurs today, then display it.
254 p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
258 wprintf("<table border=0 cellpadding=2><TR>"
259 "<td bgcolor=\"#CCCCDD\">"
263 wprintf("<font size=-1>"
264 "<a class=\"event%s\" href=\"display_edit_event?"
265 "msgnum=%ld&calview=month&year=%d&month=%d&day=%d\""
267 (Cal->unread)?"_unread":"_read",
272 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
273 wprintf("<i>%s</i> ", _("Summary:"));
274 escputs((char *)icalproperty_get_comment(p));
277 q = icalcomponent_get_first_property(
279 ICAL_LOCATION_PROPERTY);
281 wprintf("<i>%s</i> ", _("Location:"));
282 escputs((char *)icalproperty_get_comment(q));
287 * Only show start/end times if we're actually looking at the VEVENT
288 * component. Otherwise it shows bogus dates for e.g. timezones
290 if (icalcomponent_isa(Cal->cal) == ICAL_VEVENT_COMPONENT) {
292 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
294 t = icalproperty_get_dtstart(q);
299 memset(&d_tm, 0, sizeof d_tm);
300 d_tm.tm_year = t.year - 1900;
301 d_tm.tm_mon = t.month - 1;
302 d_tm.tm_mday = t.day;
303 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
304 wprintf("<i>%s</i> %s<br>",
308 tt = icaltime_as_timet(t);
309 webcit_fmt_date(buf, tt, 1);
310 wprintf("<i>%s</i> %s<br>",
311 _("Starting date/time:"), buf);
314 * Embed the 'show end date/time' loop inside here so it
315 * only executes if this is NOT an all day event.
317 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
319 t = icalproperty_get_dtend(q);
320 tt = icaltime_as_timet(t);
321 webcit_fmt_date(buf, tt, 1);
322 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
330 q = icalcomponent_get_first_property(Cal->cal, ICAL_DESCRIPTION_PROPERTY);
332 wprintf("<i>%s</i> ", _("Notes:"));
333 escputs((char *)icalproperty_get_comment(q));
339 icalproperty_get_comment(p));
340 wprintf("</a></font><br />\n");
343 wprintf("</td></tr></table>");
357 * \brief Display one day of a whole month view of a calendar
358 * \param thetime the month we want to see
360 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
368 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
374 struct icaltimetype t;
376 int month, day, year;
377 int all_day_event = 0;
381 time_format = get_time_format_cached ();
383 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
384 else timeformat="%I:%M %p";
386 localtime_r(&thetime, &today_tm);
387 month = today_tm.tm_mon + 1;
388 day = today_tm.tm_mday;
389 year = today_tm.tm_year + 1900;
391 Pos = GetNewHashPos();
392 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
393 Cal = (disp_cal*)vCal;
394 p = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
396 t = icalproperty_get_dtstart(p);
397 event_tt = icaltime_as_timet(t);
399 if (t.is_date) all_day_event = 1;
400 else all_day_event = 0;
403 gmtime_r(&event_tts, &event_tms);
406 localtime_r(&event_tts, &event_tms);
408 /* \todo epoch &! daymask */
409 if ((event_tms.tm_year == today_tm.tm_year)
410 && (event_tms.tm_mon == today_tm.tm_mon)
411 && (event_tms.tm_mday == today_tm.tm_mday)) {
417 p = icalcomponent_get_first_property(
419 ICAL_SUMMARY_PROPERTY);
420 e = icalcomponent_get_first_property(
422 ICAL_DTEND_PROPERTY);
423 if ((p != NULL) && (e != NULL)) {
426 t = icalproperty_get_dtend(e);
427 event_tte = icaltime_as_timet(t);
428 localtime_r(&event_tte, &event_tme);
429 difftime=(event_tte-event_tts)/60;
430 hours=(int)(difftime / 60);
431 minutes=difftime % 60;
432 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
434 "<a class=\"event%s\" href=\"display_edit_event?msgnum=%ld&calview=calbrief&year=%s&month=%s&day=%s\">",
437 (Cal->unread)?"_unread":"_read",
446 icalproperty_get_comment(p));
447 /* \todo: allso ammitime format */
448 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
449 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
451 wprintf("</a></font></td>"
452 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
469 * view one month. pretty view
471 void calendar_month_view(int year, int month, int day) {
472 struct tm starting_tm;
476 time_t previous_month;
478 time_t colheader_time;
479 struct tm colheader_tm;
480 char colheader_label[32];
485 * Determine what day to start. If an impossible value is found, start on Sunday.
487 get_pref_long("weekstart", &weekstart, 17);
488 if (weekstart > 6) weekstart = 0;
491 * Now back up to the 1st of the month...
493 memset(&starting_tm, 0, sizeof(struct tm));
495 starting_tm.tm_year = year - 1900;
496 starting_tm.tm_mon = month - 1;
497 starting_tm.tm_mday = day;
498 thetime = mktime(&starting_tm);
500 memcpy(&tm, &starting_tm, sizeof(struct tm));
501 while (tm.tm_mday != 1) {
502 thetime = thetime - (time_t)86400; /* go back 24 hours */
503 localtime_r(&thetime, &tm);
506 /* Determine previous and next months ... for links */
507 previous_month = thetime - (time_t)864000L; /* back 10 days */
508 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
510 /* Now back up until we're on the user's preferred start day */
511 localtime_r(&thetime, &tm);
512 while (tm.tm_wday != weekstart) {
513 thetime = thetime - (time_t)86400; /* go back 24 hours */
514 lprintf(9, "Subtracting a day, thetime is now %d - %s", thetime, ctime(&thetime));
515 localtime_r(&thetime, &tm);
516 lprintf(9, "tm.tm_wday is %d, weekstart is %d\n", tm.tm_wday, weekstart);
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;
1055 int extratimeline = 0;
1058 time_format = get_time_format_cached ();
1059 get_pref_long("daystart", &daystart, 8);
1060 get_pref_long("dayend", &dayend, 17);
1063 memset(&d_tm, 0, sizeof d_tm);
1064 d_tm.tm_year = year - 1900;
1065 d_tm.tm_mon = month - 1;
1067 today_t = mktime(&d_tm);
1069 /* Figure out the dates for "yesterday" and "tomorrow" links */
1071 memset(&today, 0, sizeof(struct icaltimetype));
1073 today.month = month;
1077 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
1079 yesterday = icaltime_normalize(yesterday);
1081 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
1083 tomorrow = icaltime_normalize(tomorrow);
1085 wprintf("<div class=\"fix_scrollbar_bug\">");
1087 /* Inner table (the real one) */
1088 wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
1090 /* Innermost cell (contains hours etc.) */
1091 wprintf("<td class=\"events_of_the_day\" >");
1092 wprintf("<dl class=\"events\" >");
1094 /* Now the middle of the day... */
1096 extratimeline = timeline / 3;
1098 for (hour = 0; hour < daystart; ++hour) { /* could do HEIGHT=xx */
1099 wprintf("<dt class=\"extrahour\" "
1101 "position: absolute; "
1102 "top: %dpx; left: 0px; "
1105 "<a href=\"display_edit_event?msgnum=0"
1106 "&calview=day&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
1107 (hour * extratimeline ), extratimeline,
1108 year, month, day, hour
1111 if (time_format == WC_TIMEFORMAT_24) {
1112 wprintf("%2d:00</a> ", hour);
1115 wprintf("%d:00%s</a> ",
1116 (hour <= 12 ? hour : hour-12),
1117 (hour < 12 ? "am" : "pm")
1124 gap = daystart * extratimeline;
1126 for (hour = daystart; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
1127 wprintf("<dt class=\"hour\" "
1129 "position: absolute; "
1130 "top: %ldpx; left: 0px; "
1133 "<a href=\"display_edit_event?msgnum=0&calview=day"
1134 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
1135 gap + ((hour - daystart) * timeline ), timeline,
1136 year, month, day, hour
1139 if (time_format == WC_TIMEFORMAT_24) {
1140 wprintf("%2d:00</a> ", hour);
1143 wprintf("%d:00%s</a> ",
1144 (hour <= 12 ? hour : hour-12),
1145 (hour < 12 ? "am" : "pm")
1152 gap = gap + ((dayend - daystart + 1) * timeline);
1154 for (hour = (dayend + 1); hour < 24; ++hour) { /* could do HEIGHT=xx */
1155 wprintf("<dt class=\"extrahour\" "
1157 "position: absolute; "
1158 "top: %ldpx; left: 0px; "
1161 "<a href=\"display_edit_event?msgnum=0&calview=day"
1162 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
1163 gap + ((hour - dayend - 1) * extratimeline ), extratimeline,
1164 year, month, day, hour
1167 if (time_format == WC_TIMEFORMAT_24) {
1168 wprintf("%2d:00</a> ", hour);
1171 wprintf("%d:00%s</a> ",
1172 (hour <= 12 ? hour : hour-12),
1173 (hour < 12 ? "am" : "pm")
1180 /* Display events with start and end times on this day */
1181 calendar_day_view_display_events(today_t, year, month, day, 0, daystart, dayend);
1184 wprintf("</td>"); /* end of innermost table */
1186 /* Display extra events (start/end times not present or not today) in the middle column */
1187 wprintf("<td class=\"extra_events\">");
1191 /* Display all-day events */
1192 calendar_day_view_display_events(today_t, year, month, day, 1, daystart, dayend);
1196 wprintf("</td>"); /** end extra on the middle */
1198 wprintf("<td width=20%% align=center valign=top>"); /** begin stuff-on-the-right */
1200 /* Begin todays-date-with-left-and-right-arrows */
1201 wprintf("<table border=0 width=100%% "
1202 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
1206 wprintf("<td align=center>");
1207 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
1208 yesterday.year, yesterday.month, yesterday.day);
1209 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
1212 wc_strftime(d_str, sizeof d_str,
1214 "<font size=+2>%B</font><br />"
1215 "<font size=+3>%d</font><br />"
1216 "<font size=+2>%Y</font><br />"
1220 wprintf("%s", d_str);
1223 wprintf("<td align=center>");
1224 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
1225 tomorrow.year, tomorrow.month, tomorrow.day);
1226 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
1227 " border=0></a>\n");
1230 wprintf("</tr></table>\n");
1231 /* End todays-date-with-left-and-right-arrows */
1233 /* Embed a mini month calendar in this space */
1234 wprintf("<br />\n");
1235 embeddable_mini_calendar(year, month, "readfwd?calview=day&year=%d&month=%d&day=%d");
1237 wprintf("</font></center>\n");
1239 wprintf("</td></tr>"); /** end stuff-on-the-right */
1241 wprintf("</table>" /** end of inner table */
1244 wprintf("<script type=\"text/javascript\">"
1245 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); "
1252 * Display today's events.
1254 void calendar_summary_view(void) {
1261 struct icaltimetype t;
1266 int all_day_event = 0;
1267 char timestring[SIZ];
1268 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
1270 if (GetCount(WC->disp_cal_items) == 0) {
1275 localtime_r(&now, &today_tm);
1277 Pos = GetNewHashPos();
1278 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
1279 Cal = (disp_cal*)vCal;
1280 p = icalcomponent_get_first_property(Cal->cal,
1281 ICAL_DTSTART_PROPERTY);
1283 t = icalproperty_get_dtstart(p);
1284 event_tt = icaltime_as_timet(t);
1291 fmt_time(timestring, event_tt);
1293 if (all_day_event) {
1294 gmtime_r(&event_tt, &event_tm);
1297 localtime_r(&event_tt, &event_tm);
1300 if ( (event_tm.tm_year == today_tm.tm_year)
1301 && (event_tm.tm_mon == today_tm.tm_mon)
1302 && (event_tm.tm_mday == today_tm.tm_mday)
1306 p = icalcomponent_get_first_property(
1308 ICAL_SUMMARY_PROPERTY);
1311 icalproperty_get_comment(p));
1312 wprintf(" (%s)<br />\n", timestring);
1317 DeleteHashPos(&Pos);
1318 DeleteHash(&WC->disp_cal_items);
1323 * do the whole calendar page
1324 * view any part of the calender. decide which way, etc.
1326 void do_calendar_view(void) {
1329 int year, month, day;
1332 /* In case no date was specified, go with today */
1334 localtime_r(&now, &tm);
1335 year = tm.tm_year + 1900;
1336 month = tm.tm_mon + 1;
1339 /* Now see if a date was specified */
1340 if (havebstr("year")) year = ibstr("year");
1341 if (havebstr("month")) month = ibstr("month");
1342 if (havebstr("day")) day = ibstr("day");
1344 /* How would you like that cooked? */
1345 if (havebstr("calview")) {
1346 strcpy(calview, bstr("calview"));
1349 strcpy(calview, "month");
1352 /* Display the selected view */
1353 if (!strcasecmp(calview, "day")) {
1354 calendar_day_view(year, month, day);
1356 else if (!strcasecmp(calview, "week")) {
1357 calendar_week_view(year, month, day);
1360 if (WC->wc_view == VIEW_CALBRIEF) {
1361 calendar_brief_month_view(year, month, day);
1364 calendar_month_view(year, month, day);
1368 /* Free the in-memory list of calendar items */
1369 DeleteHash(&WC->disp_cal_items);
1374 * Helper function for do_tasks_view(). Returns the due date/time of a vtodo.
1376 time_t get_task_due_date(icalcomponent *vtodo) {
1379 if (vtodo == NULL) {
1384 * If we're looking at a fully encapsulated VCALENDAR
1385 * rather than a VTODO component, recurse into the data
1386 * structure until we get a VTODO.
1388 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1389 return get_task_due_date(
1390 icalcomponent_get_first_component(
1391 vtodo, ICAL_VTODO_COMPONENT
1396 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1398 return(icaltime_as_timet(icalproperty_get_due(p)));
1407 * Compare the due dates of two tasks (this is for sorting)
1409 int task_due_cmp(const void *vtask1, const void *vtask2) {
1410 disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
1411 disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2);
1416 t1 = get_task_due_date(Task1->cal);
1417 t2 = get_task_due_date(Task2->cal);
1418 if (t1 < t2) return(-1);
1419 if (t1 > t2) return(1);
1424 * qsort filter to move completed tasks to bottom of task list
1426 int task_completed_cmp(const void *vtask1, const void *vtask2) {
1427 disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
1428 // disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2);
1430 icalproperty_status t1 = icalcomponent_get_status((Task1)->cal);
1431 // icalproperty_status t2 = icalcomponent_get_status(((struct disp_cal *)task2)->cal);
1433 if (t1 == ICAL_STATUS_COMPLETED)
1441 * do the whole task view stuff
1443 void do_tasks_view(void) {
1453 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
1455 wprintf("<div class=\"fix_scrollbar_bug\">"
1456 "<table class=\"calendar_view_background\"><tbody id=\"taskview\">\n<tr>\n"
1458 wprintf(_("Completed?"));
1459 wprintf("</th><th>");
1460 wprintf(_("Name of task"));
1461 wprintf("</th><th>");
1462 wprintf(_("Date due"));
1463 wprintf("</th><th>");
1464 wprintf(_("Category"));
1465 wprintf(" (<select id=\"selectcategory\"><option value=\"showall\">%s</option></select>)</th></tr>\n",
1468 nItems = GetCount(WC->disp_cal_items);
1470 /* Sort them if necessary
1472 SortByPayload(WC->disp_cal_items, task_due_cmp);
1474 * this shouldn't be neccessary, since we sort by the start time.
1477 /* And then again, by completed */
1479 SortByPayload(WC->disp_cal_items,
1480 task_completed_cmp);
1483 Pos = GetNewHashPos();
1484 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
1485 Cal = (disp_cal*)vCal;
1486 wprintf("<tr><td>");
1487 icalproperty_status todoStatus = icalcomponent_get_status(Cal->cal);
1488 wprintf("<input type=\"checkbox\" name=\"completed\" value=\"completed\" ");
1489 if (todoStatus == ICAL_STATUS_COMPLETED) {
1490 wprintf("checked=\"checked\" ");
1492 wprintf("disabled=\"disabled\">\n</td><td>");
1493 p = icalcomponent_get_first_property(Cal->cal,
1494 ICAL_SUMMARY_PROPERTY);
1495 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1497 urlescputs(WC->wc_roomname);
1499 /* wprintf("<img align=middle "
1500 "src=\"static/taskmanag_16x.gif\" border=0> "); */
1502 escputs((char *)icalproperty_get_comment(p));
1507 due = get_task_due_date(Cal->cal);
1508 wprintf("<td><span");
1510 webcit_fmt_date(buf, due, 0);
1516 wprintf("</span></td>");
1518 p = icalcomponent_get_first_property(Cal->cal,
1519 ICAL_CATEGORIES_PROPERTY);
1521 escputs((char *)icalproperty_get_categories(p));
1527 wprintf("</tbody></table></div>\n");
1530 DeleteHash(&WC->disp_cal_items);
1531 DeleteHashPos(&Pos);