5 * \defgroup CalHtmlHandles Handles the HTML display of calendar items.
10 #include "webserver.h"
12 #ifndef WEBCIT_WITH_CALENDAR_SERVICE
14 /**\brief stub for non-libical builds */
15 void do_calendar_view(void) {
16 wprintf("<center><i>");
17 wprintf(_("The calendar view is not available."));
18 wprintf("</i></center><br />\n");
21 /**\brief stub for non-libical builds */
22 void do_tasks_view(void) {
23 wprintf("<center><I>");
24 wprintf(_("The tasks view is not available."));
25 wprintf("</i></center><br />\n");
28 #else /* WEBCIT_WITH_CALENDAR_SERVICE */
30 /****************************************************************************/
33 * \brief Display one day of a whole month view of a calendar
34 * \param thetime the month we want to see
36 void calendar_month_view_display_events(time_t thetime) {
43 icalproperty *p = NULL;
44 icalproperty *pe = NULL;
45 icalproperty *q = NULL;
46 struct icaltimetype t;
48 int all_day_event = 0;
52 if (WC->num_cal == 0) {
53 wprintf("<br /><br /><br />\n");
57 localtime_r(&thetime, &today_tm);
58 month = today_tm.tm_mon + 1;
59 day = today_tm.tm_mday;
60 year = today_tm.tm_year + 1900;
62 for (i=0; i<(WC->num_cal); ++i) {
63 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
64 ICAL_DTSTART_PROPERTY);
65 pe = icalcomponent_get_first_property(WC->disp_cal[i].cal,
68 t = icalproperty_get_dtstart(p);
69 event_tt = icaltime_as_timet(t);
71 if (t.is_date) all_day_event = 1;
72 else all_day_event = 0;
75 gmtime_r(&event_tt, &event_tm);
76 gmtime_r(&event_tt, &event_te);// allday events don't have end-dates.
79 localtime_r(&event_tt, &event_tm);
82 t = icalproperty_get_dtend(pe);
83 event_tte = icaltime_as_timet(t);
84 localtime_r(&event_tte, &event_te);
87 localtime_r(&event_tt, &event_te);
90 if ((event_tm.tm_year <= today_tm.tm_year)
91 && (event_tm.tm_mon <= today_tm.tm_mon)
92 && (event_tm.tm_mday <= today_tm.tm_mday)
93 && (event_te.tm_year >= today_tm.tm_year)
94 && (event_te.tm_mon >= today_tm.tm_mon)
95 && (event_te.tm_mday >= today_tm.tm_mday)) {
97 p = icalcomponent_get_first_property(
99 ICAL_SUMMARY_PROPERTY);
103 wprintf("<table border=0 cellpadding=2><TR>"
104 "<td bgcolor=\"#CCCCDD\">"
108 wprintf("<font size=-1>"
109 "<a href=\"display_edit_event?"
110 "msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\""
112 WC->disp_cal[i].cal_msgnum,
119 wprintf("<i>%s</i> ", _("Summary:"));
120 escputs((char *)icalproperty_get_comment(p));
123 q = icalcomponent_get_first_property(
125 ICAL_LOCATION_PROPERTY);
127 wprintf("<i>%s</i> ", _("Location:"));
128 escputs((char *)icalproperty_get_comment(q));
133 * Only show start/end times if we're actually looking at the VEVENT
134 * component. Otherwise it shows bogus dates for e.g. timezones
136 if (icalcomponent_isa(WC->disp_cal[i].cal) == ICAL_VEVENT_COMPONENT) {
138 q = icalcomponent_get_first_property(WC->disp_cal[i].cal,
139 ICAL_DTSTART_PROPERTY);
141 t = icalproperty_get_dtstart(q);
146 memset(&d_tm, 0, sizeof d_tm);
147 d_tm.tm_year = t.year - 1900;
148 d_tm.tm_mon = t.month - 1;
149 d_tm.tm_mday = t.day;
150 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
151 wprintf("<i>%s</i> %s<br>",
155 tt = icaltime_as_timet(t);
156 fmt_date(buf, tt, 1);
157 wprintf("<i>%s</i> %s<br>",
158 _("Starting date/time:"), buf);
160 /* Embed the 'show end date/time' loop inside here so it
161 * only executes if this is NOT an all day event.
163 q = icalcomponent_get_first_property(WC->disp_cal[i].cal,
164 ICAL_DTEND_PROPERTY);
166 t = icalproperty_get_dtend(q);
167 tt = icaltime_as_timet(t);
168 fmt_date(buf, tt, 1);
169 wprintf("<i>%s</i> %s<br>",
170 _("Ending date/time:"), buf);
178 q = icalcomponent_get_first_property(
180 ICAL_DESCRIPTION_PROPERTY);
182 wprintf("<i>%s</i> ", _("Notes:"));
183 escputs((char *)icalproperty_get_comment(q));
189 icalproperty_get_comment(p));
190 wprintf("</a></font><br />\n");
193 wprintf("</td></tr></table>");
207 * \brief Display one day of a whole month view of a calendar
208 * \param thetime the month we want to see
210 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
220 struct icaltimetype t;
221 int month, day, year;
222 int all_day_event = 0;
226 time_format = get_time_format_cached ();
228 if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
229 else timeformat="%I:%M %p";
231 localtime_r(&thetime, &today_tm);
232 month = today_tm.tm_mon + 1;
233 day = today_tm.tm_mday;
234 year = today_tm.tm_year + 1900;
236 for (i=0; i<(WC->num_cal); ++i) {
237 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
238 ICAL_DTSTART_PROPERTY);
240 t = icalproperty_get_dtstart(p);
241 event_tt = icaltime_as_timet(t);
243 if (t.is_date) all_day_event = 1;
244 else all_day_event = 0;
247 gmtime_r(&event_tts, &event_tms);
250 localtime_r(&event_tts, &event_tms);
252 /** \todo epoch &! daymask */
253 if ((event_tms.tm_year == today_tm.tm_year)
254 && (event_tms.tm_mon == today_tm.tm_mon)
255 && (event_tms.tm_mday == today_tm.tm_mday)) {
261 p = icalcomponent_get_first_property(
263 ICAL_SUMMARY_PROPERTY);
264 e = icalcomponent_get_first_property(
266 ICAL_DTEND_PROPERTY);
267 if ((p != NULL) && (e != NULL)) {
270 t = icalproperty_get_dtend(e);
271 event_tte = icaltime_as_timet(t);
272 localtime_r(&event_tte, &event_tme);
273 difftime=(event_tte-event_tts)/60;
274 hours=(int)(difftime / 60);
275 minutes=difftime % 60;
276 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
278 "<a href=\"display_edit_event?msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\">",
282 WC->disp_cal[i].cal_msgnum,
290 icalproperty_get_comment(p));
291 /** \todo: allso ammitime format */
292 wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
293 wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
295 wprintf("</a></font></td>"
296 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
313 * \brief view one month. pretty view
314 * \param year the year
315 * \param month the month
316 * \param day the actual day we want to see
318 void calendar_month_view(int year, int month, int day) {
319 struct tm starting_tm;
323 time_t previous_month;
325 time_t colheader_time;
326 struct tm colheader_tm;
327 char colheader_label[32];
330 /** Determine what day to start.
331 * First, back up to the 1st of the month...
333 memset(&starting_tm, 0, sizeof(struct tm));
334 starting_tm.tm_year = year - 1900;
335 starting_tm.tm_mon = month - 1;
336 starting_tm.tm_mday = day;
337 thetime = mktime(&starting_tm);
339 memcpy(&tm, &starting_tm, sizeof(struct tm));
340 while (tm.tm_mday != 1) {
341 thetime = thetime - (time_t)86400; /* go back 24 hours */
342 localtime_r(&thetime, &tm);
345 /** Determine previous and next months ... for links */
346 previous_month = thetime - (time_t)864000L; /* back 10 days */
347 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
349 /** Now back up until we're on a Sunday */
350 localtime_r(&thetime, &tm);
351 while (tm.tm_wday != 0) {
352 thetime = thetime - (time_t)86400; /* go back 24 hours */
353 localtime_r(&thetime, &tm);
356 /** Outer table (to get the background color) */
357 wprintf("<div class=\"fix_scrollbar_bug\">"
358 "<table class=\"calendar\"> \n <tr><td>");
360 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
362 wprintf("<td align=center>");
364 localtime_r(&previous_month, &tm);
365 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
366 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
367 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
369 wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
370 wprintf(" "
371 "<font size=+1 color=\"#FFFFFF\">"
374 " ", colheader_label, year);
376 localtime_r(&next_month, &tm);
377 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
378 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
379 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
381 wprintf("</td></tr></table>\n");
383 /** Inner table (the real one) */
384 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
385 "bgcolor=#204B78 id=\"inner_month\"><tr>");
386 colheader_time = thetime;
387 for (i=0; i<7; ++i) {
388 colheader_time = thetime + (i * 86400) ;
389 localtime_r(&colheader_time, &colheader_tm);
390 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
391 wprintf("<td align=center width=14%%>"
392 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
398 /** Now do 35 or 42 days */
399 for (i = 0; i < 42; ++i) {
400 localtime_r(&thetime, &tm);
402 if ((i < 35) || (chg_month == 0)) {
404 if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) {
411 /** Before displaying Sunday, start a new row */
416 wprintf("<td class=\"cal%s\"><div class=\"day\">",
417 ((tm.tm_mon != month-1) ? "out" :
418 ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
421 if ((i==0) || (tm.tm_mday == 1)) {
422 wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
423 wprintf("%s ", colheader_label);
425 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
432 /** put the data here, stupid */
433 calendar_month_view_display_events(thetime);
437 /** After displaying Saturday, end the row */
444 thetime += (time_t)86400; /** ahead 24 hours */
447 wprintf("</table>" /** end of inner table */
448 "</td></tr></table>" /** end of outer table */
452 * Initialize the bubble tooltips.
454 * Yes, this is as stupid as it looks. Instead of just making the call
455 * to btt_enableTooltips() straight away, we have to create a timer event
456 * and let it initialize as an event after 1 millisecond. This is to
457 * work around a bug in Internet Explorer that causes it to crash if we
458 * manipulate the innerHTML of various DOM nodes while the page is still
459 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
460 * for more information.
462 wprintf("<script type=\"text/javascript\">"
463 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
469 * \brief view one month. brief view
470 * \param year the year
471 * \param month the month
472 * \param day the actual day we want to see
474 void calendar_brief_month_view(int year, int month, int day) {
475 struct tm starting_tm;
479 time_t previous_month;
481 char month_label[32];
483 /** Determine what day to start.
484 * First, back up to the 1st of the month...
486 memset(&starting_tm, 0, sizeof(struct tm));
487 starting_tm.tm_year = year - 1900;
488 starting_tm.tm_mon = month - 1;
489 starting_tm.tm_mday = day;
490 thetime = mktime(&starting_tm);
492 memcpy(&tm, &starting_tm, sizeof(struct tm));
493 while (tm.tm_mday != 1) {
494 thetime = thetime - (time_t)86400; /* go back 24 hours */
495 localtime_r(&thetime, &tm);
498 /** Determine previous and next months ... for links */
499 previous_month = thetime - (time_t)864000L; /* back 10 days */
500 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
502 /** Now back up until we're on a Sunday */
503 localtime_r(&thetime, &tm);
504 while (tm.tm_wday != 0) {
505 thetime = thetime - (time_t)86400; /* go back 24 hours */
506 localtime_r(&thetime, &tm);
509 /** Outer table (to get the background color) */
510 wprintf("<div class=\"fix_scrollbar_bug\">"
511 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
512 "bgcolor=#204B78><TR><TD>\n");
514 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
516 wprintf("<td align=center>");
518 localtime_r(&previous_month, &tm);
519 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
520 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
521 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
523 wc_strftime(month_label, sizeof month_label, "%B", &tm);
524 wprintf(" "
525 "<font size=+1 color=\"#FFFFFF\">"
528 " ", month_label, year);
530 localtime_r(&next_month, &tm);
531 wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
532 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
533 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
535 wprintf("</td></tr></table>\n");
537 /** Inner table (the real one) */
538 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
539 "bgcolor=#EEEECC><TR>");
541 wprintf("<tr><td colspan=\"100%\">\n");
543 /** Now do 35 days */
544 for (i = 0; i < 35; ++i) {
545 char weeknumber[255];
546 char weekday_name[32];
548 localtime_r(&thetime, &tm);
551 /** Before displaying Sunday, start a new CELL */
553 wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
554 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
555 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
565 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
566 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
570 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
571 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
572 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
574 weekday_name,tm.tm_mday,
577 /** put the data of one day here, stupid */
578 calendar_month_view_brief_events(thetime, daycolor);
581 /** After displaying Saturday, end the row */
583 wprintf("</td></tr></table>\n");
586 thetime += (time_t)86400; /** ahead 24 hours */
589 wprintf("</table>" /** end of inner table */
590 "</td></tr></table>" /** end of outer table */
595 * \brief view one week
596 * this should view just one week, but it's not here yet.
597 * \todo ny implemented
598 * \param year the year
599 * \param month the month
600 * \param day the day which we want to see the week around
602 void calendar_week_view(int year, int month, int day) {
603 wprintf("<center><i>week view FIXME</i></center><br />\n");
608 * \brief display one day
609 * Display events for a particular hour of a particular day.
610 * (Specify hour < 0 to show "all day" events)
611 * \param year the year
612 * \param month the month
614 * \param hour the hour we want to start displaying?????
616 void calendar_day_view_display_events(int year, int month,
620 icalproperty *pe = NULL;
621 struct icaltimetype t;
622 struct icaltimetype te;
627 int all_day_event = 0;
629 if (WC->num_cal == 0) {
630 // \todo FIXME wprintf("<br /><br /><br />\n");
634 for (i=0; i<(WC->num_cal); ++i) {
635 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
636 ICAL_DTSTART_PROPERTY);
637 pe = icalcomponent_get_first_property(WC->disp_cal[i].cal,
638 ICAL_DTEND_PROPERTY);
640 t = icalproperty_get_dtstart(p);
641 event_tt = icaltime_as_timet(t);
650 gmtime_r(&event_tt, &event_tm);
651 gmtime_r(&event_tt, &event_te);
654 localtime_r(&event_tt, &event_tm);
657 te = icalproperty_get_dtend(pe);
658 event_tte = icaltime_as_timet(te);
659 localtime_r(&event_tte, &event_te);
662 localtime_r(&event_tt, &event_te);
665 if (((event_tm.tm_year <= (year-1900))
666 && (event_tm.tm_mon <= (month-1))
667 && (event_tm.tm_mday <= day)
668 && (event_te.tm_year >= (year-1900))
669 && (event_te.tm_mon >= (month-1))
670 && (event_te.tm_mday >= day))
672 // are we in the start hour?
673 ((event_tm.tm_mday == day)
674 && (event_tm.tm_hour == hour)
676 // are we an all day event?
677 || ((hour<0)&&(t.is_date))
678 // does it span multible days and we're not at the start day?
680 && (event_tm.tm_mday < day)
681 && (event_te.tm_mday >= day))
684 p = icalcomponent_get_first_property(
686 ICAL_SUMMARY_PROPERTY);
690 wprintf("<table border=1 cellpadding=2><TR>"
691 "<td bgcolor=\"#CCCCCC\">"
695 wprintf("<font size=-1>"
696 "<a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d\">",
697 WC->disp_cal[i].cal_msgnum,
701 icalproperty_get_comment(p));
702 wprintf("</a></font><br />\n");
705 wprintf("</td></tr></table>");
718 * \brief view one day
719 * \param year the year
720 * \param month the month
721 * \param day the day we want to display
723 void calendar_day_view(int year, int month, int day) {
725 struct icaltimetype today, yesterday, tomorrow;
728 char daystart_str[16], dayend_str[16];
733 time_format = get_time_format_cached ();
734 get_preference("daystart", daystart_str, sizeof daystart_str);
735 if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
736 get_preference("dayend", dayend_str, sizeof dayend_str);
737 if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str);
740 /** Figure out the dates for "yesterday" and "tomorrow" links */
742 memset(&today, 0, sizeof(struct icaltimetype));
748 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
750 yesterday = icaltime_normalize(yesterday);
752 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
754 tomorrow = icaltime_normalize(tomorrow);
757 /** Outer table (to get the background color) */
758 wprintf("<div class=\"fix_scrollbar_bug\">"
759 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
760 "bgcolor=#204B78><tr><td>\n");
762 /** Inner table (the real one) */
763 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
764 "bgcolor=#204B78><tr>\n");
766 /** Innermost table (contains hours etc.) */
767 wprintf("<td width=80%%>"
768 "<table width=100%% border=0 cellpadding=1 cellspacing=1 "
769 "bgcolor=#204B78>\n");
771 /** Display events before 8:00 (hour=-1 is all-day events) */
773 "<td bgcolor=\"#CCCCDD\" valign=middle width=10%%></td>"
774 "<td bgcolor=\"#FFFFFF\" valign=top>");
775 for (hour = (-1); hour <= (daystart-1); ++hour) {
776 calendar_day_view_display_events(year, month, day, hour);
778 wprintf("</td></tr>\n");
780 /** Now the middle of the day... */
781 for (hour = daystart; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
782 wprintf("<tr height=30><td bgcolor=\"#CCCCDD\" align=middle "
783 "valign=middle width=10%%>");
784 wprintf("<a href=\"display_edit_event?msgnum=0"
785 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
786 year, month, day, hour
789 if (time_format == WC_TIMEFORMAT_24) {
790 wprintf("%2d:00</a> ", hour);
793 wprintf("%d:00%s</a> ",
794 (hour <= 12 ? hour : hour-12),
795 (hour < 12 ? "am" : "pm")
799 wprintf("</td><td bgcolor=\"#FFFFFF\" valign=top>");
801 /* put the data here, stupid */
802 calendar_day_view_display_events(year, month, day, hour);
804 wprintf("</td></tr>\n");
807 /** Display events after 5:00... */
809 "<td bgcolor=\"#CCCCDD\" valign=middle width=10%%></td>"
810 "<td bgcolor=\"#FFFFFF\" valign=top>");
811 for (hour = (dayend+1); hour <= 23; ++hour) {
812 calendar_day_view_display_events(year, month, day, hour);
814 wprintf("</td></tr>\n");
817 wprintf("</table>" /* end of innermost table */
821 wprintf("<td width=20%% valign=top>"); /* begin stuff-on-the-right */
824 /** Begin todays-date-with-left-and-right-arrows */
825 wprintf("<table border=0 width=100%% "
826 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
830 wprintf("<td align=center>");
831 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
832 yesterday.year, yesterday.month, yesterday.day);
833 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
837 memset(&d_tm, 0, sizeof d_tm);
838 d_tm.tm_year = year - 1900;
839 d_tm.tm_mon = month - 1;
841 wc_strftime(d_str, sizeof d_str,
843 "<font size=+2>%B</font><br />"
844 "<font size=+3>%d</font><br />"
845 "<font size=+2>%Y</font><br />"
849 wprintf("%s", d_str);
852 wprintf("<td align=center>");
853 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
854 tomorrow.year, tomorrow.month, tomorrow.day);
855 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
859 wprintf("</tr></table>\n");
860 /** End todays-date-with-left-and-right-arrows */
862 /** \todo In the future we might want to put a month-o-matic here */
864 wprintf("</font></center>\n");
866 wprintf("</td>"); /** end stuff-on-the-right */
870 wprintf("</tr></table>" /** end of inner table */
871 "</td></tr></table></div>" /** end of outer table */
879 * \brief Display today's events.
881 void calendar_summary_view(void) {
884 struct icaltimetype t;
889 int all_day_event = 0;
890 char timestring[SIZ];
892 if (WC->num_cal == 0) {
897 localtime_r(&now, &today_tm);
899 for (i=0; i<(WC->num_cal); ++i) {
900 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
901 ICAL_DTSTART_PROPERTY);
903 t = icalproperty_get_dtstart(p);
904 event_tt = icaltime_as_timet(t);
911 fmt_time(timestring, event_tt);
914 gmtime_r(&event_tt, &event_tm);
917 localtime_r(&event_tt, &event_tm);
920 if ( (event_tm.tm_year == today_tm.tm_year)
921 && (event_tm.tm_mon == today_tm.tm_mon)
922 && (event_tm.tm_mday == today_tm.tm_mday)
926 p = icalcomponent_get_first_property(
928 ICAL_SUMMARY_PROPERTY);
931 icalproperty_get_comment(p));
932 wprintf(" (%s)<br />\n", timestring);
937 free_calendar_buffer();
942 * \brief clean up ical memory
943 * \todo this could get troubel with future ical versions
945 void free_calendar_buffer(void) {
947 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
948 icalcomponent_free(WC->disp_cal[i].cal);
958 * \brief do the whole calendar page
959 * view any part of the calender. decide which way, etc.
961 void do_calendar_view(void) {
964 int year, month, day;
967 /** In case no date was specified, go with today */
969 localtime_r(&now, &tm);
970 year = tm.tm_year + 1900;
971 month = tm.tm_mon + 1;
974 /** Now see if a date was specified */
975 if (!IsEmptyStr(bstr("year"))) year = atoi(bstr("year"));
976 if (!IsEmptyStr(bstr("month"))) month = atoi(bstr("month"));
977 if (!IsEmptyStr(bstr("day"))) day = atoi(bstr("day"));
979 /** How would you like that cooked? */
980 if (!IsEmptyStr(bstr("calview"))) {
981 strcpy(calview, bstr("calview"));
984 strcpy(calview, "month");
987 /** Display the selected view */
988 if (!strcasecmp(calview, "day")) {
989 calendar_day_view(year, month, day);
991 else if (!strcasecmp(calview, "week")) {
992 calendar_week_view(year, month, day);
995 if (WC->wc_view == VIEW_CALBRIEF) {
996 calendar_brief_month_view(year, month, day);
999 calendar_month_view(year, month, day);
1003 /** Free the calendar stuff */
1004 free_calendar_buffer();
1010 * \brief get task due date
1011 * Helper function for do_tasks_view().
1012 * \param vtodo a task to get the due date
1013 * \return the date/time due.
1015 time_t get_task_due_date(icalcomponent *vtodo) {
1018 if (vtodo == NULL) {
1023 * If we're looking at a fully encapsulated VCALENDAR
1024 * rather than a VTODO component, recurse into the data
1025 * structure until we get a VTODO.
1027 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
1028 return get_task_due_date(
1029 icalcomponent_get_first_component(
1030 vtodo, ICAL_VTODO_COMPONENT
1035 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
1037 return(icaltime_as_timet(icalproperty_get_due(p)));
1046 * \brief Compare the due dates of two tasks (this is for sorting)
1047 * \param task1 first task to compare
1048 * \param task2 second task to compare
1050 int task_due_cmp(const void *task1, const void *task2) {
1054 t1 = get_task_due_date(((struct disp_cal *)task1)->cal);
1055 t2 = get_task_due_date(((struct disp_cal *)task2)->cal);
1057 if (t1 < t2) return(-1);
1058 if (t1 > t2) return(1);
1066 * \brief do the whole task view stuff
1068 void do_tasks_view(void) {
1075 wprintf("<div class=\"fix_scrollbar_bug\">"
1076 "<table class=\"calendar_view_background\">\n<tr>\n"
1078 wprintf(_("Name of task"));
1079 wprintf("</th><th>");
1080 wprintf(_("Date due"));
1081 wprintf("</th></tr>\n"
1084 /** Sort them if necessary */
1085 if (WC->num_cal > 1) {
1088 sizeof(struct disp_cal),
1093 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
1096 wprintf("<tr bgcolor=\"#%s\"><td>",
1097 (bg ? "DDDDDD" : "FFFFFF")
1100 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
1101 ICAL_SUMMARY_PROPERTY);
1102 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
1103 WC->disp_cal[i].cal_msgnum );
1104 urlescputs(WC->wc_roomname);
1106 wprintf("<img align=middle "
1107 "src=\"static/taskmanag_16x.gif\" border=0> ");
1109 escputs((char *)icalproperty_get_comment(p));
1114 due = get_task_due_date(WC->disp_cal[i].cal);
1115 fmt_date(buf, due, 0);
1116 wprintf("<td><font");
1117 if (due < time(NULL)) {
1118 wprintf(" color=\"#FF0000\"");
1120 wprintf(">%s</font></td></tr>\n", buf);
1123 wprintf("</table></div>\n");
1125 /** Free the list */
1126 free_calendar_buffer();
1130 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */