5 * \defgroup CalHtmlHandles Handles the HTML display of calendar items.
10 #include "webserver.h"
12 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
14 /****************************************************************************/
17 void embeddable_mini_calendar(int year, int month, char *urlformat)
19 struct tm starting_tm;
23 time_t previous_month;
25 time_t colheader_time;
26 struct tm colheader_tm;
27 char colheader_label[32];
29 char weekstart_buf[16];
32 char escaped_urlformat[256];
34 snprintf(div_id, sizeof div_id, "mini_calendar_%d", rand() );
36 /* Determine what day to start.
38 get_preference("weekstart", weekstart_buf, sizeof weekstart_buf);
39 weekstart = atoi(weekstart_buf);
42 * Now back up to the 1st of the month...
44 memset(&starting_tm, 0, sizeof(struct tm));
46 starting_tm.tm_year = year - 1900;
47 starting_tm.tm_mon = month - 1;
48 starting_tm.tm_mday = 1;
49 thetime = mktime(&starting_tm);
51 memcpy(&tm, &starting_tm, sizeof(struct tm));
52 while (tm.tm_mday != 1) {
53 thetime = thetime - (time_t)86400; /* go back 24 hours */
54 localtime_r(&thetime, &tm);
57 /** Determine previous and next months ... for links */
58 previous_month = thetime - (time_t)864000L; /* back 10 days */
59 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
61 /** Now back up until we're on the user's preferred start day */
62 localtime_r(&thetime, &tm);
63 while (tm.tm_wday != weekstart) {
64 thetime = thetime - (time_t)86400; /* go back 24 hours */
65 localtime_r(&thetime, &tm);
68 wprintf("<div class=\"mini_calendar\" id=\"%s\">\n", div_id);
70 /* Previous month link */
71 localtime_r(&previous_month, &tm);
72 wprintf("<a href=\"javascript:minical_change_month(%d,%d);\">«</a>",
73 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
75 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
76 wprintf(" "
77 "<span class=\"mini_calendar_month_label\">"
80 " ", colheader_label, year);
83 localtime_r(&next_month, &tm);
84 wprintf("<a href=\"javascript:minical_change_month(%d,%d);\">»</a>",
85 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
87 wprintf("<table border=0 cellpadding=1 cellspacing=1 class=\"mini_calendar_days\">"
89 colheader_time = thetime;
91 colheader_time = thetime + (i * 86400) ;
92 localtime_r(&colheader_time, &colheader_tm);
93 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
94 wprintf("<th>%c</th>", colheader_label[0]);
100 /** Now do 35 or 42 days */
101 for (i = 0; i < 42; ++i) {
102 localtime_r(&thetime, &tm);
106 /** Before displaying Sunday, start a new row */
111 if (tm.tm_mon == month-1) {
112 snprintf(url, sizeof url, urlformat,
113 tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday);
114 wprintf("<td><a href=\"%s\">%d</a></td>", url, tm.tm_mday);
117 wprintf("<td> </td>");
120 /** After displaying one week, end the row */
127 thetime += (time_t)86400; /** ahead 24 hours */
130 wprintf("</table>" /** end of inner table */
133 /* javascript for previous and next month */
134 len = strlen(urlformat);
135 for (i=0; i<len; ++i) {
136 sprintf(&escaped_urlformat[i*2], "%02X", urlformat[i]);
139 wprintf("<script type=\"text/javascript\"> "
140 " function minical_change_month(year, month) { "
141 " p = 'year=' + year + '&month=' + month "
142 " + '&urlformat=%s&r=' + CtdlRandomString(); "
143 " new Ajax.Updater('%s', 'mini_calendar', "
144 " { method: 'get', parameters: p, evalScripts: true } ); "
148 escaped_urlformat, div_id
153 /* ajax embedder for the above mini calendar */
154 void ajax_mini_calendar(void) {
157 char *escaped_urlformat;
159 escaped_urlformat = bstr("urlformat");
160 len = strlen(escaped_urlformat) * 2 ;
161 for (i=0; i<len; ++i) {
162 urlformat[i] = xtoi(&escaped_urlformat[i*2], 2);
166 embeddable_mini_calendar( atoi(bstr("year")), atoi(bstr("month")), urlformat );
171 * \brief Display one day of a whole month view of a calendar
172 * \param thetime the month we want to see
174 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 */
189 struct disp_cal *Cal;
192 if (WCC->num_cal == 0) {
193 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;
219 /* Now loop through our list of events to see which ones occur today.
221 for (i=0; i<(WCC->num_cal); ++i) {
222 Cal = &WCC->disp_cal[i];
224 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
226 t = icalproperty_get_dtstart(q);
229 memset(&t, 0, sizeof t);
231 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
233 end_t = icalproperty_get_dtend(q);
236 memset(&end_t, 0, sizeof end_t);
238 if (t.is_date) all_day_event = 1;
242 show_event = ((t.year == year) && (t.month == month) && (t.day == day));
246 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
249 /* If we determined that this event occurs today, then display it.
252 p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
256 wprintf("<table border=0 cellpadding=2><TR>"
257 "<td bgcolor=\"#CCCCDD\">"
261 wprintf("<font size=-1>"
262 "<a href=\"display_edit_event?"
263 "msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\""
265 WC->disp_cal[i].cal_msgnum,
272 wprintf("<i>%s</i> ", _("Summary:"));
273 escputs((char *)icalproperty_get_comment(p));
276 q = icalcomponent_get_first_property(
278 ICAL_LOCATION_PROPERTY);
280 wprintf("<i>%s</i> ", _("Location:"));
281 escputs((char *)icalproperty_get_comment(q));
286 * Only show start/end times if we're actually looking at the VEVENT
287 * component. Otherwise it shows bogus dates for e.g. timezones
289 if (icalcomponent_isa(Cal->cal) == ICAL_VEVENT_COMPONENT) {
291 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
293 t = icalproperty_get_dtstart(q);
298 memset(&d_tm, 0, sizeof d_tm);
299 d_tm.tm_year = t.year - 1900;
300 d_tm.tm_mon = t.month - 1;
301 d_tm.tm_mday = t.day;
302 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
303 wprintf("<i>%s</i> %s<br>",
307 tt = icaltime_as_timet(t);
308 fmt_date(buf, tt, 1);
309 wprintf("<i>%s</i> %s<br>",
310 _("Starting date/time:"), buf);
312 /* Embed the 'show end date/time' loop inside here so it
313 * only executes if this is NOT an all day event.
315 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
317 t = icalproperty_get_dtend(q);
318 tt = icaltime_as_timet(t);
319 fmt_date(buf, tt, 1);
320 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
328 q = icalcomponent_get_first_property(Cal->cal, ICAL_DESCRIPTION_PROPERTY);
330 wprintf("<i>%s</i> ", _("Notes:"));
331 escputs((char *)icalproperty_get_comment(q));
337 icalproperty_get_comment(p));
338 wprintf("</a></font><br />\n");
341 wprintf("</td></tr></table>");
354 * \brief Display one day of a whole month view of a calendar
355 * \param thetime the month we want to see
357 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
367 struct icaltimetype t;
368 int month, day, year;
369 int all_day_event = 0;
373 time_format = get_time_format_cached ();
375 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
376 else timeformat="%I:%M %p";
378 localtime_r(&thetime, &today_tm);
379 month = today_tm.tm_mon + 1;
380 day = today_tm.tm_mday;
381 year = today_tm.tm_year + 1900;
383 for (i=0; i<(WC->num_cal); ++i) {
384 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
385 ICAL_DTSTART_PROPERTY);
387 t = icalproperty_get_dtstart(p);
388 event_tt = icaltime_as_timet(t);
390 if (t.is_date) all_day_event = 1;
391 else all_day_event = 0;
394 gmtime_r(&event_tts, &event_tms);
397 localtime_r(&event_tts, &event_tms);
399 /** \todo epoch &! daymask */
400 if ((event_tms.tm_year == today_tm.tm_year)
401 && (event_tms.tm_mon == today_tm.tm_mon)
402 && (event_tms.tm_mday == today_tm.tm_mday)) {
408 p = icalcomponent_get_first_property(
410 ICAL_SUMMARY_PROPERTY);
411 e = icalcomponent_get_first_property(
413 ICAL_DTEND_PROPERTY);
414 if ((p != NULL) && (e != NULL)) {
417 t = icalproperty_get_dtend(e);
418 event_tte = icaltime_as_timet(t);
419 localtime_r(&event_tte, &event_tme);
420 difftime=(event_tte-event_tts)/60;
421 hours=(int)(difftime / 60);
422 minutes=difftime % 60;
423 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
425 "<a href=\"display_edit_event?msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\">",
429 WC->disp_cal[i].cal_msgnum,
437 icalproperty_get_comment(p));
438 /** \todo: allso ammitime format */
439 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
440 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
442 wprintf("</a></font></td>"
443 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
460 * \brief view one month. pretty view
461 * \param year the year
462 * \param month the month
463 * \param day the actual day we want to see
465 void calendar_month_view(int year, int month, int day) {
466 struct tm starting_tm;
470 time_t previous_month;
472 time_t colheader_time;
473 struct tm colheader_tm;
474 char colheader_label[32];
477 char weekstart_buf[16];
479 /* Determine what day to start.
481 get_preference("weekstart", weekstart_buf, sizeof weekstart_buf);
482 weekstart = atoi(weekstart_buf);
485 * Now back up to the 1st of the month...
487 memset(&starting_tm, 0, sizeof(struct tm));
489 starting_tm.tm_year = year - 1900;
490 starting_tm.tm_mon = month - 1;
491 starting_tm.tm_mday = day;
492 thetime = mktime(&starting_tm);
494 memcpy(&tm, &starting_tm, sizeof(struct tm));
495 while (tm.tm_mday != 1) {
496 thetime = thetime - (time_t)86400; /* go back 24 hours */
497 localtime_r(&thetime, &tm);
500 /** Determine previous and next months ... for links */
501 previous_month = thetime - (time_t)864000L; /* back 10 days */
502 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
504 /** Now back up until we're on the user's preferred start day */
505 localtime_r(&thetime, &tm);
506 while (tm.tm_wday != weekstart) {
507 thetime = thetime - (time_t)86400; /* go back 24 hours */
508 localtime_r(&thetime, &tm);
511 /** Outer table (to get the background color) */
512 wprintf("<div class=\"fix_scrollbar_bug\">"
513 "<table class=\"calendar\"> \n <tr><td>");
515 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
517 wprintf("<td align=center>");
519 localtime_r(&previous_month, &tm);
520 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
521 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
522 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
524 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
525 wprintf(" "
526 "<font size=+1 color=\"#FFFFFF\">"
529 " ", colheader_label, year);
531 localtime_r(&next_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/nextdate_32x.gif\" border=0></A>\n");
536 wprintf("</td></tr></table>\n");
538 /** Inner table (the real one) */
539 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
540 "bgcolor=#204B78 id=\"inner_month\"><tr>");
541 colheader_time = thetime;
542 for (i=0; i<7; ++i) {
543 colheader_time = thetime + (i * 86400) ;
544 localtime_r(&colheader_time, &colheader_tm);
545 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
546 wprintf("<td align=center width=14%%>"
547 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
553 /** Now do 35 or 42 days */
554 for (i = 0; i < 42; ++i) {
555 localtime_r(&thetime, &tm);
557 if ((i < 35) || (chg_month == 0)) {
559 if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) {
566 /** Before displaying Sunday, start a new row */
571 wprintf("<td class=\"cal%s\"><div class=\"day\">",
572 ((tm.tm_mon != month-1) ? "out" :
573 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
576 if ((i==0) || (tm.tm_mday == 1)) {
577 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
578 wprintf("%s ", colheader_label);
580 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
587 /** put the data here, stupid */
588 calendar_month_view_display_events(
596 /** After displaying Saturday, end the row */
603 thetime += (time_t)86400; /** ahead 24 hours */
606 wprintf("</table>" /** end of inner table */
607 "</td></tr></table>" /** end of outer table */
611 * Initialize the bubble tooltips.
613 * Yes, this is as stupid as it looks. Instead of just making the call
614 * to btt_enableTooltips() straight away, we have to create a timer event
615 * and let it initialize as an event after 1 millisecond. This is to
616 * work around a bug in Internet Explorer that causes it to crash if we
617 * manipulate the innerHTML of various DOM nodes while the page is still
618 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
619 * for more information.
621 wprintf("<script type=\"text/javascript\">"
622 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
628 * \brief view one month. brief view
629 * \param year the year
630 * \param month the month
631 * \param day the actual day we want to see
633 void calendar_brief_month_view(int year, int month, int day) {
634 struct tm starting_tm;
638 time_t previous_month;
640 char month_label[32];
642 /** Determine what day to start.
643 * First, back up to the 1st of the month...
645 memset(&starting_tm, 0, sizeof(struct tm));
646 starting_tm.tm_year = year - 1900;
647 starting_tm.tm_mon = month - 1;
648 starting_tm.tm_mday = day;
649 thetime = mktime(&starting_tm);
651 memcpy(&tm, &starting_tm, sizeof(struct tm));
652 while (tm.tm_mday != 1) {
653 thetime = thetime - (time_t)86400; /* go back 24 hours */
654 localtime_r(&thetime, &tm);
657 /** Determine previous and next months ... for links */
658 previous_month = thetime - (time_t)864000L; /* back 10 days */
659 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
661 /** Now back up until we're on a Sunday */
662 localtime_r(&thetime, &tm);
663 while (tm.tm_wday != 0) {
664 thetime = thetime - (time_t)86400; /* go back 24 hours */
665 localtime_r(&thetime, &tm);
668 /** Outer table (to get the background color) */
669 wprintf("<div class=\"fix_scrollbar_bug\">"
670 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
671 "bgcolor=#204B78><TR><TD>\n");
673 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
675 wprintf("<td align=center>");
677 localtime_r(&previous_month, &tm);
678 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
679 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
680 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
682 wc_strftime(month_label, sizeof month_label, "%B", &tm);
683 wprintf(" "
684 "<font size=+1 color=\"#FFFFFF\">"
687 " ", month_label, year);
689 localtime_r(&next_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/nextdate_32x.gif\" border=0></A>\n");
694 wprintf("</td></tr></table>\n");
696 /** Inner table (the real one) */
697 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
698 "bgcolor=#EEEECC><TR>");
700 wprintf("<tr><td colspan=\"100%\">\n");
702 /** Now do 35 days */
703 for (i = 0; i < 35; ++i) {
704 char weeknumber[255];
705 char weekday_name[32];
707 localtime_r(&thetime, &tm);
710 /** Before displaying Sunday, start a new CELL */
712 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
713 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
714 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
724 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
725 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
729 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
730 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
731 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
733 weekday_name,tm.tm_mday,
736 /** put the data of one day here, stupid */
737 calendar_month_view_brief_events(thetime, daycolor);
740 /** After displaying Saturday, end the row */
742 wprintf("</td></tr></table>\n");
745 thetime += (time_t)86400; /** ahead 24 hours */
748 wprintf("</table>" /** end of inner table */
749 "</td></tr></table>" /** end of outer table */
754 * \brief view one week
755 * this should view just one week, but it's not here yet.
756 * \todo ny implemented
757 * \param year the year
758 * \param month the month
759 * \param day the day which we want to see the week around
761 void calendar_week_view(int year, int month, int day) {
762 wprintf("<center><i>week view FIXME</i></center><br />\n");
767 * \brief display one day
768 * Display events for a particular hour of a particular day.
769 * (Specify hour < 0 to show "all day" events)
770 * \param year the year
771 * \param month the month
773 * \param hour the hour we want to start displaying
774 * \param dstart daystart
777 void calendar_day_view_display_events(time_t thetime, int year, int month,
779 int dstart, int dend) {
781 icalproperty *p = NULL;
782 icalproperty *q = NULL;
790 int all_day_event = 0;
791 int ongoing_event = 0;
792 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
793 struct disp_cal *Cal;
794 struct icaltimetype t;
795 struct icaltimetype end_t;
796 struct icaltimetype today_start_t;
797 struct icaltimetype today_end_t;
798 struct tm starting_tm;
811 if (WCC->num_cal == 0) {
812 // \todo FIXME wprintf("<br /><br /><br />\n");
816 lprintf (2, "printing %d\n", hour); /// TODO: remove me.
817 event_start = thetime + 60 * 60 * hour;
818 event_end = thetime + 60 * 60 * (hour + 1);
821 /* Create an imaginary event which spans the current hour. Any events which
822 * overlap with this one take place at least partially in this day.
824 memset(&starting_tm, 0, sizeof(struct tm));
825 starting_tm.tm_year = year - 1900;
826 starting_tm.tm_mon = month - 1;
827 starting_tm.tm_mday = day;
828 starting_tm.tm_hour = hour;
829 starting_tm.tm_min = 0;
830 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
831 today_start_t.is_utc = 1;
833 memset(&ending_tm, 0, sizeof(struct tm));
834 ending_tm.tm_year = year - 1900;
835 ending_tm.tm_mon = month - 1;
836 ending_tm.tm_mday = day;
837 ending_tm.tm_hour = hour;
838 ending_tm.tm_min = 59;
839 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
840 today_end_t.is_utc = 1;
842 /* Now loop through our list of events to see which ones occur today.
844 for (i=0; i<(WCC->num_cal); ++i) {
845 Cal = &WCC->disp_cal[i];
850 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
852 t = icalproperty_get_dtstart(q);
853 event_tt = icaltime_as_timet(t);
854 localtime_r(&event_tt, &event_te);
857 memset(&t, 0, sizeof t);
859 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
861 end_t = icalproperty_get_dtend(q);
862 event_tte = icaltime_as_timet(end_t);
863 localtime_r(&event_tte, &event_tm);
866 memset(&end_t, 0, sizeof end_t);
868 if (t.is_date) all_day_event = 1;
872 show_event = ((t.year == year) && (t.month == month) && (t.day == day) && (hour == -1));
876 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
880 /* If we determined that this event occurs today, then display it.
882 p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
884 if ((show_event) && (p != NULL)) {
886 if ((event_te.tm_mday != day) || (event_tm.tm_mday != day)) ongoing_event = 1;
890 wprintf("<li class=\"event\"> "
891 "<a href=\"display_edit_event?"
892 "msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\" "
893 " class=\"event_title\" "
895 Cal->cal_msgnum, year, month, day, hour);
896 wprintf("<i>%s</i><br />", _("All day event"));
897 wprintf("<i>%s</i> ", _("Summary:"));
898 escputs((char *) icalproperty_get_comment(p));
900 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
902 wprintf("<i>%s</i> ", _("Location:"));
903 escputs((char *)icalproperty_get_comment(q));
906 memset(&d_tm, 0, sizeof d_tm);
907 d_tm.tm_year = t.year - 1900;
908 d_tm.tm_mon = t.month - 1;
909 d_tm.tm_mday = t.day;
910 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
911 wprintf("<i>%s</i> %s<br>",_("Date:"), d_str);
912 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
914 wprintf("<i>%s</i> ", _("Notes:"));
915 escputs((char *)icalproperty_get_comment(q));
919 escputs((char *) icalproperty_get_comment(p));
920 wprintf("</a> <span>(");
921 wprintf(_("All day event"));
922 wprintf(")</span></li>\n");
924 else if (ongoing_event && (hour == -1))
926 wprintf("<li class=\"event\"> "
927 "<a href=\"display_edit_event?"
928 "msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\" "
929 " class=\"event_title\" "
931 Cal->cal_msgnum, year, month, day, hour);
932 wprintf("<i>%s</i><br />", _("Ongoing event"));
933 wprintf("<i>%s</i> ", _("Summary:"));
934 escputs((char *) icalproperty_get_comment(p));
936 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
938 wprintf("<i>%s</i> ", _("Location:"));
939 escputs((char *)icalproperty_get_comment(q));
942 fmt_date(buf, event_tt, 1);
943 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
944 fmt_date(buf, event_tte, 1);
945 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
946 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
948 wprintf("<i>%s</i> ", _("Notes:"));
949 escputs((char *)icalproperty_get_comment(q));
953 escputs((char *) icalproperty_get_comment(p));
954 wprintf("</a> <span>(");
955 wprintf(_("Ongoing event"));
956 wprintf(")</span></li>\n");
961 if ((today_start_t.hour == t.hour)
962 && ((event_te.tm_mday == day)
963 || (event_tm.tm_mday == day)))
966 if (event_te.tm_mday != day) event_te.tm_hour = 0;
967 if (event_tm.tm_mday != day) event_tm.tm_hour = 24;
969 if ((event_te.tm_hour < dstart) && (event_tm.tm_hour <= dstart)) {
970 startmin = diffmin = event_te.tm_min / 6;
971 endmin = ((event_tm.tm_hour == hour) ? (event_tm.tm_min / 2) : (event_tm.tm_min / 6)) ;
972 top = (event_te.tm_hour * 10) + startmin -1;
973 height= ((event_tm.tm_hour - event_te.tm_hour) * 10) + endmin - diffmin ;
975 if ((event_te.tm_hour < dstart) && (event_tm.tm_hour >= dstart)) {
976 startmin = diffmin = event_te.tm_min / 6;
977 endmin = event_tm.tm_min / 2;
978 top = (event_te.tm_hour * 10) + startmin - 1;
979 height = ((dstart - event_te.tm_hour) * 10) + ((event_tm.tm_hour - dstart) * 30) + endmin - (diffmin * 3);
981 if ((event_te.tm_hour <= dstart) && (event_tm.tm_hour > dend)) {
982 startmin = diffmin = ((event_te.tm_hour == hour) ? (event_te.tm_min / 2) : (event_te.tm_min / 6)) ;
983 endmin = event_tm.tm_min / 6;
984 top = (event_te.tm_hour * 10) + startmin - 1;
985 height = ((dstart - event_te.tm_hour) * 10) + ((dend - dstart + 1) * 30) + ((event_tm.tm_hour - dend - 1) * 10) + endmin - diffmin;
987 if ((event_te.tm_hour >= dstart) && (event_tm.tm_hour <= dend)) {
988 startmin = diffmin = (event_te.tm_min / 2);
989 endmin = event_tm.tm_min / 2;
990 top = (dstart * 10) + ((event_te.tm_hour - dstart) * 30) + startmin - 1;
991 height = ((event_tm.tm_hour - event_te.tm_hour) * 30) + endmin - diffmin;
993 if ((event_te.tm_hour >= dstart) && (event_te.tm_hour <= dend) && (event_tm.tm_hour > dend)) {
994 startmin = diffmin = (event_te.tm_min / 2);
995 endmin = event_tm.tm_min / 6;
996 top = (dstart * 10) + ((event_te.tm_hour - dstart) * 30) + diffmin - 1;
997 height = (((dend - event_te.tm_hour + 1) * 30) + ((event_tm.tm_hour - dend - 1) * 10)) + endmin - diffmin;
999 if ((event_te.tm_hour > dend) && (event_tm.tm_hour > dend)) {
1000 startmin = diffmin = event_te.tm_min / 6;
1001 endmin = event_tm.tm_min / 6;
1002 top = (dstart * 10) + ((dend - dstart) * 30) + ((event_tm.tm_hour - event_te.tm_hour + 1) * 10) + startmin - 1;
1003 height = ((event_tm.tm_hour - event_te.tm_hour) * 10) + endmin - diffmin;
1005 // TODO: we seem to end up here for some reason if we're just a one hour event. Thierry, please decide what to do then...
1006 wprintf("<dd class=\"event\" "
1007 "style=\"position: absolute; "
1008 "top:%dpx; left:%dpx; "
1009 "height:%dpx; \" >",
1010 top, (gap * 40), height
1012 wprintf("<a href=\"display_edit_event?"
1013 "msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d&case=%d\" "
1014 "class=\"event_title\" "
1016 Cal->cal_msgnum, year, month, day, t.hour, hour);
1017 wprintf("<i>%s</i> ", _("Summary:"));
1018 escputs((char *) icalproperty_get_comment(p));
1020 q = icalcomponent_get_first_property(Cal->cal,ICAL_LOCATION_PROPERTY);
1022 wprintf("<i>%s</i> ", _("Location:"));
1023 escputs((char *)icalproperty_get_comment(q));
1026 fmt_date(buf, event_tt, 1);
1027 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
1028 fmt_date(buf, event_tte, 1);
1029 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
1030 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
1032 wprintf("<i>%s</i> ", _("Notes:"));
1033 escputs((char *)icalproperty_get_comment(q));
1038 escputs((char *) icalproperty_get_comment(p));
1039 wprintf("</a></dd>\n");
1048 * \brief view one day
1049 * \param year the year
1050 * \param month the month
1051 * \param day the day we want to display
1053 void calendar_day_view(int year, int month, int day) {
1055 struct icaltimetype today, yesterday, tomorrow;
1058 char daystart_str[16], dayend_str[16];
1064 int extratimeline = 0;
1067 time_format = get_time_format_cached ();
1068 get_preference("daystart", daystart_str, sizeof daystart_str);
1069 if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
1070 get_preference("dayend", dayend_str, sizeof dayend_str);
1071 if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str);
1074 memset(&d_tm, 0, sizeof d_tm);
1075 d_tm.tm_year = year - 1900;
1076 d_tm.tm_mon = month - 1;
1078 today_t = mktime(&d_tm);
1080 /** Figure out the dates for "yesterday" and "tomorrow" links */
1082 memset(&today, 0, sizeof(struct icaltimetype));
1084 today.month = month;
1088 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
1090 yesterday = icaltime_normalize(yesterday);
1092 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
1094 tomorrow = icaltime_normalize(tomorrow);
1096 wprintf("<div class=\"fix_scrollbar_bug\">");
1098 /** Inner table (the real one) */
1099 wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
1101 /** Innermost cell (contains hours etc.) */
1102 wprintf("<td class=\"events_of_the_day\" >");
1103 wprintf("<dl class=\"events\" >");
1105 /** Now the middle of the day... */
1107 extratimeline = timeline / 3;
1109 for (hour = 0; hour < daystart; ++hour) { /* could do HEIGHT=xx */
1110 wprintf("<dt class=\"extrahour\" "
1112 "position: absolute; "
1113 "top: %dpx; left: 0px; "
1116 "<a href=\"display_edit_event?msgnum=0"
1117 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
1118 (hour * extratimeline ), extratimeline,
1119 year, month, day, hour
1122 if (time_format == WC_TIMEFORMAT_24) {
1123 wprintf("%2d:00</a> ", hour);
1126 wprintf("%d:00%s</a> ",
1127 (hour <= 12 ? hour : hour-12),
1128 (hour < 12 ? "am" : "pm")
1134 /* put the data here, stupid */
1135 calendar_day_view_display_events(today_t, year, month, day, hour, daystart, dayend);
1139 gap = daystart * extratimeline;
1141 for (hour = daystart; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
1142 wprintf("<dt class=\"hour\" "
1144 "position: absolute; "
1145 "top: %dpx; left: 0px; "
1148 "<a href=\"display_edit_event?msgnum=0"
1149 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
1150 gap + ((hour - daystart) * timeline ), timeline,
1151 year, month, day, hour
1154 if (time_format == WC_TIMEFORMAT_24) {
1155 wprintf("%2d:00</a> ", hour);
1158 wprintf("%d:00%s</a> ",
1159 (hour <= 12 ? hour : hour-12),
1160 (hour < 12 ? "am" : "pm")
1166 /* put the data here, stupid */
1167 calendar_day_view_display_events(today_t, year, month, day, hour, daystart, dayend);
1171 gap = gap + ((dayend - daystart + 1) * timeline);
1173 for (hour = (dayend + 1); hour < 24; ++hour) { /* could do HEIGHT=xx */
1174 wprintf("<dt class=\"extrahour\" "
1176 "position: absolute; "
1177 "top: %dpx; left: 0px; "
1180 "<a href=\"display_edit_event?msgnum=0"
1181 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
1182 gap + ((hour - dayend - 1) * extratimeline ), extratimeline,
1183 year, month, day, hour
1186 if (time_format == WC_TIMEFORMAT_24) {
1187 wprintf("%2d:00</a> ", hour);
1190 wprintf("%d:00%s</a> ",
1191 (hour <= 12 ? hour : hour-12),
1192 (hour < 12 ? "am" : "pm")
1198 /* put the data here, stupid */
1199 calendar_day_view_display_events(today_t, year, month, day, hour, daystart, dayend);
1204 wprintf("</td>"); /* end of innermost table */
1206 /** Extra events on the middle */
1207 wprintf("<td class=\"extra_events\">");
1211 /** Display all-day events) */
1212 calendar_day_view_display_events(today_t, year, month, day, -1, daystart, dayend);
1216 wprintf("</td>"); /** end extra on the middle */
1218 wprintf("<td width=20%% align=center valign=top>"); /** begin stuff-on-the-right */
1220 /** Begin todays-date-with-left-and-right-arrows */
1221 wprintf("<table border=0 width=100%% "
1222 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
1226 wprintf("<td align=center>");
1227 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
1228 yesterday.year, yesterday.month, yesterday.day);
1229 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
1232 wc_strftime(d_str, sizeof d_str,
1234 "<font size=+2>%B</font><br />"
1235 "<font size=+3>%d</font><br />"
1236 "<font size=+2>%Y</font><br />"
1240 wprintf("%s", d_str);
1243 wprintf("<td align=center>");
1244 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
1245 tomorrow.year, tomorrow.month, tomorrow.day);
1246 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
1247 " border=0></a>\n");
1250 wprintf("</tr></table>\n");
1251 /** End todays-date-with-left-and-right-arrows */
1253 /** Embed a mini month calendar in this space */
1254 wprintf("<br />\n");
1255 embeddable_mini_calendar(year, month, "readfwd?calview=day&year=%d&month=%d&day=%d");
1257 wprintf("</font></center>\n");
1259 wprintf("</td></tr>"); /** end stuff-on-the-right */
1261 wprintf("</table>" /** end of inner table */
1264 wprintf("<script type=\"text/javascript\">"
1265 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); "
1272 * \brief Display today's events.
1274 void calendar_summary_view(void) {
1277 struct icaltimetype t;
1282 int all_day_event = 0;
1283 char timestring[SIZ];
1285 if (WC->num_cal == 0) {
1290 localtime_r(&now, &today_tm);
1292 for (i=0; i<(WC->num_cal); ++i) {
1293 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1294 ICAL_DTSTART_PROPERTY);
1296 t = icalproperty_get_dtstart(p);
1297 event_tt = icaltime_as_timet(t);
1304 fmt_time(timestring, event_tt);
1306 if (all_day_event) {
1307 gmtime_r(&event_tt, &event_tm);
1310 localtime_r(&event_tt, &event_tm);
1313 if ( (event_tm.tm_year == today_tm.tm_year)
1314 && (event_tm.tm_mon == today_tm.tm_mon)
1315 && (event_tm.tm_mday == today_tm.tm_mday)
1319 p = icalcomponent_get_first_property(
1320 WC->disp_cal[i].cal,
1321 ICAL_SUMMARY_PROPERTY);
1324 icalproperty_get_comment(p));
1325 wprintf(" (%s)<br />\n", timestring);
1330 free_calendar_buffer();
1335 * \brief clean up ical memory
1336 * \todo this could get troubel with future ical versions
1338 void free_calendar_buffer(void) {
1340 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1341 icalcomponent_free(WC->disp_cal[i].cal);
1345 WC->disp_cal = NULL;
1351 * \brief do the whole calendar page
1352 * view any part of the calender. decide which way, etc.
1354 void do_calendar_view(void) {
1357 int year, month, day;
1360 /** In case no date was specified, go with today */
1362 localtime_r(&now, &tm);
1363 year = tm.tm_year + 1900;
1364 month = tm.tm_mon + 1;
1367 /** Now see if a date was specified */
1368 if (!IsEmptyStr(bstr("year"))) year = atoi(bstr("year"));
1369 if (!IsEmptyStr(bstr("month"))) month = atoi(bstr("month"));
1370 if (!IsEmptyStr(bstr("day"))) day = atoi(bstr("day"));
1372 /** How would you like that cooked? */
1373 if (!IsEmptyStr(bstr("calview"))) {
1374 strcpy(calview, bstr("calview"));
1377 strcpy(calview, "month");
1380 /** Display the selected view */
1381 if (!strcasecmp(calview, "day")) {
1382 calendar_day_view(year, month, day);
1384 else if (!strcasecmp(calview, "week")) {
1385 calendar_week_view(year, month, day);
1388 if (WC->wc_view == VIEW_CALBRIEF) {
1389 calendar_brief_month_view(year, month, day);
1392 calendar_month_view(year, month, day);
1396 /** Free the calendar stuff */
1397 free_calendar_buffer();
1403 * \brief get task due date
1404 * Helper function for do_tasks_view().
1405 * \param vtodo a task to get the due date
1406 * \return the date/time due.
1408 time_t get_task_due_date(icalcomponent *vtodo) {
1411 if (vtodo == NULL) {
1416 * If we're looking at a fully encapsulated VCALENDAR
1417 * rather than a VTODO component, recurse into the data
1418 * structure until we get a VTODO.
1420 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1421 return get_task_due_date(
1422 icalcomponent_get_first_component(
1423 vtodo, ICAL_VTODO_COMPONENT
1428 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1430 return(icaltime_as_timet(icalproperty_get_due(p)));
1439 * \brief Compare the due dates of two tasks (this is for sorting)
1440 * \param task1 first task to compare
1441 * \param task2 second task to compare
1443 int task_due_cmp(const void *task1, const void *task2) {
1447 t1 = get_task_due_date(((struct disp_cal *)task1)->cal);
1448 t2 = get_task_due_date(((struct disp_cal *)task2)->cal);
1450 if (t1 < t2) return(-1);
1451 if (t1 > t2) return(1);
1459 * \brief do the whole task view stuff
1461 void do_tasks_view(void) {
1468 wprintf("<div class=\"fix_scrollbar_bug\">"
1469 "<table class=\"calendar_view_background\">\n<tr>\n"
1471 wprintf(_("Name of task"));
1472 wprintf("</th><th>");
1473 wprintf(_("Date due"));
1474 wprintf("</th></tr>\n"
1477 /** Sort them if necessary */
1478 if (WC->num_cal > 1) {
1481 sizeof(struct disp_cal),
1486 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1489 wprintf("<tr bgcolor=\"#%s\"><td>",
1490 (bg ? "DDDDDD" : "FFFFFF")
1493 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1494 ICAL_SUMMARY_PROPERTY);
1495 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1496 WC->disp_cal[i].cal_msgnum );
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(WC->disp_cal[i].cal);
1508 fmt_date(buf, due, 0);
1509 wprintf("<td><font");
1510 if (due < time(NULL)) {
1511 wprintf(" color=\"#FF0000\"");
1513 wprintf(">%s</font></td></tr>\n", buf);
1516 wprintf("</table></div>\n");
1518 /** Free the list */
1519 free_calendar_buffer();
1523 #else /* WEBCIT_WITH_CALENDAR_SERVICE */
1525 /**\brief stub for non-libical builds */
1526 void do_calendar_view(void) {
1527 wprintf("<center><i>");
1528 wprintf(_("The calendar view is not available."));
1529 wprintf("</i></center><br />\n");
1532 /**\brief stub for non-libical builds */
1533 void do_tasks_view(void) {
1534 wprintf("<center><I>");
1535 wprintf(_("The tasks view is not available."));
1536 wprintf("</i></center><br />\n");
1539 /**\brief stub for non-libical builds */
1540 void ajax_mini_calendar(void) {
1543 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */