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(time_t thetime) {
23 icalproperty *p = NULL;
24 icalproperty *q = NULL;
25 struct icaltimetype t;
27 int all_day_event = 0;
28 int multi_day_event = 0;
29 int fill_day_event = 0;
33 struct wcsession *WCC;
38 if (WCC->num_cal == 0) {
39 wprintf("<br /><br /><br />\n");
43 localtime_r(&thetime, &today_tm);
44 month = today_tm.tm_mon + 1;
45 day = today_tm.tm_mday;
46 year = today_tm.tm_year + 1900;
48 for (i=0; i<(WCC->num_cal); ++i) {
52 Cal = &WCC->disp_cal[i];
53 all_day_event = Cal->start_hour == -1;
54 show_event = thetime == Cal->start_day;
56 if (Cal->multi_day_event) {
58 // are we in the range of the event?
59 show_event = (Cal->start_day <= thetime) &&
60 (Cal->end_day >= thetime);
62 // are we not start or end day?
63 fill_day_event = (Cal->start_day < thetime) &&
64 (Cal->end_day > thetime);
68 p = icalcomponent_get_first_property(
70 ICAL_SUMMARY_PROPERTY);
74 wprintf("<table border=0 cellpadding=2><TR>"
75 "<td bgcolor=\"#CCCCDD\">"
79 wprintf("<font size=-1>"
80 "<a href=\"display_edit_event?"
81 "msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\""
83 WC->disp_cal[i].cal_msgnum,
90 wprintf("<i>%s</i> ", _("Summary:"));
91 escputs((char *)icalproperty_get_comment(p));
94 q = icalcomponent_get_first_property(
96 ICAL_LOCATION_PROPERTY);
98 wprintf("<i>%s</i> ", _("Location:"));
99 escputs((char *)icalproperty_get_comment(q));
104 * Only show start/end times if we're actually looking at the VEVENT
105 * component. Otherwise it shows bogus dates for e.g. timezones
107 if (icalcomponent_isa(Cal->cal) == ICAL_VEVENT_COMPONENT) {
109 q = icalcomponent_get_first_property(Cal->cal,
110 ICAL_DTSTART_PROPERTY);
112 t = icalproperty_get_dtstart(q);
117 memset(&d_tm, 0, sizeof d_tm);
118 d_tm.tm_year = t.year - 1900;
119 d_tm.tm_mon = t.month - 1;
120 d_tm.tm_mday = t.day;
121 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
122 wprintf("<i>%s</i> %s<br>",
126 tt = icaltime_as_timet(t);
127 fmt_date(buf, tt, 1);
128 wprintf("<i>%s</i> %s<br>",
129 _("Starting date/time:"), buf);
131 /* Embed the 'show end date/time' loop inside here so it
132 * only executes if this is NOT an all day event.
134 q = icalcomponent_get_first_property(Cal->cal,
135 ICAL_DTEND_PROPERTY);
137 t = icalproperty_get_dtend(q);
138 tt = icaltime_as_timet(t);
139 fmt_date(buf, tt, 1);
140 wprintf("<i>%s</i> %s<br>",
141 _("Ending date/time:"), buf);
149 q = icalcomponent_get_first_property(
151 ICAL_DESCRIPTION_PROPERTY);
153 wprintf("<i>%s</i> ", _("Notes:"));
154 escputs((char *)icalproperty_get_comment(q));
160 icalproperty_get_comment(p));
161 wprintf("</a></font><br />\n");
164 wprintf("</td></tr></table>");
177 * \brief Display one day of a whole month view of a calendar
178 * \param thetime the month we want to see
180 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
190 struct icaltimetype t;
191 int month, day, year;
192 int all_day_event = 0;
196 time_format = get_time_format_cached ();
198 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
199 else timeformat="%I:%M %p";
201 localtime_r(&thetime, &today_tm);
202 month = today_tm.tm_mon + 1;
203 day = today_tm.tm_mday;
204 year = today_tm.tm_year + 1900;
206 for (i=0; i<(WC->num_cal); ++i) {
207 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
208 ICAL_DTSTART_PROPERTY);
210 t = icalproperty_get_dtstart(p);
211 event_tt = icaltime_as_timet(t);
213 if (t.is_date) all_day_event = 1;
214 else all_day_event = 0;
217 gmtime_r(&event_tts, &event_tms);
220 localtime_r(&event_tts, &event_tms);
222 /** \todo epoch &! daymask */
223 if ((event_tms.tm_year == today_tm.tm_year)
224 && (event_tms.tm_mon == today_tm.tm_mon)
225 && (event_tms.tm_mday == today_tm.tm_mday)) {
231 p = icalcomponent_get_first_property(
233 ICAL_SUMMARY_PROPERTY);
234 e = icalcomponent_get_first_property(
236 ICAL_DTEND_PROPERTY);
237 if ((p != NULL) && (e != NULL)) {
240 t = icalproperty_get_dtend(e);
241 event_tte = icaltime_as_timet(t);
242 localtime_r(&event_tte, &event_tme);
243 difftime=(event_tte-event_tts)/60;
244 hours=(int)(difftime / 60);
245 minutes=difftime % 60;
246 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
248 "<a href=\"display_edit_event?msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\">",
252 WC->disp_cal[i].cal_msgnum,
260 icalproperty_get_comment(p));
261 /** \todo: allso ammitime format */
262 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
263 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
265 wprintf("</a></font></td>"
266 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
283 * \brief view one month. pretty view
284 * \param year the year
285 * \param month the month
286 * \param day the actual day we want to see
288 void calendar_month_view(int year, int month, int day) {
289 struct tm starting_tm;
293 time_t previous_month;
295 time_t colheader_time;
296 struct tm colheader_tm;
297 char colheader_label[32];
300 /** Determine what day to start.
301 * First, back up to the 1st of the month...
303 memset(&starting_tm, 0, sizeof(struct tm));
304 starting_tm.tm_year = year - 1900;
305 starting_tm.tm_mon = month - 1;
306 starting_tm.tm_mday = day;
307 thetime = mktime(&starting_tm);
309 memcpy(&tm, &starting_tm, sizeof(struct tm));
310 while (tm.tm_mday != 1) {
311 thetime = thetime - (time_t)86400; /* go back 24 hours */
312 localtime_r(&thetime, &tm);
315 /** Determine previous and next months ... for links */
316 previous_month = thetime - (time_t)864000L; /* back 10 days */
317 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
319 /** Now back up until we're on a Sunday */
320 localtime_r(&thetime, &tm);
321 while (tm.tm_wday != 0) {
322 thetime = thetime - (time_t)86400; /* go back 24 hours */
323 localtime_r(&thetime, &tm);
326 /** Outer table (to get the background color) */
327 wprintf("<div class=\"fix_scrollbar_bug\">"
328 "<table class=\"calendar\"> \n <tr><td>");
330 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
332 wprintf("<td align=center>");
334 localtime_r(&previous_month, &tm);
335 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
336 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
337 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
339 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
340 wprintf(" "
341 "<font size=+1 color=\"#FFFFFF\">"
344 " ", colheader_label, year);
346 localtime_r(&next_month, &tm);
347 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
348 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
349 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
351 wprintf("</td></tr></table>\n");
353 /** Inner table (the real one) */
354 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
355 "bgcolor=#204B78 id=\"inner_month\"><tr>");
356 colheader_time = thetime;
357 for (i=0; i<7; ++i) {
358 colheader_time = thetime + (i * 86400) ;
359 localtime_r(&colheader_time, &colheader_tm);
360 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
361 wprintf("<td align=center width=14%%>"
362 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
368 /** Now do 35 or 42 days */
369 for (i = 0; i < 42; ++i) {
370 localtime_r(&thetime, &tm);
372 if ((i < 35) || (chg_month == 0)) {
374 if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) {
381 /** Before displaying Sunday, start a new row */
386 wprintf("<td class=\"cal%s\"><div class=\"day\">",
387 ((tm.tm_mon != month-1) ? "out" :
388 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
391 if ((i==0) || (tm.tm_mday == 1)) {
392 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
393 wprintf("%s ", colheader_label);
395 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
402 /** put the data here, stupid */
403 calendar_month_view_display_events(thetime);
407 /** After displaying Saturday, end the row */
414 thetime += (time_t)86400; /** ahead 24 hours */
417 wprintf("</table>" /** end of inner table */
418 "</td></tr></table>" /** end of outer table */
422 * Initialize the bubble tooltips.
424 * Yes, this is as stupid as it looks. Instead of just making the call
425 * to btt_enableTooltips() straight away, we have to create a timer event
426 * and let it initialize as an event after 1 millisecond. This is to
427 * work around a bug in Internet Explorer that causes it to crash if we
428 * manipulate the innerHTML of various DOM nodes while the page is still
429 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
430 * for more information.
432 wprintf("<script type=\"text/javascript\">"
433 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
439 * \brief view one month. brief view
440 * \param year the year
441 * \param month the month
442 * \param day the actual day we want to see
444 void calendar_brief_month_view(int year, int month, int day) {
445 struct tm starting_tm;
449 time_t previous_month;
451 char month_label[32];
453 /** Determine what day to start.
454 * First, back up to the 1st of the month...
456 memset(&starting_tm, 0, sizeof(struct tm));
457 starting_tm.tm_year = year - 1900;
458 starting_tm.tm_mon = month - 1;
459 starting_tm.tm_mday = day;
460 thetime = mktime(&starting_tm);
462 memcpy(&tm, &starting_tm, sizeof(struct tm));
463 while (tm.tm_mday != 1) {
464 thetime = thetime - (time_t)86400; /* go back 24 hours */
465 localtime_r(&thetime, &tm);
468 /** Determine previous and next months ... for links */
469 previous_month = thetime - (time_t)864000L; /* back 10 days */
470 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
472 /** Now back up until we're on a Sunday */
473 localtime_r(&thetime, &tm);
474 while (tm.tm_wday != 0) {
475 thetime = thetime - (time_t)86400; /* go back 24 hours */
476 localtime_r(&thetime, &tm);
479 /** Outer table (to get the background color) */
480 wprintf("<div class=\"fix_scrollbar_bug\">"
481 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
482 "bgcolor=#204B78><TR><TD>\n");
484 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
486 wprintf("<td align=center>");
488 localtime_r(&previous_month, &tm);
489 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
490 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
491 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
493 wc_strftime(month_label, sizeof month_label, "%B", &tm);
494 wprintf(" "
495 "<font size=+1 color=\"#FFFFFF\">"
498 " ", month_label, year);
500 localtime_r(&next_month, &tm);
501 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
502 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
503 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
505 wprintf("</td></tr></table>\n");
507 /** Inner table (the real one) */
508 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
509 "bgcolor=#EEEECC><TR>");
511 wprintf("<tr><td colspan=\"100%\">\n");
513 /** Now do 35 days */
514 for (i = 0; i < 35; ++i) {
515 char weeknumber[255];
516 char weekday_name[32];
518 localtime_r(&thetime, &tm);
521 /** Before displaying Sunday, start a new CELL */
523 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
524 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
525 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
535 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
536 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
540 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
541 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
542 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
544 weekday_name,tm.tm_mday,
547 /** put the data of one day here, stupid */
548 calendar_month_view_brief_events(thetime, daycolor);
551 /** After displaying Saturday, end the row */
553 wprintf("</td></tr></table>\n");
556 thetime += (time_t)86400; /** ahead 24 hours */
559 wprintf("</table>" /** end of inner table */
560 "</td></tr></table>" /** end of outer table */
565 * \brief view one week
566 * this should view just one week, but it's not here yet.
567 * \todo ny implemented
568 * \param year the year
569 * \param month the month
570 * \param day the day which we want to see the week around
572 void calendar_week_view(int year, int month, int day) {
573 wprintf("<center><i>week view FIXME</i></center><br />\n");
578 * \brief display one day
579 * Display events for a particular hour of a particular day.
580 * (Specify hour < 0 to show "all day" events)
581 * \param year the year
582 * \param month the month
584 * \param hour the hour we want to start displaying
585 * \param inner a flag to display between daystart and dayend
586 * (Specify inner to 1 to show inner events)
587 * (Specify inner to 0 to show "all day events and events after dayend)
588 * \param dstart daystart
590 void calendar_day_view_display_events(time_t thetime, int year, int month,
592 int inner, int dstart) {
602 int all_day_event = 0;
603 struct wcsession *WCC;
604 struct disp_cal *Cal;
608 if (WCC->num_cal == 0) {
609 // \todo FIXME wprintf("<br /><br /><br />\n");
613 event_start = thetime + 60 * 60 * hour;
614 event_end = thetime + 60 * 60 * (hour + 1);
616 for (i=0; i<(WCC->num_cal); ++i) {
617 Cal = &WCC->disp_cal[i];
618 all_day_event = Cal->start_hour == -1;
621 if (! all_day_event && inner)
623 show_event = (thetime == Cal->start_day) &&
624 (event_start <= Cal->start_hour) &&
625 ((Cal->end_hour != -1)?
626 (Cal->end_hour < event_end) : 1);
631 show_event = !inner && (Cal->start_day == thetime);
634 p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
635 if ((show_event) && (p != NULL)) {
637 wprintf("<dd><a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
638 Cal->cal_msgnum,year, month, day, hour);
639 escputs((char *) icalproperty_get_comment(p));
640 wprintf("</a></dd>\n");
643 wprintf("<dd class=\"event\" "
644 "style=\"position: absolute; "
645 "top:%dpx; left:100px; "
647 (1 + (event_tm.tm_min / 2) + (event_te.tm_hour - hour) + (hour * 30) - (dstart * 30)),
648 (((event_te.tm_min - event_tm.tm_min) / 2) +(event_te.tm_hour - hour) * 30)
659 wprintf("<a href=\"display_edit_event?"
660 "msgnum=%ld&calview=day&year=%d"
661 "&month=%d&day=%d&hour=%d\""
663 WC->disp_cal[i].cal_msgnum,
664 year, month, day, hour
666 wprintf("<i>%s</i> ", _("Summary:"));
667 escputs((char *)icalproperty_get_comment(p));
670 l = icalcomponent_get_first_property(
672 ICAL_LOCATION_PROPERTY);
674 wprintf("<i>%s</i> ", _("Location:"));
675 escputs((char *)icalproperty_get_comment(l));
678 n = icalcomponent_get_first_property(
680 ICAL_DESCRIPTION_PROPERTY);
682 wprintf("<i>%s</i> ", _("Notes:"));
683 escputs((char *)icalproperty_get_comment(n));
688 icalproperty_get_comment(p));
689 wprintf("</a></dd>\n");
697 /* TODO: whats that? thierry, when do we need to show this?
698 wprintf("<a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
699 WC->disp_cal[i].cal_msgnum,
700 year, month, day, hour
703 icalproperty_get_comment(p));
704 wprintf("</a></dd>\n");
713 * \brief view one day
714 * \param year the year
715 * \param month the month
716 * \param day the day we want to display
718 void calendar_day_view(int year, int month, int day) {
720 struct icaltimetype today, yesterday, tomorrow;
723 char daystart_str[16], dayend_str[16];
729 time_format = get_time_format_cached ();
730 get_preference("daystart", daystart_str, sizeof daystart_str);
731 if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
732 get_preference("dayend", dayend_str, sizeof dayend_str);
733 if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str);
736 memset(&d_tm, 0, sizeof d_tm);
737 d_tm.tm_year = year - 1900;
738 d_tm.tm_mon = month - 1;
740 gmtime_r(&today_t, &d_tm);
742 /** Figure out the dates for "yesterday" and "tomorrow" links */
744 memset(&today, 0, sizeof(struct icaltimetype));
750 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
752 yesterday = icaltime_normalize(yesterday);
754 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
756 tomorrow = icaltime_normalize(tomorrow);
758 wprintf("<div class=\"fix_scrollbar_bug\">");
760 /** Inner table (the real one) */
761 wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
763 /** Innermost cell (contains hours etc.) */
764 wprintf("<td class=\"middle_of_the_day\" >");
769 " position: absolute ; "
773 " clip: rect(0px 500px %dpx 0px);"
774 " clip: rect(0px, 500px, %dpx, 0px);"
776 (dayend - daystart) * 30,
777 (dayend - daystart) * 30
779 /** Now the middle of the day... */
780 for (hour = 0; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
781 if (hour >= daystart) {
782 wprintf("<dt><a href=\"display_edit_event?msgnum=0"
783 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
784 year, month, day, hour
787 if (time_format == WC_TIMEFORMAT_24) {
788 wprintf("%2d:00</a> ", hour);
791 wprintf("%d:00%s</a> ",
792 (hour <= 12 ? hour : hour-12),
793 (hour < 12 ? "am" : "pm")
800 /* put the data here, stupid */
801 calendar_day_view_display_events(today_t, year, month, day, hour, 1 , daystart);
806 wprintf("</td>"); /* end of innermost table */
808 /** Extra events on the middle */
809 wprintf("<td class=\"extra_events\">");
813 /** Display all-day events) */
814 wprintf("<dt>All day events</dt>");
815 calendar_day_view_display_events(today_t, year, month, day, -1, 0 , daystart);
817 /** Display events before daystart */
818 wprintf("<dt>Before day start</dt>");
819 for (hour = 0; hour <= (daystart-1); ++hour) {
820 calendar_day_view_display_events(today_t, year, month, day, hour, 0, daystart );
823 /** Display events after dayend... */
824 wprintf("<dt>After</dt>");
825 for (hour = (dayend+1); hour <= 23; ++hour) {
826 calendar_day_view_display_events(today_t, year, month, day, hour, 0, daystart );
831 wprintf("</td>"); /** end extra on the middle */
833 wprintf("<td width=20%% valign=top>"); /** begin stuff-on-the-right */
835 /** Begin todays-date-with-left-and-right-arrows */
836 wprintf("<table border=0 width=100%% "
837 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
841 wprintf("<td align=center>");
842 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
843 yesterday.year, yesterday.month, yesterday.day);
844 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
847 wc_strftime(d_str, sizeof d_str,
849 "<font size=+2>%B</font><br />"
850 "<font size=+3>%d</font><br />"
851 "<font size=+2>%Y</font><br />"
855 wprintf("%s", d_str);
858 wprintf("<td align=center>");
859 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
860 tomorrow.year, tomorrow.month, tomorrow.day);
861 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
865 wprintf("</tr></table>\n");
866 /** End todays-date-with-left-and-right-arrows */
868 /** \todo In the future we might want to put a month-o-matic here */
870 wprintf("</font></center>\n");
872 wprintf("</td></tr>"); /** end stuff-on-the-right */
874 wprintf("</table>" /** end of inner table */
877 wprintf("<script type=\"text/javascript\">"
878 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); "
885 * \brief Display today's events.
887 void calendar_summary_view(void) {
890 struct icaltimetype t;
895 int all_day_event = 0;
896 char timestring[SIZ];
898 if (WC->num_cal == 0) {
903 localtime_r(&now, &today_tm);
905 for (i=0; i<(WC->num_cal); ++i) {
906 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
907 ICAL_DTSTART_PROPERTY);
909 t = icalproperty_get_dtstart(p);
910 event_tt = icaltime_as_timet(t);
917 fmt_time(timestring, event_tt);
920 gmtime_r(&event_tt, &event_tm);
923 localtime_r(&event_tt, &event_tm);
926 if ( (event_tm.tm_year == today_tm.tm_year)
927 && (event_tm.tm_mon == today_tm.tm_mon)
928 && (event_tm.tm_mday == today_tm.tm_mday)
932 p = icalcomponent_get_first_property(
934 ICAL_SUMMARY_PROPERTY);
937 icalproperty_get_comment(p));
938 wprintf(" (%s)<br />\n", timestring);
943 free_calendar_buffer();
948 * \brief clean up ical memory
949 * \todo this could get troubel with future ical versions
951 void free_calendar_buffer(void) {
953 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
954 icalcomponent_free(WC->disp_cal[i].cal);
964 * \brief do the whole calendar page
965 * view any part of the calender. decide which way, etc.
967 void do_calendar_view(void) {
970 int year, month, day;
973 /** In case no date was specified, go with today */
975 localtime_r(&now, &tm);
976 year = tm.tm_year + 1900;
977 month = tm.tm_mon + 1;
980 /** Now see if a date was specified */
981 if (!IsEmptyStr(bstr("year"))) year = atoi(bstr("year"));
982 if (!IsEmptyStr(bstr("month"))) month = atoi(bstr("month"));
983 if (!IsEmptyStr(bstr("day"))) day = atoi(bstr("day"));
985 /** How would you like that cooked? */
986 if (!IsEmptyStr(bstr("calview"))) {
987 strcpy(calview, bstr("calview"));
990 strcpy(calview, "month");
993 /** Display the selected view */
994 if (!strcasecmp(calview, "day")) {
995 calendar_day_view(year, month, day);
997 else if (!strcasecmp(calview, "week")) {
998 calendar_week_view(year, month, day);
1001 if (WC->wc_view == VIEW_CALBRIEF) {
1002 calendar_brief_month_view(year, month, day);
1005 calendar_month_view(year, month, day);
1009 /** Free the calendar stuff */
1010 free_calendar_buffer();
1016 * \brief get task due date
1017 * Helper function for do_tasks_view().
1018 * \param vtodo a task to get the due date
1019 * \return the date/time due.
1021 time_t get_task_due_date(icalcomponent *vtodo) {
1024 if (vtodo == NULL) {
1029 * If we're looking at a fully encapsulated VCALENDAR
1030 * rather than a VTODO component, recurse into the data
1031 * structure until we get a VTODO.
1033 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1034 return get_task_due_date(
1035 icalcomponent_get_first_component(
1036 vtodo, ICAL_VTODO_COMPONENT
1041 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1043 return(icaltime_as_timet(icalproperty_get_due(p)));
1052 * \brief Compare the due dates of two tasks (this is for sorting)
1053 * \param task1 first task to compare
1054 * \param task2 second task to compare
1056 int task_due_cmp(const void *task1, const void *task2) {
1060 t1 = get_task_due_date(((struct disp_cal *)task1)->cal);
1061 t2 = get_task_due_date(((struct disp_cal *)task2)->cal);
1063 if (t1 < t2) return(-1);
1064 if (t1 > t2) return(1);
1072 * \brief do the whole task view stuff
1074 void do_tasks_view(void) {
1081 wprintf("<div class=\"fix_scrollbar_bug\">"
1082 "<table class=\"calendar_view_background\">\n<tr>\n"
1084 wprintf(_("Name of task"));
1085 wprintf("</th><th>");
1086 wprintf(_("Date due"));
1087 wprintf("</th></tr>\n"
1090 /** Sort them if necessary */
1091 if (WC->num_cal > 1) {
1094 sizeof(struct disp_cal),
1099 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1102 wprintf("<tr bgcolor=\"#%s\"><td>",
1103 (bg ? "DDDDDD" : "FFFFFF")
1106 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1107 ICAL_SUMMARY_PROPERTY);
1108 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1109 WC->disp_cal[i].cal_msgnum );
1110 urlescputs(WC->wc_roomname);
1112 wprintf("<img align=middle "
1113 "src=\"static/taskmanag_16x.gif\" border=0> ");
1115 escputs((char *)icalproperty_get_comment(p));
1120 due = get_task_due_date(WC->disp_cal[i].cal);
1121 fmt_date(buf, due, 0);
1122 wprintf("<td><font");
1123 if (due < time(NULL)) {
1124 wprintf(" color=\"#FF0000\"");
1126 wprintf(">%s</font></td></tr>\n", buf);
1129 wprintf("</table></div>\n");
1131 /** Free the list */
1132 free_calendar_buffer();
1136 #else /* WEBCIT_WITH_CALENDAR_SERVICE */
1138 /**\brief stub for non-libical builds */
1139 void do_calendar_view(void) {
1140 wprintf("<center><i>");
1141 wprintf(_("The calendar view is not available."));
1142 wprintf("</i></center><br />\n");
1145 /**\brief stub for non-libical builds */
1146 void do_tasks_view(void) {
1147 wprintf("<center><I>");
1148 wprintf(_("The tasks view is not available."));
1149 wprintf("</i></center><br />\n");
1153 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */