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,
396 ICAL_DTSTART_PROPERTY);
398 t = icalproperty_get_dtstart(p);
399 event_tt = icaltime_as_timet(t);
401 if (t.is_date) all_day_event = 1;
402 else all_day_event = 0;
405 gmtime_r(&event_tts, &event_tms);
408 localtime_r(&event_tts, &event_tms);
410 /** \todo epoch &! daymask */
411 if ((event_tms.tm_year == today_tm.tm_year)
412 && (event_tms.tm_mon == today_tm.tm_mon)
413 && (event_tms.tm_mday == today_tm.tm_mday)) {
419 p = icalcomponent_get_first_property(
421 ICAL_SUMMARY_PROPERTY);
422 e = icalcomponent_get_first_property(
424 ICAL_DTEND_PROPERTY);
425 if ((p != NULL) && (e != NULL)) {
428 t = icalproperty_get_dtend(e);
429 event_tte = icaltime_as_timet(t);
430 localtime_r(&event_tte, &event_tme);
431 difftime=(event_tte-event_tts)/60;
432 hours=(int)(difftime / 60);
433 minutes=difftime % 60;
434 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
436 "<a class=\"event%s\" href=\"display_edit_event?msgnum=%ld&calview=calbrief&year=%s&month=%s&day=%s\">",
439 (Cal->unread)?"_unread":"_read",
448 icalproperty_get_comment(p));
449 /** \todo: allso ammitime format */
450 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
451 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
453 wprintf("</a></font></td>"
454 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
472 * \brief view one month. pretty view
473 * \param year the year
474 * \param month the month
475 * \param day the actual day we want to see
477 void calendar_month_view(int year, int month, int day) {
478 struct tm starting_tm;
482 time_t previous_month;
484 time_t colheader_time;
485 struct tm colheader_tm;
486 char colheader_label[32];
489 char weekstart_buf[16];
491 /* Determine what day to start.
493 get_preference("weekstart", weekstart_buf, sizeof weekstart_buf);
494 weekstart = atoi(weekstart_buf);
497 * Now back up to the 1st of the month...
499 memset(&starting_tm, 0, sizeof(struct tm));
501 starting_tm.tm_year = year - 1900;
502 starting_tm.tm_mon = month - 1;
503 starting_tm.tm_mday = day;
504 thetime = mktime(&starting_tm);
506 memcpy(&tm, &starting_tm, sizeof(struct tm));
507 while (tm.tm_mday != 1) {
508 thetime = thetime - (time_t)86400; /* go back 24 hours */
509 localtime_r(&thetime, &tm);
512 /** Determine previous and next months ... for links */
513 previous_month = thetime - (time_t)864000L; /* back 10 days */
514 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
516 /** Now back up until we're on the user's preferred start day */
517 localtime_r(&thetime, &tm);
518 while (tm.tm_wday != weekstart) {
519 thetime = thetime - (time_t)86400; /* go back 24 hours */
520 localtime_r(&thetime, &tm);
523 /** Outer table (to get the background color) */
524 wprintf("<div class=\"fix_scrollbar_bug\">"
525 "<table class=\"calendar\"> \n <tr><td>");
527 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
529 wprintf("<td align=center>");
531 localtime_r(&previous_month, &tm);
532 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
533 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
534 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
536 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
537 wprintf(" "
538 "<font size=+1 color=\"#FFFFFF\">"
541 " ", colheader_label, year);
543 localtime_r(&next_month, &tm);
544 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
545 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
546 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
548 wprintf("</td></tr></table>\n");
550 /** Inner table (the real one) */
551 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
552 "bgcolor=#204B78 id=\"inner_month\"><tr>");
553 colheader_time = thetime;
554 for (i=0; i<7; ++i) {
555 colheader_time = thetime + (i * 86400) ;
556 localtime_r(&colheader_time, &colheader_tm);
557 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
558 wprintf("<th align=center width=14%%>"
559 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
565 /** Now do 35 or 42 days */
566 for (i = 0; i < 42; ++i) {
567 localtime_r(&thetime, &tm);
569 if ((i < 35) || (chg_month == 0)) {
571 if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) {
578 /** Before displaying Sunday, start a new row */
583 wprintf("<td class=\"cal%s\"><div class=\"day\">",
584 ((tm.tm_mon != month-1) ? "out" :
585 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
588 if ((i==0) || (tm.tm_mday == 1)) {
589 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
590 wprintf("%s ", colheader_label);
592 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
599 /** put the data here, stupid */
600 calendar_month_view_display_events(
608 /** After displaying Saturday, end the row */
615 thetime += (time_t)86400; /** ahead 24 hours */
618 wprintf("</table>" /** end of inner table */
619 "</td></tr></table>" /** end of outer table */
623 * Initialize the bubble tooltips.
625 * Yes, this is as stupid as it looks. Instead of just making the call
626 * to btt_enableTooltips() straight away, we have to create a timer event
627 * and let it initialize as an event after 1 millisecond. This is to
628 * work around a bug in Internet Explorer that causes it to crash if we
629 * manipulate the innerHTML of various DOM nodes while the page is still
630 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
631 * for more information.
633 wprintf("<script type=\"text/javascript\">"
634 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
640 * \brief view one month. brief view
641 * \param year the year
642 * \param month the month
643 * \param day the actual day we want to see
645 void calendar_brief_month_view(int year, int month, int day) {
646 struct tm starting_tm;
650 time_t previous_month;
652 char month_label[32];
654 /** Determine what day to start.
655 * First, back up to the 1st of the month...
657 memset(&starting_tm, 0, sizeof(struct tm));
658 starting_tm.tm_year = year - 1900;
659 starting_tm.tm_mon = month - 1;
660 starting_tm.tm_mday = day;
661 thetime = mktime(&starting_tm);
663 memcpy(&tm, &starting_tm, sizeof(struct tm));
664 while (tm.tm_mday != 1) {
665 thetime = thetime - (time_t)86400; /* go back 24 hours */
666 localtime_r(&thetime, &tm);
669 /** Determine previous and next months ... for links */
670 previous_month = thetime - (time_t)864000L; /* back 10 days */
671 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
673 /** Now back up until we're on a Sunday */
674 localtime_r(&thetime, &tm);
675 while (tm.tm_wday != 0) {
676 thetime = thetime - (time_t)86400; /* go back 24 hours */
677 localtime_r(&thetime, &tm);
680 /** Outer table (to get the background color) */
681 wprintf("<div class=\"fix_scrollbar_bug\">"
682 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
683 "bgcolor=#204B78><TR><TD>\n");
685 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
687 wprintf("<td align=center>");
689 localtime_r(&previous_month, &tm);
690 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
691 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
692 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
694 wc_strftime(month_label, sizeof month_label, "%B", &tm);
695 wprintf(" "
696 "<font size=+1 color=\"#FFFFFF\">"
699 " ", month_label, year);
701 localtime_r(&next_month, &tm);
702 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
703 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
704 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
706 wprintf("</td></tr></table>\n");
708 /** Inner table (the real one) */
709 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
710 "bgcolor=#EEEECC><TR>");
712 wprintf("<tr><td colspan=\"100%\">\n");
714 /** Now do 35 days */
715 for (i = 0; i < 35; ++i) {
716 char weeknumber[255];
717 char weekday_name[32];
719 localtime_r(&thetime, &tm);
722 /** Before displaying Sunday, start a new CELL */
724 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
725 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
726 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
736 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
737 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
741 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
742 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
743 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
745 weekday_name,tm.tm_mday,
748 /** put the data of one day here, stupid */
749 calendar_month_view_brief_events(thetime, daycolor);
752 /** After displaying Saturday, end the row */
754 wprintf("</td></tr></table>\n");
757 thetime += (time_t)86400; /** ahead 24 hours */
760 wprintf("</table>" /** end of inner table */
761 "</td></tr></table>" /** end of outer table */
766 * \brief view one week
767 * this should view just one week, but it's not here yet.
768 * \todo ny implemented
769 * \param year the year
770 * \param month the month
771 * \param day the day which we want to see the week around
773 void calendar_week_view(int year, int month, int day) {
774 wprintf("<center><i>week view FIXME</i></center><br />\n");
779 * \brief display one day
780 * Display events for a particular hour of a particular day.
781 * (Specify hour < 0 to show "all day" events)
782 * \param year the year
783 * \param month the month
785 * \param hour the hour we want to start displaying
786 * \param dstart daystart
789 void calendar_day_view_display_events(time_t thetime,
801 icalproperty *p = NULL;
802 icalproperty *q = NULL;
808 int all_day_event = 0;
809 int ongoing_event = 0;
810 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
812 struct icaltimetype t;
813 struct icaltimetype end_t;
814 struct icaltimetype today_start_t;
815 struct icaltimetype today_end_t;
816 struct tm starting_tm;
829 if (GetCount(WCC->disp_cal_items) == 0) {
830 /* nothing to display */
834 /* Create an imaginary event which spans the current day. Any events which
835 * overlap with this one take place at least partially in this day.
837 memset(&starting_tm, 0, sizeof(struct tm));
838 starting_tm.tm_year = year - 1900;
839 starting_tm.tm_mon = month - 1;
840 starting_tm.tm_mday = day;
841 starting_tm.tm_hour = 0;
842 starting_tm.tm_min = 0;
843 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
844 today_start_t.is_utc = 1;
846 memset(&ending_tm, 0, sizeof(struct tm));
847 ending_tm.tm_year = year - 1900;
848 ending_tm.tm_mon = month - 1;
849 ending_tm.tm_mday = day;
850 ending_tm.tm_hour = 23;
851 ending_tm.tm_min = 59;
852 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
853 today_end_t.is_utc = 1;
855 /* Now loop through our list of events to see which ones occur today.
857 Pos = GetNewHashPos();
858 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
859 Cal = (disp_cal*)vCal;
864 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
866 t = icalproperty_get_dtstart(q);
867 event_tt = icaltime_as_timet(t);
868 localtime_r(&event_tt, &event_te);
871 memset(&t, 0, sizeof t);
873 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
875 end_t = icalproperty_get_dtend(q);
876 event_tte = icaltime_as_timet(end_t);
877 localtime_r(&event_tte, &event_tm);
880 memset(&end_t, 0, sizeof end_t);
882 if (t.is_date) all_day_event = 1;
886 show_event = ((t.year == year) && (t.month == month) && (t.day == day) && (notime_events));
890 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
893 /* If we determined that this event occurs today, then display it.
895 p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
897 if ((show_event) && (p != NULL)) {
899 if ((event_te.tm_mday != day) || (event_tm.tm_mday != day)) ongoing_event = 1;
901 if (all_day_event && notime_events)
903 wprintf("<li class=\"event_framed%s\"> "
904 "<a href=\"display_edit_event?"
905 "msgnum=%ld&calview=day&year=%d&month=%d&day=%d\" "
906 " class=\"event_title\" "
908 (Cal->unread)?"_unread":"_read",
909 Cal->cal_msgnum, year, month, day);
910 wprintf("<i>%s</i><br />", _("All day event"));
911 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
912 wprintf("<i>%s</i> ", _("Summary:"));
913 escputs((char *) icalproperty_get_comment(p));
915 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
917 wprintf("<i>%s</i> ", _("Location:"));
918 escputs((char *)icalproperty_get_comment(q));
921 memset(&d_tm, 0, sizeof d_tm);
922 d_tm.tm_year = t.year - 1900;
923 d_tm.tm_mon = t.month - 1;
924 d_tm.tm_mday = t.day;
925 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
926 wprintf("<i>%s</i> %s<br>",_("Date:"), d_str);
927 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
929 wprintf("<i>%s</i> ", _("Notes:"));
930 escputs((char *)icalproperty_get_comment(q));
934 escputs((char *) icalproperty_get_comment(p));
935 wprintf("</a> <span>(");
936 wprintf(_("All day event"));
937 wprintf(")</span></li>\n");
939 else if (ongoing_event && notime_events)
941 wprintf("<li class=\"event_framed%s\"> "
942 "<a href=\"display_edit_event?"
943 "msgnum=%ld&calview=day&year=%d&month=%d&day=%d\" "
944 " class=\"event_title\" "
946 (Cal->unread)?"_unread":"_read",
947 Cal->cal_msgnum, year, month, day);
948 wprintf("<i>%s</i><br />", _("Ongoing event"));
949 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
950 wprintf("<i>%s</i> ", _("Summary:"));
951 escputs((char *) icalproperty_get_comment(p));
953 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
955 wprintf("<i>%s</i> ", _("Location:"));
956 escputs((char *)icalproperty_get_comment(q));
959 webcit_fmt_date(buf, event_tt, 1);
960 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
961 webcit_fmt_date(buf, event_tte, 1);
962 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
963 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
965 wprintf("<i>%s</i> ", _("Notes:"));
966 escputs((char *)icalproperty_get_comment(q));
970 escputs((char *) icalproperty_get_comment(p));
971 wprintf("</a> <span>(");
972 wprintf(_("Ongoing event"));
973 wprintf(")</span></li>\n");
975 else if (!all_day_event && !notime_events)
979 if (event_te.tm_mday != day) event_te.tm_hour = 0;
980 if (event_tm.tm_mday != day) event_tm.tm_hour = 24;
982 /* Calculate the location of the top of the box */
983 if (event_te.tm_hour < dstart) {
984 startmin = diffmin = event_te.tm_min / 6;
985 top = (event_te.tm_hour * 10) + startmin;
987 else if ((event_te.tm_hour >= dstart) && (event_te.tm_hour <= dend)) {
988 startmin = diffmin = (event_te.tm_min / 2);
989 top = (dstart * 10) + ((event_te.tm_hour - dstart) * 30) + startmin;
991 else if (event_te.tm_hour >dend) {
992 startmin = diffmin = event_te.tm_min / 6;
993 top = (dstart * 10) + ((dend - dstart - 1) * 30) + ((event_tm.tm_hour - dend + 1) * 10) + startmin ;
996 /* should never get here */
999 /* Calculate the location of the bottom of the box */
1000 if (event_tm.tm_hour < dstart) {
1001 endmin = diffmin = event_tm.tm_min / 6;
1002 bottom = (event_tm.tm_hour * 10) + endmin;
1004 else if ((event_tm.tm_hour >= dstart) && (event_tm.tm_hour <= dend)) {
1005 endmin = diffmin = (event_tm.tm_min / 2);
1006 bottom = (dstart * 10) + ((event_tm.tm_hour - dstart) * 30) + endmin ;
1008 else if (event_tm.tm_hour >dend) {
1009 endmin = diffmin = event_tm.tm_min / 6;
1010 bottom = (dstart * 10) + ((dend - dstart + 1) * 30) + ((event_tm.tm_hour - dend - 1) * 10) + endmin;
1013 /* should never get here */
1016 wprintf("<dd class=\"event_framed%s\" "
1017 "style=\"position: absolute; "
1018 "top:%dpx; left:%dpx; "
1019 "height:%dpx; \" >",
1020 (Cal->unread)?"_unread":"_read",
1021 top, (gap * 40), (bottom-top)
1023 wprintf("<a href=\"display_edit_event?"
1024 "msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\" "
1025 "class=\"event_title\" "
1027 Cal->cal_msgnum, year, month, day, t.hour);
1028 wprintf("<i>%s: %s</i><br />", _("From"), Cal->from);
1029 wprintf("<i>%s</i> ", _("Summary:"));
1030 escputs((char *) icalproperty_get_comment(p));
1032 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
1034 wprintf("<i>%s</i> ", _("Location:"));
1035 escputs((char *)icalproperty_get_comment(q));
1038 webcit_fmt_date(buf, event_tt, 1);
1039 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
1040 webcit_fmt_date(buf, event_tte, 1);
1041 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
1042 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
1044 wprintf("<i>%s</i> ", _("Notes:"));
1045 escputs((char *)icalproperty_get_comment(q));
1050 escputs((char *) icalproperty_get_comment(p));
1051 wprintf("</a></dd>\n");
1055 DeleteHashPos(&Pos);
1059 * \brief view one day
1060 * \param year the year
1061 * \param month the month
1062 * \param day the day we want to display
1064 void calendar_day_view(int year, int month, int day) {
1066 struct icaltimetype today, yesterday, tomorrow;
1069 char daystart_str[16], dayend_str[16];
1075 int extratimeline = 0;
1078 time_format = get_time_format_cached ();
1079 get_preference("daystart", daystart_str, sizeof daystart_str);
1080 if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
1081 get_preference("dayend", dayend_str, sizeof dayend_str);
1082 if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str);
1085 memset(&d_tm, 0, sizeof d_tm);
1086 d_tm.tm_year = year - 1900;
1087 d_tm.tm_mon = month - 1;
1089 today_t = mktime(&d_tm);
1091 /** Figure out the dates for "yesterday" and "tomorrow" links */
1093 memset(&today, 0, sizeof(struct icaltimetype));
1095 today.month = month;
1099 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
1101 yesterday = icaltime_normalize(yesterday);
1103 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
1105 tomorrow = icaltime_normalize(tomorrow);
1107 wprintf("<div class=\"fix_scrollbar_bug\">");
1109 /** Inner table (the real one) */
1110 wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
1112 /** Innermost cell (contains hours etc.) */
1113 wprintf("<td class=\"events_of_the_day\" >");
1114 wprintf("<dl class=\"events\" >");
1116 /** Now the middle of the day... */
1118 extratimeline = timeline / 3;
1120 for (hour = 0; hour < daystart; ++hour) { /* could do HEIGHT=xx */
1121 wprintf("<dt class=\"extrahour\" "
1123 "position: absolute; "
1124 "top: %dpx; left: 0px; "
1127 "<a href=\"display_edit_event?msgnum=0"
1128 "&calview=day&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
1129 (hour * extratimeline ), extratimeline,
1130 year, month, day, hour
1133 if (time_format == WC_TIMEFORMAT_24) {
1134 wprintf("%2d:00</a> ", hour);
1137 wprintf("%d:00%s</a> ",
1138 (hour <= 12 ? hour : hour-12),
1139 (hour < 12 ? "am" : "pm")
1146 gap = daystart * extratimeline;
1148 for (hour = daystart; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
1149 wprintf("<dt class=\"hour\" "
1151 "position: absolute; "
1152 "top: %dpx; left: 0px; "
1155 "<a href=\"display_edit_event?msgnum=0&calview=day"
1156 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
1157 gap + ((hour - daystart) * timeline ), timeline,
1158 year, month, day, hour
1161 if (time_format == WC_TIMEFORMAT_24) {
1162 wprintf("%2d:00</a> ", hour);
1165 wprintf("%d:00%s</a> ",
1166 (hour <= 12 ? hour : hour-12),
1167 (hour < 12 ? "am" : "pm")
1174 gap = gap + ((dayend - daystart + 1) * timeline);
1176 for (hour = (dayend + 1); hour < 24; ++hour) { /* could do HEIGHT=xx */
1177 wprintf("<dt class=\"extrahour\" "
1179 "position: absolute; "
1180 "top: %dpx; left: 0px; "
1183 "<a href=\"display_edit_event?msgnum=0&calview=day"
1184 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
1185 gap + ((hour - dayend - 1) * extratimeline ), extratimeline,
1186 year, month, day, hour
1189 if (time_format == WC_TIMEFORMAT_24) {
1190 wprintf("%2d:00</a> ", hour);
1193 wprintf("%d:00%s</a> ",
1194 (hour <= 12 ? hour : hour-12),
1195 (hour < 12 ? "am" : "pm")
1202 /* Display events with start and end times on this day */
1203 calendar_day_view_display_events(today_t, year, month, day, 0, daystart, dayend);
1206 wprintf("</td>"); /* end of innermost table */
1208 /** Display extra events (start/end times not present or not today) in the middle column */
1209 wprintf("<td class=\"extra_events\">");
1213 /** Display all-day events */
1214 calendar_day_view_display_events(today_t, year, month, day, 1, daystart, dayend);
1218 wprintf("</td>"); /** end extra on the middle */
1220 wprintf("<td width=20%% align=center valign=top>"); /** begin stuff-on-the-right */
1222 /** Begin todays-date-with-left-and-right-arrows */
1223 wprintf("<table border=0 width=100%% "
1224 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
1228 wprintf("<td align=center>");
1229 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
1230 yesterday.year, yesterday.month, yesterday.day);
1231 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
1234 wc_strftime(d_str, sizeof d_str,
1236 "<font size=+2>%B</font><br />"
1237 "<font size=+3>%d</font><br />"
1238 "<font size=+2>%Y</font><br />"
1242 wprintf("%s", d_str);
1245 wprintf("<td align=center>");
1246 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
1247 tomorrow.year, tomorrow.month, tomorrow.day);
1248 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
1249 " border=0></a>\n");
1252 wprintf("</tr></table>\n");
1253 /** End todays-date-with-left-and-right-arrows */
1255 /** Embed a mini month calendar in this space */
1256 wprintf("<br />\n");
1257 embeddable_mini_calendar(year, month, "readfwd?calview=day&year=%d&month=%d&day=%d");
1259 wprintf("</font></center>\n");
1261 wprintf("</td></tr>"); /** end stuff-on-the-right */
1263 wprintf("</table>" /** end of inner table */
1266 wprintf("<script type=\"text/javascript\">"
1267 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); "
1274 * \brief Display today's events.
1276 void calendar_summary_view(void) {
1283 struct icaltimetype t;
1288 int all_day_event = 0;
1289 char timestring[SIZ];
1290 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
1292 if (GetCount(WC->disp_cal_items) == 0) {
1297 localtime_r(&now, &today_tm);
1299 Pos = GetNewHashPos();
1300 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
1301 Cal = (disp_cal*)vCal;
1302 p = icalcomponent_get_first_property(Cal->cal,
1303 ICAL_DTSTART_PROPERTY);
1305 t = icalproperty_get_dtstart(p);
1306 event_tt = icaltime_as_timet(t);
1313 fmt_time(timestring, event_tt);
1315 if (all_day_event) {
1316 gmtime_r(&event_tt, &event_tm);
1319 localtime_r(&event_tt, &event_tm);
1322 if ( (event_tm.tm_year == today_tm.tm_year)
1323 && (event_tm.tm_mon == today_tm.tm_mon)
1324 && (event_tm.tm_mday == today_tm.tm_mday)
1328 p = icalcomponent_get_first_property(
1330 ICAL_SUMMARY_PROPERTY);
1333 icalproperty_get_comment(p));
1334 wprintf(" (%s)<br />\n", timestring);
1339 DeleteHashPos(&Pos);
1340 DeleteHash(&WC->disp_cal_items);
1345 * \brief do the whole calendar page
1346 * view any part of the calender. decide which way, etc.
1348 void do_calendar_view(void) {
1351 int year, month, day;
1354 /** In case no date was specified, go with today */
1356 localtime_r(&now, &tm);
1357 year = tm.tm_year + 1900;
1358 month = tm.tm_mon + 1;
1361 /** Now see if a date was specified */
1362 if (havebstr("year")) year = ibstr("year");
1363 if (havebstr("month")) month = ibstr("month");
1364 if (havebstr("day")) day = ibstr("day");
1366 /** How would you like that cooked? */
1367 if (havebstr("calview")) {
1368 strcpy(calview, bstr("calview"));
1371 strcpy(calview, "month");
1374 /** Display the selected view */
1375 if (!strcasecmp(calview, "day")) {
1376 calendar_day_view(year, month, day);
1378 else if (!strcasecmp(calview, "week")) {
1379 calendar_week_view(year, month, day);
1382 if (WC->wc_view == VIEW_CALBRIEF) {
1383 calendar_brief_month_view(year, month, day);
1386 calendar_month_view(year, month, day);
1390 /** Free the calendar stuff */
1391 DeleteHash(&WC->disp_cal_items);
1396 * \brief get task due date
1397 * Helper function for do_tasks_view().
1398 * \param vtodo a task to get the due date
1399 * \return the date/time due.
1401 time_t get_task_due_date(icalcomponent *vtodo) {
1404 if (vtodo == NULL) {
1409 * If we're looking at a fully encapsulated VCALENDAR
1410 * rather than a VTODO component, recurse into the data
1411 * structure until we get a VTODO.
1413 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1414 return get_task_due_date(
1415 icalcomponent_get_first_component(
1416 vtodo, ICAL_VTODO_COMPONENT
1421 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1423 return(icaltime_as_timet(icalproperty_get_due(p)));
1432 * \brief Compare the due dates of two tasks (this is for sorting)
1433 * \param task1 first task to compare
1434 * \param task2 second task to compare
1436 int task_due_cmp(const void *vtask1, const void *vtask2) {
1437 disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
1438 disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2);
1443 t1 = get_task_due_date(Task1->cal);
1444 t2 = get_task_due_date(Task2->cal);
1445 if (t1 < t2) return(-1);
1446 if (t1 > t2) return(1);
1451 * \brief qsort filter to move completed tasks to bottom of task list
1453 int task_completed_cmp(const void *vtask1, const void *vtask2) {
1454 disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
1455 // disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2);
1457 icalproperty_status t1 = icalcomponent_get_status((Task1)->cal);
1458 // icalproperty_status t2 = icalcomponent_get_status(((struct disp_cal *)task2)->cal);
1460 if (t1 == ICAL_STATUS_COMPLETED)
1468 * \brief do the whole task view stuff
1470 void do_tasks_view(void) {
1480 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
1482 wprintf("<div class=\"fix_scrollbar_bug\">"
1483 "<table class=\"calendar_view_background\"><tbody id=\"taskview\">\n<tr>\n"
1485 wprintf(_("Completed?"));
1486 wprintf("</th><th>");
1487 wprintf(_("Name of task"));
1488 wprintf("</th><th>");
1489 wprintf(_("Date due"));
1490 wprintf("</th><th>");
1491 wprintf(_("Category"));
1492 wprintf(" (<select id=\"selectcategory\"><option value=\"showall\">%s</option></select>)</th></tr>\n",
1495 nItems = GetCount(WC->disp_cal_items);
1496 /** Sort them if necessary * /
1498 SortByPayload(WC->disp_cal_items,
1500 } // this shouldn't be neccessary, since we sort by the start time.
1502 /** And then again, by completed */
1504 SortByPayload(WC->disp_cal_items,
1505 task_completed_cmp);
1508 Pos = GetNewHashPos();
1509 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
1510 Cal = (disp_cal*)vCal;
1511 wprintf("<tr><td>");
1512 icalproperty_status todoStatus = icalcomponent_get_status(Cal->cal);
1513 wprintf("<input type=\"checkbox\" name=\"completed\" value=\"completed\" ");
1514 if (todoStatus == ICAL_STATUS_COMPLETED) {
1515 wprintf("checked=\"checked\" ");
1517 wprintf("disabled=\"disabled\">\n</td><td>");
1518 p = icalcomponent_get_first_property(Cal->cal,
1519 ICAL_SUMMARY_PROPERTY);
1520 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1522 urlescputs(WC->wc_roomname);
1524 /* wprintf("<img align=middle "
1525 "src=\"static/taskmanag_16x.gif\" border=0> "); */
1527 escputs((char *)icalproperty_get_comment(p));
1532 due = get_task_due_date(Cal->cal);
1533 wprintf("<td><span");
1535 webcit_fmt_date(buf, due, 0);
1541 wprintf("</span></td>");
1543 p = icalcomponent_get_first_property(Cal->cal,
1544 ICAL_CATEGORIES_PROPERTY);
1546 escputs((char *)icalproperty_get_categories(p));
1552 wprintf("</tbody></table></div>\n");
1554 /** Free the list */
1555 DeleteHash(&WC->disp_cal_items);
1556 DeleteHashPos(&Pos);