2 * Handles the HTML display of calendar items.
4 * Copyright (c) 1996-2010 by the citadel.org team
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "webserver.h"
25 /* These define how high the hour rows are in the day view */
27 #define EXTRATIMELINE (TIMELINE / 2)
29 void embeddable_mini_calendar(int year, int month)
31 struct tm starting_tm;
35 time_t previous_month;
37 time_t colheader_time;
38 struct tm colheader_tm;
39 char colheader_label[32];
44 snprintf(div_id, sizeof div_id, "mini_calendar_%d", rand() );
46 /* Determine what day to start. If an impossible value is found, start on Sunday.
48 get_pref_long("weekstart", &weekstart, 17);
49 if (weekstart > 6) weekstart = 0;
52 * Now back up to the 1st of the month...
54 memset(&starting_tm, 0, sizeof(struct tm));
56 starting_tm.tm_year = year - 1900;
57 starting_tm.tm_mon = month - 1;
58 starting_tm.tm_mday = 1;
59 thetime = mktime(&starting_tm);
61 memcpy(&tm, &starting_tm, sizeof(struct tm));
62 while (tm.tm_mday != 1) {
63 thetime = thetime - (time_t)86400; /* go back 24 hours */
64 localtime_r(&thetime, &tm);
67 /* Determine previous and next months ... for links */
68 previous_month = thetime - (time_t)864000L; /* back 10 days */
69 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
71 /* Now back up until we're on the user's preferred start day */
72 localtime_r(&thetime, &tm);
73 while (tm.tm_wday != weekstart) {
74 thetime = thetime - (time_t)86400; /* go back 24 hours */
75 localtime_r(&thetime, &tm);
78 wc_printf("<div class=\"mini_calendar\" id=\"%s\">\n", div_id);
80 /* Previous month link */
81 localtime_r(&previous_month, &tm);
82 wc_printf("<a href=\"javascript:minical_change_month(%d,%d);\">«</a>",
83 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
85 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
86 wc_printf(" "
87 "<span class=\"mini_calendar_month_label\">"
90 " ", colheader_label, year);
93 localtime_r(&next_month, &tm);
94 wc_printf("<a href=\"javascript:minical_change_month(%d,%d);\">»</a>",
95 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
97 wc_printf("<table border=\"0\" cellpadding=\"1\" cellspacing=\"1\" class=\"mini_calendar_days\">"
99 colheader_time = thetime;
100 for (i=0; i<7; ++i) {
101 colheader_time = thetime + (i * 86400) ;
102 localtime_r(&colheader_time, &colheader_tm);
103 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
104 wc_printf("<th>%c</th>", colheader_label[0]);
107 wc_printf("</tr>\n");
110 /* Now do 35 or 42 days */
111 for (i = 0; i < 42; ++i) {
112 localtime_r(&thetime, &tm);
116 /* Before displaying Sunday, start a new row */
121 if (tm.tm_mon == month-1) {
122 snprintf(url, sizeof url, "readfwd?calview=day?year=%d?month=%d?day=%d",
123 tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday);
124 wc_printf("<td><a href=\"%s\">%d</a></td>", url, tm.tm_mday);
127 wc_printf("<td> </td>");
130 /* After displaying one week, end the row */
132 wc_printf("</tr>\n");
137 thetime += (time_t)86400; /* ahead 24 hours */
140 wc_printf("</table>" /* end of inner table */
143 StrBufAppendPrintf(WC->trailing_javascript,
144 " function minical_change_month(year, month) { \n"
145 " p = 'year=' + year + '&month=' + month \n"
146 " + '&r=' + CtdlRandomString(); \n"
147 " new Ajax.Updater('%s', 'mini_calendar', \n"
148 " { method: 'get', parameters: p, evalScripts: true } ); \n"
157 * ajax embedder for the above mini calendar
159 void ajax_mini_calendar(void)
161 embeddable_mini_calendar( ibstr("year"), ibstr("month"));
166 * Display one day of a whole month view of a calendar
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 icaltimetype today_t;
182 struct tm starting_tm;
184 int all_day_event = 0;
190 if (GetCount(WCC->disp_cal_items) == 0) {
191 wc_printf("<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 * Create another one without caring about the timezone for all day events.
221 today_t = icaltime_null_date();
223 today_t.month = month;
227 * Now loop through our list of events to see which ones occur today.
229 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
230 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
231 Cal = (disp_cal*)vCal;
233 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
235 t = icalproperty_get_dtstart(q);
238 memset(&t, 0, sizeof t);
240 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
242 end_t = icalproperty_get_dtend(q);
245 memset(&end_t, 0, sizeof end_t);
247 if (t.is_date) all_day_event = 1;
251 show_event = ical_ctdl_is_overlap(t, end_t, today_t, icaltime_null_time());
255 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
259 * If we determined that this event occurs today, then display it.
262 p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
264 p = icalproperty_new_summary(_("Untitled Event"));
265 icalcomponent_add_property(Cal->cal, p);
270 wc_printf("<table border=\"0\" cellpadding=\"2\"><TR>"
271 "<td bgcolor=\"#CCCCDD\">"
276 wc_printf("<font size=\"-1\">"
277 "<a class=\"event%s\" href=\"display_edit_event?"
278 "msgnum=%ld?calview=month?year=%d?month=%d?day=%d\">"
280 (Cal->unread)?"_unread":"_read",
285 escputs((char *) icalproperty_get_comment(p));
287 wc_printf("<span class=\"tooltip\"><span class=\"btttop\"></span><span class=\"bttmiddle\">");
289 wc_printf("<i>%s: %s</i><br />", _("From"), Cal->from);
290 wc_printf("<i>%s</i> ", _("Summary:"));
291 escputs((char *)icalproperty_get_comment(p));
294 q = icalcomponent_get_first_property(
296 ICAL_LOCATION_PROPERTY);
298 wc_printf("<i>%s</i> ", _("Location:"));
299 escputs((char *)icalproperty_get_comment(q));
304 * Only show start/end times if we're actually looking at the VEVENT
305 * component. Otherwise it shows bogus dates for e.g. timezones
307 if (icalcomponent_isa(Cal->cal) == ICAL_VEVENT_COMPONENT) {
309 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
313 t = icalproperty_get_dtstart(q);
314 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
316 end_t = icalproperty_get_dtend(q);
320 * events with starting date/time equal
321 * ending date/time might get only
322 * DTSTART but no DTEND
332 /* end given, have to adjust it */
333 icaltime_adjust(&end_t, -1, 0, 0, 0);
335 memset(&d_tm, 0, sizeof d_tm);
336 d_tm.tm_year = t.year - 1900;
337 d_tm.tm_mon = t.month - 1;
338 d_tm.tm_mday = t.day;
339 wc_strftime(buf, sizeof buf, "%x", &d_tm);
341 if (no_end || !icaltime_compare(t, end_t)) {
342 wc_printf("<i>%s</i> %s<br>",
346 wc_printf("<i>%s</i> %s<br>",
347 _("Starting date:"), buf);
348 d_tm.tm_year = end_t.year - 1900;
349 d_tm.tm_mon = end_t.month - 1;
350 d_tm.tm_mday = end_t.day;
351 wc_strftime(buf, sizeof buf, "%x", &d_tm);
352 wc_printf("<i>%s</i> %s<br>",
353 _("Ending date:"), buf);
357 tt = icaltime_as_timet(t);
358 webcit_fmt_date(buf, 256, tt, DATEFMT_BRIEF);
359 if (no_end || !icaltime_compare(t, end_t)) {
360 wc_printf("<i>%s</i> %s<br>",
361 _("Date/time:"), buf);
364 wc_printf("<i>%s</i> %s<br>",
365 _("Starting date/time:"), buf);
366 tt = icaltime_as_timet(end_t);
367 webcit_fmt_date(buf, 256, tt, DATEFMT_BRIEF);
368 wc_printf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
376 q = icalcomponent_get_first_property(Cal->cal, ICAL_DESCRIPTION_PROPERTY);
378 wc_printf("<i>%s</i> ", _("Notes:"));
379 escputs((char *)icalproperty_get_comment(q));
383 wc_printf("</span><span class=\"bttbottom\"></span></span>");
384 wc_printf("</a></font><br />\n");
387 wc_printf("</td></tr></table>");
401 * Display one day of a whole month view of a calendar
403 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
417 struct icaltimetype t;
419 int month, day, year;
420 int all_day_event = 0;
424 time_format = get_time_format_cached ();
426 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
427 else timeformat="%I:%M %p";
429 localtime_r(&thetime, &today_tm);
430 month = today_tm.tm_mon + 1;
431 day = today_tm.tm_mday;
432 year = today_tm.tm_year + 1900;
434 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
435 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
436 Cal = (disp_cal*)vCal;
437 p = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
439 t = icalproperty_get_dtstart(p);
440 event_tt = icaltime_as_timet(t);
442 if (t.is_date) all_day_event = 1;
443 else all_day_event = 0;
446 gmtime_r(&event_tts, &event_tms);
449 localtime_r(&event_tts, &event_tms);
451 /* \todo epoch &! daymask */
452 if ((event_tms.tm_year == today_tm.tm_year)
453 && (event_tms.tm_mon == today_tm.tm_mon)
454 && (event_tms.tm_mday == today_tm.tm_mday)) {
460 p = icalcomponent_get_first_property(
462 ICAL_SUMMARY_PROPERTY);
464 p = icalproperty_new_summary(_("Untitled Event"));
465 icalcomponent_add_property(Cal->cal, p);
467 e = icalcomponent_get_first_property(
469 ICAL_DTEND_PROPERTY);
470 if ((p != NULL) && (e != NULL)) {
473 t = icalproperty_get_dtend(e);
474 event_tte = icaltime_as_timet(t);
475 localtime_r(&event_tte, &event_tme);
476 difftime=(event_tte-event_tts)/60;
477 hours=(int)(difftime / 60);
478 minutes=difftime % 60;
479 wc_printf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
481 "<a class=\"event%s\" href=\"display_edit_event?msgnum=%ld?calview=calbrief?year=%s?month=%s?day=%s\">",
484 (Cal->unread)?"_unread":"_read",
493 icalproperty_get_comment(p));
494 /* \todo: allso ammitime format */
495 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
496 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
498 wc_printf("</a></font></td>"
499 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
516 * view one month. pretty view
518 void calendar_month_view(int year, int month, int day) {
519 struct tm starting_tm;
524 time_t previous_month;
526 time_t colheader_time;
528 struct tm colheader_tm;
529 char colheader_label[32];
533 * Make sure we know which day is today.
535 today_timet = time(NULL);
536 localtime_r(&today_timet, &today_tm);
539 * Determine what day to start. If an impossible value is found, start on Sunday.
541 get_pref_long("weekstart", &weekstart, 17);
542 if (weekstart > 6) weekstart = 0;
545 * Now back up to the 1st of the month...
547 memset(&starting_tm, 0, sizeof(struct tm));
549 starting_tm.tm_year = year - 1900;
550 starting_tm.tm_mon = month - 1;
551 starting_tm.tm_mday = day;
552 thetime = mktime(&starting_tm);
554 memcpy(&tm, &starting_tm, sizeof(struct tm));
555 while (tm.tm_mday != 1) {
556 thetime = thetime - (time_t)86400; /* go back 24 hours */
557 localtime_r(&thetime, &tm);
560 /* Determine previous and next months ... for links */
561 previous_month = thetime - (time_t)864000L; /* back 10 days */
562 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
564 /* Now back up until we're on the user's preferred start day */
565 localtime_r(&thetime, &tm);
566 while (tm.tm_wday != weekstart) {
567 thetime = thetime - (time_t)86400; /* go back 24 hours */
568 localtime_r(&thetime, &tm);
571 /* Outer table (to get the background color) */
572 wc_printf("<table class=\"calendar\"> \n <tr><td>");
574 wc_printf("<table width=\"100%%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>\n");
576 wc_printf("<td align=\"center\">");
578 localtime_r(&previous_month, &tm);
579 wc_printf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
580 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
581 wc_printf("<img alt=\"%s\" align=\"middle\" src=\"static/prevdate_32x.gif\" border=\"0\"></a>\n", _("previous"));
583 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
584 wc_printf(" "
585 "<font size=\"+1\" color=\"#FFFFFF\">"
588 " ", colheader_label, year);
590 localtime_r(&next_month, &tm);
591 wc_printf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
592 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
593 wc_printf("<img alt=\"%s\" align=\"middle\" src=\"static/nextdate_32x.gif\" border=\"0\"></A>\n", _("next"));
595 wc_printf("</td></tr></table>\n");
597 /* Inner table (the real one) */
598 wc_printf("<table width=\"100%%\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" "
599 "bgcolor='#204B78' id=\"inner_month\"><tr>");
600 wc_printf("<th align=\"center\" width=\"2%%\"></th>");
601 colheader_time = thetime;
602 for (i=0; i<7; ++i) {
603 colheader_time = thetime + (i * 86400) ;
604 localtime_r(&colheader_time, &colheader_tm);
605 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
606 wc_printf("<th align=\"center\" width=\"14%%\">"
607 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
610 wc_printf("</tr>\n");
613 /* Now do 35 or 42 days */
614 localtime_r(&thetime, &tm);
615 for (i = 0; i<42; ++i) {
617 /* Before displaying the first day of the week, start a new row */
619 wc_printf("<tr><td class=\"week_of_year\">");
620 wc_strftime(colheader_label, sizeof colheader_label, "%V", &tm);
621 wc_printf("%s ", colheader_label);
624 wc_printf("<td class=\"cal%s\"><div class=\"day\">",
625 ((tm.tm_mon != month-1) ? "out" :
626 (((tm.tm_year == today_tm.tm_year) && (tm.tm_mon == today_tm.tm_mon) && (tm.tm_mday == today_tm.tm_mday)) ? "today" :
627 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
630 if ((i==0) || (tm.tm_mday == 1)) {
631 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
632 wc_printf("%s ", colheader_label);
634 wc_printf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">"
641 /* put the data here, stupid */
642 calendar_month_view_display_events(
650 /* After displaying the last day of the week, end the row */
652 wc_printf("</tr>\n");
655 thetime += (time_t)86400; /* ahead 24 hours */
656 localtime_r(&thetime, &tm);
658 if ( ((i % 7) == 6) && (tm.tm_mon != month-1) && (tm.tm_mday < 15) ) {
659 i = 100; /* break out of the loop */
663 wc_printf("</table>" /* end of inner table */
664 "</td></tr></table>\n" /* end of outer table */
669 * view one month. brief view
671 void calendar_brief_month_view(int year, int month, int day) {
672 struct tm starting_tm;
676 time_t previous_month;
678 char month_label[32];
680 /* Determine what day to start.
681 * First, back up to the 1st of the month...
683 memset(&starting_tm, 0, sizeof(struct tm));
684 starting_tm.tm_year = year - 1900;
685 starting_tm.tm_mon = month - 1;
686 starting_tm.tm_mday = day;
687 thetime = mktime(&starting_tm);
689 memcpy(&tm, &starting_tm, sizeof(struct tm));
690 while (tm.tm_mday != 1) {
691 thetime = thetime - (time_t)86400; /* go back 24 hours */
692 localtime_r(&thetime, &tm);
695 /* Determine previous and next months ... for links */
696 previous_month = thetime - (time_t)864000L; /* back 10 days */
697 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
699 /* Now back up until we're on a Sunday */
700 localtime_r(&thetime, &tm);
701 while (tm.tm_wday != 0) {
702 thetime = thetime - (time_t)86400; /* go back 24 hours */
703 localtime_r(&thetime, &tm);
706 /* Outer table (to get the background color) */
707 wc_printf("<table width=\"100%%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" "
708 "bgcolor=#204B78><tr><td>\n");
710 wc_printf("<table width=\"100%%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>\n");
712 wc_printf("<td align=\"center\">");
714 localtime_r(&previous_month, &tm);
715 wc_printf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
716 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
717 wc_printf("<img alt=\"%s\" align=\"middle\" src=\"static/prevdate_32x.gif\" border=\"0\"></a>\n", _("previous"));
719 wc_strftime(month_label, sizeof month_label, "%B", &tm);
720 wc_printf(" "
721 "<font size=\"+1\" color=\"#FFFFFF\">"
724 " ", month_label, year);
726 localtime_r(&next_month, &tm);
727 wc_printf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
728 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
729 wc_printf("<img alt=\"%s\" align=\"middle\" src=\"static/nextdate_32x.gif\" border=\"0\"></a>\n", _("next"));
731 wc_printf("</td></tr></table>\n");
733 /* Inner table (the real one) */
734 wc_printf("<table width=\"100%%\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" "
735 "bgcolor=#EEEECC><TR>");
736 wc_printf("</tr>\n");
737 wc_printf("<tr><td colspan=\"100%%\">\n");
740 for (i = 0; i < 35; ++i) {
741 char weeknumber[255];
742 char weekday_name[32];
744 localtime_r(&thetime, &tm);
747 /* Before displaying Sunday, start a new CELL */
749 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
750 wc_printf("<table border='0' bgcolor=\"#EEEECC\" width='100%%'> <tr><th colspan='4'>%s %s</th></tr>"
751 " <tr><td>%s</td><td width='70%%'>%s</td><td>%s</td><td>%s</td></tr>\n",
761 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
762 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
766 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
767 wc_printf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
768 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
770 weekday_name,tm.tm_mday,
773 /* put the data of one day here, stupid */
774 calendar_month_view_brief_events(thetime, daycolor);
777 /* After displaying Saturday, end the row */
779 wc_printf("</td></tr></table>\n");
782 thetime += (time_t)86400; /* ahead 24 hours */
785 wc_printf("</table>" /* end of inner table */
786 "</td></tr></table>\n" /* end of outer table */
791 * Calendar week view -- not implemented yet, this is a stub function
793 void calendar_week_view(int year, int month, int day) {
794 wc_printf("<center><i>week view FIXME</i></center><br />\n");
800 * Display events for a particular hour of a particular day.
801 * (Specify hour < 0 to show "all day" events)
803 * dstart and dend indicate which hours our "daytime" begins and end
805 void calendar_day_view_display_events(time_t thetime,
817 icalproperty *p = NULL;
818 icalproperty *q = NULL;
824 int all_day_event = 0;
825 int ongoing_event = 0;
828 struct icaltimetype t;
829 struct icaltimetype end_t;
830 struct icaltimetype today_start_t;
831 struct icaltimetype today_end_t;
832 struct icaltimetype today_t;
833 struct tm starting_tm;
844 if (GetCount(WCC->disp_cal_items) == 0) {
845 /* nothing to display */
849 /* Create an imaginary event which spans the current day. Any events which
850 * overlap with this one take place at least partially in this day.
852 memset(&starting_tm, 0, sizeof(struct tm));
853 starting_tm.tm_year = year - 1900;
854 starting_tm.tm_mon = month - 1;
855 starting_tm.tm_mday = day;
856 starting_tm.tm_hour = 0;
857 starting_tm.tm_min = 0;
858 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
859 today_start_t.is_utc = 1;
861 memset(&ending_tm, 0, sizeof(struct tm));
862 ending_tm.tm_year = year - 1900;
863 ending_tm.tm_mon = month - 1;
864 ending_tm.tm_mday = day;
865 ending_tm.tm_hour = 23;
866 ending_tm.tm_min = 59;
867 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
868 today_end_t.is_utc = 1;
871 * Create another one without caring about the timezone for all day events.
873 today_t = icaltime_null_date();
875 today_t.month = month;
878 /* Now loop through our list of events to see which ones occur today.
880 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
881 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
882 Cal = (disp_cal*)vCal;
887 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
889 t = icalproperty_get_dtstart(q);
890 event_tt = icaltime_as_timet(t);
891 localtime_r(&event_tt, &event_te);
894 memset(&t, 0, sizeof t);
897 if (t.is_date) all_day_event = 1;
899 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
901 end_t = icalproperty_get_dtend(q);
904 /* no end given means end = start */
905 memcpy(&end_t, &t, sizeof(struct icaltimetype));
910 show_event = ical_ctdl_is_overlap(t, end_t, today_t, icaltime_null_time());
911 if (icaltime_compare(t, end_t)) {
913 * the end date is non-inclusive so adjust it by one
914 * day because our test is inclusive, note that a day is
915 * not to much because we are talking about all day
918 icaltime_adjust(&end_t, -1, 0, 0, 0);
923 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
926 event_tte = icaltime_as_timet(end_t);
927 localtime_r(&event_tte, &event_tm);
929 /* If we determined that this event occurs today, then display it.
931 p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
933 p = icalproperty_new_summary(_("Untitled Event"));
934 icalcomponent_add_property(Cal->cal, p);
937 if ((show_event) && (p != NULL)) {
939 if ((event_te.tm_mday != day) || (event_tm.tm_mday != day)) ongoing_event = 1;
941 if (all_day_event && notime_events)
943 wc_printf("<li class=\"event_framed%s\"> "
944 "<a href=\"display_edit_event?"
945 "msgnum=%ld?calview=day?year=%d?month=%d?day=%d\" "
946 " class=\"event_title\">"
948 (Cal->unread)?"_unread":"_read",
949 Cal->cal_msgnum, year, month, day
951 escputs((char *) icalproperty_get_comment(p));
952 wc_printf("<span class=\"tooltip\"><span class=\"btttop\"></span><span class=\"bttmiddle\">");
953 wc_printf("<i>%s</i><br />", _("All day event"));
954 wc_printf("<i>%s: %s</i><br />", _("From"), Cal->from);
955 wc_printf("<i>%s</i> ", _("Summary:"));
956 escputs((char *) icalproperty_get_comment(p));
958 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
960 wc_printf("<i>%s</i> ", _("Location:"));
961 escputs((char *)icalproperty_get_comment(q));
964 if (!icaltime_compare(t, end_t)) { /* one day only */
965 webcit_fmt_date(buf, 256, event_tt, DATEFMT_LOCALEDATE);
966 wc_printf("<i>%s</i> %s<br>", _("Date:"), buf);
969 webcit_fmt_date(buf, 256, event_tt, DATEFMT_LOCALEDATE);
970 wc_printf("<i>%s</i> %s<br>", _("Starting date:"), buf);
971 webcit_fmt_date(buf, 256, event_tte, DATEFMT_LOCALEDATE);
972 wc_printf("<i>%s</i> %s<br>", _("Ending date:"), buf);
974 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
976 wc_printf("<i>%s</i> ", _("Notes:"));
977 escputs((char *)icalproperty_get_comment(q));
980 wc_printf("</span><span class=\"bttbottom\"></span></span>");
981 wc_printf("</a> <span>(");
982 wc_printf(_("All day event"));
983 wc_printf(")</span></li>\n");
985 else if (ongoing_event && notime_events)
987 wc_printf("<li class=\"event_framed%s\"> "
988 "<a href=\"display_edit_event?"
989 "msgnum=%ld&calview=day?year=%d?month=%d?day=%d\" "
990 " class=\"event_title\">"
992 (Cal->unread)?"_unread":"_read",
993 Cal->cal_msgnum, year, month, day
995 escputs((char *) icalproperty_get_comment(p));
996 wc_printf("<span class=\"tooltip\"><span class=\"btttop\"></span><span class=\"bttmiddle\">");
997 wc_printf("<i>%s</i><br />", _("Ongoing event"));
998 wc_printf("<i>%s: %s</i><br />", _("From"), Cal->from);
999 wc_printf("<i>%s</i> ", _("Summary:"));
1000 escputs((char *) icalproperty_get_comment(p));
1001 wc_printf("<br />");
1002 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
1004 wc_printf("<i>%s</i> ", _("Location:"));
1005 escputs((char *)icalproperty_get_comment(q));
1006 wc_printf("<br />");
1008 webcit_fmt_date(buf, 256, event_tt, DATEFMT_BRIEF);
1009 wc_printf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
1010 webcit_fmt_date(buf, 256, event_tte, DATEFMT_BRIEF);
1011 wc_printf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
1012 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
1014 wc_printf("<i>%s</i> ", _("Notes:"));
1015 escputs((char *)icalproperty_get_comment(q));
1016 wc_printf("<br />");
1018 wc_printf("</span><span class=\"bttbottom\"></span></span>");
1019 wc_printf("</a> <span>(");
1020 wc_printf(_("Ongoing event"));
1021 wc_printf(")</span></li>\n");
1023 else if (!all_day_event && !notime_events)
1027 if (event_te.tm_mday != day) event_te.tm_hour = 0;
1028 if (event_tm.tm_mday != day) event_tm.tm_hour = 24;
1030 /* Calculate the location of the top of the box */
1031 if (event_te.tm_hour < dstart) {
1032 startmin = diffmin = event_te.tm_min / 6;
1033 top = (event_te.tm_hour * EXTRATIMELINE) + startmin;
1035 else if ((event_te.tm_hour >= dstart) && (event_te.tm_hour <= dend)) {
1036 startmin = diffmin = (event_te.tm_min / 2);
1037 top = (dstart * EXTRATIMELINE) + ((event_te.tm_hour - dstart) * TIMELINE) + startmin;
1039 else if (event_te.tm_hour >dend) {
1040 startmin = diffmin = event_te.tm_min / 6;
1041 top = (dstart * EXTRATIMELINE) + ((dend - dstart - 1) * TIMELINE) + ((event_tm.tm_hour - dend + 1) * EXTRATIMELINE) + startmin ;
1044 /* should never get here */
1047 /* Calculate the location of the bottom of the box */
1048 if (event_tm.tm_hour < dstart) {
1049 endmin = diffmin = event_tm.tm_min / 6;
1050 bottom = (event_tm.tm_hour * EXTRATIMELINE) + endmin;
1052 else if ((event_tm.tm_hour >= dstart) && (event_tm.tm_hour <= dend)) {
1053 endmin = diffmin = (event_tm.tm_min / 2);
1054 bottom = (dstart * EXTRATIMELINE) + ((event_tm.tm_hour - dstart) * TIMELINE) + endmin ;
1056 else if (event_tm.tm_hour >dend) {
1057 endmin = diffmin = event_tm.tm_min / 6;
1058 bottom = (dstart * EXTRATIMELINE) + ((dend - dstart + 1) * TIMELINE) + ((event_tm.tm_hour - dend - 1) * EXTRATIMELINE) + endmin;
1061 /* should never get here */
1064 wc_printf("<dd class=\"event_framed%s\" "
1065 "style=\"position: absolute; "
1066 "top:%dpx; left:%dpx; "
1067 "height:%dpx; \" >",
1068 (Cal->unread)?"_unread":"_read",
1069 top, (gap * 40), (bottom-top)
1071 wc_printf("<a href=\"display_edit_event?"
1072 "msgnum=%ld?calview=day?year=%d?month=%d?day=%d?hour=%d\" "
1073 "class=\"event_title\">"
1075 Cal->cal_msgnum, year, month, day, t.hour
1077 escputs((char *) icalproperty_get_comment(p));
1078 wc_printf("<span class=\"tooltip\"><span class=\"btttop\"></span><span class=\"bttmiddle\">");
1079 wc_printf("<i>%s: %s</i><br />", _("From"), Cal->from);
1080 wc_printf("<i>%s</i> ", _("Summary:"));
1081 escputs((char *) icalproperty_get_comment(p));
1082 wc_printf("<br />");
1083 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
1085 wc_printf("<i>%s</i> ", _("Location:"));
1086 escputs((char *)icalproperty_get_comment(q));
1087 wc_printf("<br />");
1089 if (!icaltime_compare(t, end_t)) { /* one day only */
1090 webcit_fmt_date(buf, 256, event_tt, DATEFMT_BRIEF);
1091 wc_printf("<i>%s</i> %s<br>", _("Date/time:"), buf);
1094 webcit_fmt_date(buf, 256, event_tt, DATEFMT_BRIEF);
1095 wc_printf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
1096 webcit_fmt_date(buf, 256, event_tte, DATEFMT_BRIEF);
1097 wc_printf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
1099 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
1101 wc_printf("<i>%s</i> ", _("Notes:"));
1102 escputs((char *)icalproperty_get_comment(q));
1103 wc_printf("<br />");
1105 wc_printf("</span><span class=\"bttbottom\"></span></span>");
1106 wc_printf("</a></dd>\n");
1110 DeleteHashPos(&Pos);
1116 void calendar_day_view(int year, int month, int day) {
1118 struct icaltimetype today, yesterday, tomorrow;
1125 int timeline = TIMELINE;
1126 int extratimeline = EXTRATIMELINE;
1131 time_format = get_time_format_cached ();
1132 get_pref_long("daystart", &daystart, 8);
1133 get_pref_long("dayend", &dayend, 17);
1135 /* when loading daystart/dayend, replace missing, corrupt, or impossible values with defaults */
1136 if ((daystart < 0) || (dayend < 2) || (daystart >= 23) || (dayend > 23) || (dayend <= daystart)) {
1142 memset(&d_tm, 0, sizeof d_tm);
1143 d_tm.tm_year = year - 1900;
1144 d_tm.tm_mon = month - 1;
1146 today_t = mktime(&d_tm);
1148 /* Figure out the dates for "yesterday" and "tomorrow" links */
1150 memset(&today, 0, sizeof(struct icaltimetype));
1152 today.month = month;
1156 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
1158 yesterday = icaltime_normalize(yesterday);
1160 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
1162 tomorrow = icaltime_normalize(tomorrow);
1164 /* Inner table (the real one) */
1165 wc_printf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
1167 /* Innermost cell (contains hours etc.) */
1168 wc_printf("<td class=\"events_of_the_day\" >");
1169 wc_printf("<dl class=\"events\" >");
1171 /* Now the middle of the day... */
1173 extrahourlabel = extratimeline - 2;
1174 hourlabel = extrahourlabel * 150 / 100;
1175 if (hourlabel > (timeline - 2)) hourlabel = timeline - 2;
1177 for (hour = 0; hour < daystart; ++hour) { /* could do HEIGHT=xx */
1178 wc_printf("<dt class=\"extrahour\" "
1180 "position: absolute; "
1181 "top: %dpx; left: 0px; "
1185 "<a href=\"display_edit_event?msgnum=0"
1186 "?calview=day?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
1187 (hour * extratimeline ),
1190 year, month, day, hour
1193 if (time_format == WC_TIMEFORMAT_24) {
1194 wc_printf("%2d:00</a> ", hour);
1197 wc_printf("%d:00%s</a> ",
1198 ((hour == 0) ? 12 : (hour <= 12 ? hour : hour-12)),
1199 (hour < 12 ? "am" : "pm")
1206 gap = daystart * extratimeline;
1208 for (hour = daystart; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
1209 wc_printf("<dt class=\"hour\" "
1211 "position: absolute; "
1212 "top: %ldpx; left: 0px; "
1216 "<a href=\"display_edit_event?msgnum=0?calview=day"
1217 "?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
1218 gap + ((hour - daystart) * timeline ),
1221 year, month, day, hour
1224 if (time_format == WC_TIMEFORMAT_24) {
1225 wc_printf("%2d:00</a> ", hour);
1228 wc_printf("%d:00%s</a> ",
1229 (hour <= 12 ? hour : hour-12),
1230 (hour < 12 ? "am" : "pm")
1237 gap = gap + ((dayend - daystart + 1) * timeline);
1239 for (hour = (dayend + 1); hour < 24; ++hour) { /* could do HEIGHT=xx */
1240 wc_printf("<dt class=\"extrahour\" "
1242 "position: absolute; "
1243 "top: %ldpx; left: 0px; "
1247 "<a href=\"display_edit_event?msgnum=0?calview=day"
1248 "?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
1249 gap + ((hour - dayend - 1) * extratimeline ),
1252 year, month, day, hour
1255 if (time_format == WC_TIMEFORMAT_24) {
1256 wc_printf("%2d:00</a> ", hour);
1259 wc_printf("%d:00%s</a> ",
1260 (hour <= 12 ? hour : hour-12),
1261 (hour < 12 ? "am" : "pm")
1268 /* Display events with start and end times on this day */
1269 calendar_day_view_display_events(today_t, year, month, day, 0, daystart, dayend);
1272 wc_printf("</td>"); /* end of innermost table */
1274 /* Display extra events (start/end times not present or not today) in the middle column */
1275 wc_printf("<td class=\"extra_events\">");
1279 /* Display all-day events */
1280 calendar_day_view_display_events(today_t, year, month, day, 1, daystart, dayend);
1284 wc_printf("</td>"); /* end extra on the middle */
1286 wc_printf("<td width='20%%' align=\"center\" valign=top>"); /* begin stuff-on-the-right */
1288 /* Begin todays-date-with-left-and-right-arrows */
1289 wc_printf("<table border=\"0\" width=\"100%%\" "
1290 "cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#FFFFFF\">\n");
1294 wc_printf("<td align=\"center\">");
1295 wc_printf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">",
1296 yesterday.year, yesterday.month, yesterday.day);
1297 wc_printf("<img alt=\"previous\" align=\"middle\" src=\"static/prevdate_32x.gif\" border=\"0\"></a>");
1300 wc_strftime(d_str, sizeof d_str,
1301 "<td align=\"center\">"
1302 "<font size='+2'>%A</font><br />"
1303 "<font size='+2'>%B</font><br />"
1304 "<font size='+3'>%d</font><br />"
1305 "<font size='+2'>%Y</font><br />"
1309 wc_printf("%s", d_str);
1312 wc_printf("<td align=\"center\">");
1313 wc_printf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">",
1314 tomorrow.year, tomorrow.month, tomorrow.day);
1315 wc_printf("<img alt=\"%s\" align=\"middle\" src=\"static/nextdate_32x.gif\""
1316 " border=\"0\"></a>\n", _("next"));
1319 wc_printf("</tr></table>\n");
1320 /* End todays-date-with-left-and-right-arrows */
1322 /* Embed a mini month calendar in this space */
1323 wc_printf("<br />\n");
1324 embeddable_mini_calendar(year, month);
1326 wc_printf("</td></tr>"); /* end stuff-on-the-right */
1327 wc_printf("</table>\n"); /* end of inner table */
1332 * Display today's events. Returns the number of items displayed.
1334 int calendar_summary_view(void) {
1336 const char *HashKey;
1341 struct icaltimetype t;
1346 int all_day_event = 0;
1347 char timestring[SIZ];
1348 wcsession *WCC = WC;
1349 int num_displayed = 0;
1351 if (GetCount(WC->disp_cal_items) == 0) {
1356 localtime_r(&now, &today_tm);
1358 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
1359 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
1360 Cal = (disp_cal*)vCal;
1361 p = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
1363 t = icalproperty_get_dtstart(p);
1364 event_tt = icaltime_as_timet(t);
1371 fmt_time(timestring, SIZ, event_tt);
1373 if (all_day_event) {
1374 gmtime_r(&event_tt, &event_tm);
1377 localtime_r(&event_tt, &event_tm);
1380 if ( (event_tm.tm_year == today_tm.tm_year)
1381 && (event_tm.tm_mon == today_tm.tm_mon)
1382 && (event_tm.tm_mday == today_tm.tm_mday)
1385 p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
1387 p = icalproperty_new_summary(_("Untitled Task"));
1388 icalcomponent_add_property(Cal->cal, p);
1392 if (WCC->CurRoom.view == VIEW_TASKS) {
1393 wc_printf("<a href=\"display_edit_task"
1395 "?return_to_summary=1"
1399 escputs(ChrPtr(WCC->CurRoom.name));
1403 wc_printf("<a href=\"display_edit_event"
1411 today_tm.tm_year + 1900,
1412 today_tm.tm_mon + 1,
1415 escputs(ChrPtr(WCC->CurRoom.name));
1418 escputs((char *) icalproperty_get_comment(p));
1419 if (!all_day_event) {
1420 wc_printf(" (%s)", timestring);
1422 wc_printf("</a><br />\n");
1428 DeleteHashPos(&Pos);
1429 DeleteHash(&WC->disp_cal_items);
1430 return(num_displayed);
1434 * Parse the URL variables in order to determine the scope and display of a calendar view
1436 int calendar_GetParamsGetServerCall(SharedMessageStatus *Stat,
1437 void **ViewSpecific,
1442 wcsession *WCC = WC;
1450 c = (calview*) malloc(sizeof(calview));
1451 memset(c, 0, sizeof(calview));
1452 *ViewSpecific = (void*)c;
1454 Stat->load_seen = 1;
1455 strcpy(cmd, "MSGS ALL");
1456 Stat->maxmsgs = 32767;
1458 /* In case no date was specified, go with today */
1460 localtime_r(&now, &tm);
1461 c->year = tm.tm_year + 1900;
1462 c->month = tm.tm_mon + 1;
1463 c->day = tm.tm_mday;
1465 /* Now see if a date was specified */
1466 if (havebstr("year")) c->year = ibstr("year");
1467 if (havebstr("month")) c->month = ibstr("month");
1468 if (havebstr("day")) c->day = ibstr("day");
1470 /* How would you like that cooked? */
1471 if (havebstr("calview")) {
1472 strcpy(cv, bstr("calview"));
1475 strcpy(cv, "month");
1478 /* Display the selected view */
1479 if (!strcasecmp(cv, "day")) {
1480 c->view = calview_day;
1482 else if (!strcasecmp(cv, "week")) {
1483 c->view = calview_week;
1485 else if (!strcasecmp(cv, "summary")) { /* shouldn't ever happen, but just in case */
1486 c->view = calview_day;
1489 if (WCC->CurRoom.view == VIEW_CALBRIEF) {
1490 c->view = calview_brief;
1493 c->view = calview_month;
1497 /* Now try and set the lower and upper bounds so that we don't
1498 * burn too many cpu cycles parsing data way in the past or future
1501 tm.tm_year = c->year - 1900;
1502 tm.tm_mon = c->month - 1;
1503 tm.tm_mday = c->day;
1506 if (c->view == calview_month) span = 3888000;
1507 if (c->view == calview_brief) span = 3888000;
1508 if (c->view == calview_week) span = 604800;
1509 if (c->view == calview_day) span = 86400;
1510 if (c->view == calview_summary) span = 86400;
1512 c->lower_bound = now - span;
1513 c->upper_bound = now + span;
1520 * Render a calendar view from data previously loaded into memory
1522 int calendar_RenderView_or_Tail(SharedMessageStatus *Stat,
1523 void **ViewSpecific,
1526 wcsession *WCC = WC;
1527 calview *c = (calview*) *ViewSpecific;
1529 if (c->view == calview_day) {
1530 calendar_day_view(c->year, c->month, c->day);
1532 else if (c->view == calview_week) {
1533 calendar_week_view(c->year, c->month, c->day);
1536 if (WCC->CurRoom.view == VIEW_CALBRIEF) {
1537 calendar_brief_month_view(c->year, c->month, c->day);
1540 calendar_month_view(c->year, c->month, c->day);
1544 /* Free the in-memory list of calendar items */
1545 DeleteHash(&WC->disp_cal_items);