5 * \defgroup CalHtmlHandles Handles the HTML display of calendar items.
10 #include "webserver.h"
12 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
14 /****************************************************************************/
17 * \brief Display one day of a whole month view of a calendar
18 * \param thetime the month we want to see
20 void calendar_month_view_display_events(int year, int month, int day)
23 icalproperty *p = NULL;
24 icalproperty *q = NULL;
25 struct icaltimetype t;
26 struct icaltimetype end_t;
27 struct icaltimetype today_start_t;
28 struct icaltimetype today_end_t;
29 struct tm starting_tm;
31 int all_day_event = 0;
34 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
38 if (WCC->num_cal == 0) {
39 wprintf("<br /><br /><br />\n");
43 /* Create an imaginary event which spans the 24 hours of today. Any events which
44 * overlap with this one take place at least partially in this day. We have to
45 * convert it from a struct tm in order to make it UTC.
47 memset(&starting_tm, 0, sizeof(struct tm));
48 starting_tm.tm_year = year - 1900;
49 starting_tm.tm_mon = month - 1;
50 starting_tm.tm_mday = day;
51 starting_tm.tm_hour = 0;
52 starting_tm.tm_min = 0;
53 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
54 today_start_t.is_utc = 1;
56 memset(&ending_tm, 0, sizeof(struct tm));
57 ending_tm.tm_year = year - 1900;
58 ending_tm.tm_mon = month - 1;
59 ending_tm.tm_mday = day;
60 ending_tm.tm_hour = 23;
61 ending_tm.tm_min = 59;
62 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
63 today_end_t.is_utc = 1;
65 /* Now loop through our list of events to see which ones occur today.
67 for (i=0; i<(WCC->num_cal); ++i) {
68 Cal = &WCC->disp_cal[i];
70 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
72 t = icalproperty_get_dtstart(q);
75 memset(&t, 0, sizeof t);
77 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
79 end_t = icalproperty_get_dtend(q);
82 memset(&end_t, 0, sizeof end_t);
84 if (t.is_date) all_day_event = 1;
88 show_event = ((t.year == year) && (t.month == month) && (t.day == day));
92 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
95 /* If we determined that this event occurs today, then display it.
98 p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
102 wprintf("<table border=0 cellpadding=2><TR>"
103 "<td bgcolor=\"#CCCCDD\">"
107 wprintf("<font size=-1>"
108 "<a href=\"display_edit_event?"
109 "msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\""
111 WC->disp_cal[i].cal_msgnum,
118 wprintf("<i>%s</i> ", _("Summary:"));
119 escputs((char *)icalproperty_get_comment(p));
122 q = icalcomponent_get_first_property(
124 ICAL_LOCATION_PROPERTY);
126 wprintf("<i>%s</i> ", _("Location:"));
127 escputs((char *)icalproperty_get_comment(q));
132 * Only show start/end times if we're actually looking at the VEVENT
133 * component. Otherwise it shows bogus dates for e.g. timezones
135 if (icalcomponent_isa(Cal->cal) == ICAL_VEVENT_COMPONENT) {
137 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
139 t = icalproperty_get_dtstart(q);
144 memset(&d_tm, 0, sizeof d_tm);
145 d_tm.tm_year = t.year - 1900;
146 d_tm.tm_mon = t.month - 1;
147 d_tm.tm_mday = t.day;
148 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
149 wprintf("<i>%s</i> %s<br>",
153 tt = icaltime_as_timet(t);
154 fmt_date(buf, tt, 1);
155 wprintf("<i>%s</i> %s<br>",
156 _("Starting date/time:"), buf);
158 /* Embed the 'show end date/time' loop inside here so it
159 * only executes if this is NOT an all day event.
161 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
163 t = icalproperty_get_dtend(q);
164 tt = icaltime_as_timet(t);
165 fmt_date(buf, tt, 1);
166 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
174 q = icalcomponent_get_first_property(Cal->cal, ICAL_DESCRIPTION_PROPERTY);
176 wprintf("<i>%s</i> ", _("Notes:"));
177 escputs((char *)icalproperty_get_comment(q));
183 icalproperty_get_comment(p));
184 wprintf("</a></font><br />\n");
187 wprintf("</td></tr></table>");
200 * \brief Display one day of a whole month view of a calendar
201 * \param thetime the month we want to see
203 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
213 struct icaltimetype t;
214 int month, day, year;
215 int all_day_event = 0;
219 time_format = get_time_format_cached ();
221 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
222 else timeformat="%I:%M %p";
224 localtime_r(&thetime, &today_tm);
225 month = today_tm.tm_mon + 1;
226 day = today_tm.tm_mday;
227 year = today_tm.tm_year + 1900;
229 for (i=0; i<(WC->num_cal); ++i) {
230 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
231 ICAL_DTSTART_PROPERTY);
233 t = icalproperty_get_dtstart(p);
234 event_tt = icaltime_as_timet(t);
236 if (t.is_date) all_day_event = 1;
237 else all_day_event = 0;
240 gmtime_r(&event_tts, &event_tms);
243 localtime_r(&event_tts, &event_tms);
245 /** \todo epoch &! daymask */
246 if ((event_tms.tm_year == today_tm.tm_year)
247 && (event_tms.tm_mon == today_tm.tm_mon)
248 && (event_tms.tm_mday == today_tm.tm_mday)) {
254 p = icalcomponent_get_first_property(
256 ICAL_SUMMARY_PROPERTY);
257 e = icalcomponent_get_first_property(
259 ICAL_DTEND_PROPERTY);
260 if ((p != NULL) && (e != NULL)) {
263 t = icalproperty_get_dtend(e);
264 event_tte = icaltime_as_timet(t);
265 localtime_r(&event_tte, &event_tme);
266 difftime=(event_tte-event_tts)/60;
267 hours=(int)(difftime / 60);
268 minutes=difftime % 60;
269 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
271 "<a href=\"display_edit_event?msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\">",
275 WC->disp_cal[i].cal_msgnum,
283 icalproperty_get_comment(p));
284 /** \todo: allso ammitime format */
285 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
286 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
288 wprintf("</a></font></td>"
289 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
306 * \brief view one month. pretty view
307 * \param year the year
308 * \param month the month
309 * \param day the actual day we want to see
311 void calendar_month_view(int year, int month, int day) {
312 struct tm starting_tm;
316 time_t previous_month;
318 time_t colheader_time;
319 struct tm colheader_tm;
320 char colheader_label[32];
323 char weekstart_buf[16];
325 /* Determine what day to start.
327 get_preference("weekstart", weekstart_buf, sizeof weekstart_buf);
328 weekstart = atoi(weekstart_buf);
331 * Now back up to the 1st of the month...
333 memset(&starting_tm, 0, sizeof(struct tm));
335 starting_tm.tm_year = year - 1900;
336 starting_tm.tm_mon = month - 1;
337 starting_tm.tm_mday = day;
338 thetime = mktime(&starting_tm);
340 memcpy(&tm, &starting_tm, sizeof(struct tm));
341 while (tm.tm_mday != 1) {
342 thetime = thetime - (time_t)86400; /* go back 24 hours */
343 localtime_r(&thetime, &tm);
346 /** Determine previous and next months ... for links */
347 previous_month = thetime - (time_t)864000L; /* back 10 days */
348 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
350 /** Now back up until we're on the user's preferred start day */
351 localtime_r(&thetime, &tm);
352 while (tm.tm_wday != weekstart) {
353 thetime = thetime - (time_t)86400; /* go back 24 hours */
354 localtime_r(&thetime, &tm);
357 /** Outer table (to get the background color) */
358 wprintf("<div class=\"fix_scrollbar_bug\">"
359 "<table class=\"calendar\"> \n <tr><td>");
361 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
363 wprintf("<td align=center>");
365 localtime_r(&previous_month, &tm);
366 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
367 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
368 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
370 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
371 wprintf(" "
372 "<font size=+1 color=\"#FFFFFF\">"
375 " ", colheader_label, year);
377 localtime_r(&next_month, &tm);
378 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
379 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
380 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
382 wprintf("</td></tr></table>\n");
384 /** Inner table (the real one) */
385 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
386 "bgcolor=#204B78 id=\"inner_month\"><tr>");
387 colheader_time = thetime;
388 for (i=0; i<7; ++i) {
389 colheader_time = thetime + (i * 86400) ;
390 localtime_r(&colheader_time, &colheader_tm);
391 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
392 wprintf("<td align=center width=14%%>"
393 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
399 /** Now do 35 or 42 days */
400 for (i = 0; i < 42; ++i) {
401 localtime_r(&thetime, &tm);
403 if ((i < 35) || (chg_month == 0)) {
405 if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) {
412 /** Before displaying Sunday, start a new row */
417 wprintf("<td class=\"cal%s\"><div class=\"day\">",
418 ((tm.tm_mon != month-1) ? "out" :
419 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
422 if ((i==0) || (tm.tm_mday == 1)) {
423 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
424 wprintf("%s ", colheader_label);
426 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
433 /** put the data here, stupid */
434 calendar_month_view_display_events(
442 /** After displaying Saturday, end the row */
449 thetime += (time_t)86400; /** ahead 24 hours */
452 wprintf("</table>" /** end of inner table */
453 "</td></tr></table>" /** end of outer table */
457 * Initialize the bubble tooltips.
459 * Yes, this is as stupid as it looks. Instead of just making the call
460 * to btt_enableTooltips() straight away, we have to create a timer event
461 * and let it initialize as an event after 1 millisecond. This is to
462 * work around a bug in Internet Explorer that causes it to crash if we
463 * manipulate the innerHTML of various DOM nodes while the page is still
464 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
465 * for more information.
467 wprintf("<script type=\"text/javascript\">"
468 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
474 * \brief view one month. brief view
475 * \param year the year
476 * \param month the month
477 * \param day the actual day we want to see
479 void calendar_brief_month_view(int year, int month, int day) {
480 struct tm starting_tm;
484 time_t previous_month;
486 char month_label[32];
488 /** Determine what day to start.
489 * First, back up to the 1st of the month...
491 memset(&starting_tm, 0, sizeof(struct tm));
492 starting_tm.tm_year = year - 1900;
493 starting_tm.tm_mon = month - 1;
494 starting_tm.tm_mday = day;
495 thetime = mktime(&starting_tm);
497 memcpy(&tm, &starting_tm, sizeof(struct tm));
498 while (tm.tm_mday != 1) {
499 thetime = thetime - (time_t)86400; /* go back 24 hours */
500 localtime_r(&thetime, &tm);
503 /** Determine previous and next months ... for links */
504 previous_month = thetime - (time_t)864000L; /* back 10 days */
505 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
507 /** Now back up until we're on a Sunday */
508 localtime_r(&thetime, &tm);
509 while (tm.tm_wday != 0) {
510 thetime = thetime - (time_t)86400; /* go back 24 hours */
511 localtime_r(&thetime, &tm);
514 /** Outer table (to get the background color) */
515 wprintf("<div class=\"fix_scrollbar_bug\">"
516 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
517 "bgcolor=#204B78><TR><TD>\n");
519 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
521 wprintf("<td align=center>");
523 localtime_r(&previous_month, &tm);
524 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
525 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
526 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
528 wc_strftime(month_label, sizeof month_label, "%B", &tm);
529 wprintf(" "
530 "<font size=+1 color=\"#FFFFFF\">"
533 " ", month_label, year);
535 localtime_r(&next_month, &tm);
536 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
537 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
538 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
540 wprintf("</td></tr></table>\n");
542 /** Inner table (the real one) */
543 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
544 "bgcolor=#EEEECC><TR>");
546 wprintf("<tr><td colspan=\"100%\">\n");
548 /** Now do 35 days */
549 for (i = 0; i < 35; ++i) {
550 char weeknumber[255];
551 char weekday_name[32];
553 localtime_r(&thetime, &tm);
556 /** Before displaying Sunday, start a new CELL */
558 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
559 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
560 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
570 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
571 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
575 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
576 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
577 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
579 weekday_name,tm.tm_mday,
582 /** put the data of one day here, stupid */
583 calendar_month_view_brief_events(thetime, daycolor);
586 /** After displaying Saturday, end the row */
588 wprintf("</td></tr></table>\n");
591 thetime += (time_t)86400; /** ahead 24 hours */
594 wprintf("</table>" /** end of inner table */
595 "</td></tr></table>" /** end of outer table */
600 * \brief view one week
601 * this should view just one week, but it's not here yet.
602 * \todo ny implemented
603 * \param year the year
604 * \param month the month
605 * \param day the day which we want to see the week around
607 void calendar_week_view(int year, int month, int day) {
608 wprintf("<center><i>week view FIXME</i></center><br />\n");
613 * \brief display one day
614 * Display events for a particular hour of a particular day.
615 * (Specify hour < 0 to show "all day" events)
616 * \param year the year
617 * \param month the month
619 * \param hour the hour we want to start displaying
620 * \param dstart daystart
623 void calendar_day_view_display_events(time_t thetime, int year, int month,
625 int dstart, int dend) {
627 icalproperty *p = NULL;
628 icalproperty *q = NULL;
636 int all_day_event = 0;
637 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
638 struct disp_cal *Cal;
639 struct icaltimetype t;
640 struct icaltimetype end_t;
641 struct icaltimetype today_start_t;
642 struct icaltimetype today_end_t;
643 struct tm starting_tm;
647 if (WCC->num_cal == 0) {
648 // \todo FIXME wprintf("<br /><br /><br />\n");
652 event_start = thetime + 60 * 60 * hour;
653 event_end = thetime + 60 * 60 * (hour + 1);
656 /* Create an imaginary event which spans the 24 hours of today. Any events which
657 * overlap with this one take place at least partially in this day.
659 memset(&starting_tm, 0, sizeof(struct tm));
660 starting_tm.tm_year = year - 1900;
661 starting_tm.tm_mon = month - 1;
662 starting_tm.tm_mday = day;
663 starting_tm.tm_hour = hour;
664 starting_tm.tm_min = 0;
665 today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
666 today_start_t.is_utc = 1;
668 memset(&ending_tm, 0, sizeof(struct tm));
669 ending_tm.tm_year = year - 1900;
670 ending_tm.tm_mon = month - 1;
671 ending_tm.tm_mday = day;
672 ending_tm.tm_hour = hour;
673 ending_tm.tm_min = 59;
674 today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
675 /* today_end_t.is_utc = 1;*/
677 /* Now loop through our list of events to see which ones occur today.
679 for (i=0; i<(WCC->num_cal); ++i) {
680 Cal = &WCC->disp_cal[i];
683 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
685 t = icalproperty_get_dtstart(q);
686 event_tt = icaltime_as_timet(t);
689 memset(&t, 0, sizeof t);
691 q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
693 end_t = icalproperty_get_dtend(q);
696 memset(&end_t, 0, sizeof end_t);
698 if (t.is_date) all_day_event = 1;
702 show_event = ((t.year == year) && (t.month == month) && (t.day == day) && (hour == -1));
706 show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
707 localtime_r(&event_tt, &event_te);
710 /* If we determined that this event occurs today, then display it.
712 p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
713 if ((show_event) && (p != NULL)) {
716 wprintf("<dd><a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
717 Cal->cal_msgnum, year, month, day, hour);
718 escputs((char *) icalproperty_get_comment(p));
719 wprintf("</a></dd>\n");
723 event_tte = icaltime_as_timet(end_t);
724 localtime_r(&event_tte, &event_tm);
725 if (hour == event_te.tm_hour) {
726 wprintf("<dd class=\"event\" "
727 "style=\"position: absolute; "
728 "top:%dpx; left:100px; "
730 ((dstart * 11) + (event_te.tm_hour - dstart) * (event_te.tm_hour < dstart? 11 : 31)),
731 ((event_tm.tm_hour - event_te.tm_hour) * 30)
733 wprintf("<a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d&case=%d\">",
734 Cal->cal_msgnum, year, month, day, t.hour, hour);
735 escputs((char *) icalproperty_get_comment(p));
736 wprintf("</a></dd>\n");
745 * \brief view one day
746 * \param year the year
747 * \param month the month
748 * \param day the day we want to display
750 void calendar_day_view(int year, int month, int day) {
752 struct icaltimetype today, yesterday, tomorrow;
755 char daystart_str[16], dayend_str[16];
761 time_format = get_time_format_cached ();
762 get_preference("daystart", daystart_str, sizeof daystart_str);
763 if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
764 get_preference("dayend", dayend_str, sizeof dayend_str);
765 if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str);
768 memset(&d_tm, 0, sizeof d_tm);
769 d_tm.tm_year = year - 1900;
770 d_tm.tm_mon = month - 1;
772 today_t = mktime(&d_tm);
774 /** Figure out the dates for "yesterday" and "tomorrow" links */
776 memset(&today, 0, sizeof(struct icaltimetype));
782 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
784 yesterday = icaltime_normalize(yesterday);
786 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
788 tomorrow = icaltime_normalize(tomorrow);
790 wprintf("<div class=\"fix_scrollbar_bug\">");
792 /** Inner table (the real one) */
793 wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
795 /** Innermost cell (contains hours etc.) */
796 wprintf("<td class=\"events_of_the_day\" >");
797 wprintf("<dl class=\"events\" >");
798 /** Now the middle of the day... */
799 for (hour = 0; hour < 24; ++hour) { /* could do HEIGHT=xx */
800 wprintf("<dt class=\"hour%s\"><a href=\"display_edit_event?msgnum=0"
801 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
802 (hour < daystart ? "before" : (hour > dayend ? "after" : "")),
803 year, month, day, hour
806 if (time_format == WC_TIMEFORMAT_24) {
807 wprintf("%2d:00</a> ", hour);
810 wprintf("%d:00%s</a> ",
811 (hour <= 12 ? hour : hour-12),
812 (hour < 12 ? "am" : "pm")
819 /* put the data here, stupid */
820 calendar_day_view_display_events(today_t, year, month, day, hour, daystart, dayend);
825 wprintf("</td>"); /* end of innermost table */
827 /** Extra events on the middle */
828 wprintf("<td class=\"extra_events\">");
832 /** Display all-day events) */
833 wprintf("<dt>All day events</dt>");
834 calendar_day_view_display_events(today_t, year, month, day, -1, daystart, dayend);
838 wprintf("</td>"); /** end extra on the middle */
840 wprintf("<td width=20%% valign=top>"); /** begin stuff-on-the-right */
842 /** Begin todays-date-with-left-and-right-arrows */
843 wprintf("<table border=0 width=100%% "
844 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
848 wprintf("<td align=center>");
849 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
850 yesterday.year, yesterday.month, yesterday.day);
851 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
854 wc_strftime(d_str, sizeof d_str,
856 "<font size=+2>%B</font><br />"
857 "<font size=+3>%d</font><br />"
858 "<font size=+2>%Y</font><br />"
862 wprintf("%s", d_str);
865 wprintf("<td align=center>");
866 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
867 tomorrow.year, tomorrow.month, tomorrow.day);
868 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
872 wprintf("</tr></table>\n");
873 /** End todays-date-with-left-and-right-arrows */
875 /** \todo In the future we might want to put a month-o-matic here */
877 wprintf("</font></center>\n");
879 wprintf("</td></tr>"); /** end stuff-on-the-right */
881 wprintf("</table>" /** end of inner table */
884 wprintf("<script type=\"text/javascript\">"
885 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); "
892 * \brief Display today's events.
894 void calendar_summary_view(void) {
897 struct icaltimetype t;
902 int all_day_event = 0;
903 char timestring[SIZ];
905 if (WC->num_cal == 0) {
910 localtime_r(&now, &today_tm);
912 for (i=0; i<(WC->num_cal); ++i) {
913 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
914 ICAL_DTSTART_PROPERTY);
916 t = icalproperty_get_dtstart(p);
917 event_tt = icaltime_as_timet(t);
924 fmt_time(timestring, event_tt);
927 gmtime_r(&event_tt, &event_tm);
930 localtime_r(&event_tt, &event_tm);
933 if ( (event_tm.tm_year == today_tm.tm_year)
934 && (event_tm.tm_mon == today_tm.tm_mon)
935 && (event_tm.tm_mday == today_tm.tm_mday)
939 p = icalcomponent_get_first_property(
941 ICAL_SUMMARY_PROPERTY);
944 icalproperty_get_comment(p));
945 wprintf(" (%s)<br />\n", timestring);
950 free_calendar_buffer();
955 * \brief clean up ical memory
956 * \todo this could get troubel with future ical versions
958 void free_calendar_buffer(void) {
960 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
961 icalcomponent_free(WC->disp_cal[i].cal);
971 * \brief do the whole calendar page
972 * view any part of the calender. decide which way, etc.
974 void do_calendar_view(void) {
977 int year, month, day;
980 /** In case no date was specified, go with today */
982 localtime_r(&now, &tm);
983 year = tm.tm_year + 1900;
984 month = tm.tm_mon + 1;
987 /** Now see if a date was specified */
988 if (!IsEmptyStr(bstr("year"))) year = atoi(bstr("year"));
989 if (!IsEmptyStr(bstr("month"))) month = atoi(bstr("month"));
990 if (!IsEmptyStr(bstr("day"))) day = atoi(bstr("day"));
992 /** How would you like that cooked? */
993 if (!IsEmptyStr(bstr("calview"))) {
994 strcpy(calview, bstr("calview"));
997 strcpy(calview, "month");
1000 /** Display the selected view */
1001 if (!strcasecmp(calview, "day")) {
1002 calendar_day_view(year, month, day);
1004 else if (!strcasecmp(calview, "week")) {
1005 calendar_week_view(year, month, day);
1008 if (WC->wc_view == VIEW_CALBRIEF) {
1009 calendar_brief_month_view(year, month, day);
1012 calendar_month_view(year, month, day);
1016 /** Free the calendar stuff */
1017 free_calendar_buffer();
1023 * \brief get task due date
1024 * Helper function for do_tasks_view().
1025 * \param vtodo a task to get the due date
1026 * \return the date/time due.
1028 time_t get_task_due_date(icalcomponent *vtodo) {
1031 if (vtodo == NULL) {
1036 * If we're looking at a fully encapsulated VCALENDAR
1037 * rather than a VTODO component, recurse into the data
1038 * structure until we get a VTODO.
1040 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1041 return get_task_due_date(
1042 icalcomponent_get_first_component(
1043 vtodo, ICAL_VTODO_COMPONENT
1048 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1050 return(icaltime_as_timet(icalproperty_get_due(p)));
1059 * \brief Compare the due dates of two tasks (this is for sorting)
1060 * \param task1 first task to compare
1061 * \param task2 second task to compare
1063 int task_due_cmp(const void *task1, const void *task2) {
1067 t1 = get_task_due_date(((struct disp_cal *)task1)->cal);
1068 t2 = get_task_due_date(((struct disp_cal *)task2)->cal);
1070 if (t1 < t2) return(-1);
1071 if (t1 > t2) return(1);
1079 * \brief do the whole task view stuff
1081 void do_tasks_view(void) {
1088 wprintf("<div class=\"fix_scrollbar_bug\">"
1089 "<table class=\"calendar_view_background\">\n<tr>\n"
1091 wprintf(_("Name of task"));
1092 wprintf("</th><th>");
1093 wprintf(_("Date due"));
1094 wprintf("</th></tr>\n"
1097 /** Sort them if necessary */
1098 if (WC->num_cal > 1) {
1101 sizeof(struct disp_cal),
1106 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1109 wprintf("<tr bgcolor=\"#%s\"><td>",
1110 (bg ? "DDDDDD" : "FFFFFF")
1113 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1114 ICAL_SUMMARY_PROPERTY);
1115 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1116 WC->disp_cal[i].cal_msgnum );
1117 urlescputs(WC->wc_roomname);
1119 wprintf("<img align=middle "
1120 "src=\"static/taskmanag_16x.gif\" border=0> ");
1122 escputs((char *)icalproperty_get_comment(p));
1127 due = get_task_due_date(WC->disp_cal[i].cal);
1128 fmt_date(buf, due, 0);
1129 wprintf("<td><font");
1130 if (due < time(NULL)) {
1131 wprintf(" color=\"#FF0000\"");
1133 wprintf(">%s</font></td></tr>\n", buf);
1136 wprintf("</table></div>\n");
1138 /** Free the list */
1139 free_calendar_buffer();
1143 #else /* WEBCIT_WITH_CALENDAR_SERVICE */
1145 /**\brief stub for non-libical builds */
1146 void do_calendar_view(void) {
1147 wprintf("<center><i>");
1148 wprintf(_("The calendar view is not available."));
1149 wprintf("</i></center><br />\n");
1152 /**\brief stub for non-libical builds */
1153 void do_tasks_view(void) {
1154 wprintf("<center><I>");
1155 wprintf(_("The tasks view is not available."));
1156 wprintf("</i></center><br />\n");
1160 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */