4 * Handles the HTML display of calendar items.
11 void embeddable_mini_calendar(int year
, int month
, char *urlformat
)
13 struct tm starting_tm
;
17 time_t previous_month
;
19 time_t colheader_time
;
20 struct tm colheader_tm
;
21 char colheader_label
[32];
25 char escaped_urlformat
[256];
27 snprintf(div_id
, sizeof div_id
, "mini_calendar_%d", rand() );
29 /* Determine what day to start. If an impossible value is found, start on Sunday.
31 get_pref_long("weekstart", &weekstart
, 17);
32 if (weekstart
> 6) weekstart
= 0;
35 * Now back up to the 1st of the month...
37 memset(&starting_tm
, 0, sizeof(struct tm
));
39 starting_tm
.tm_year
= year
- 1900;
40 starting_tm
.tm_mon
= month
- 1;
41 starting_tm
.tm_mday
= 1;
42 thetime
= mktime(&starting_tm
);
44 memcpy(&tm
, &starting_tm
, sizeof(struct tm
));
45 while (tm
.tm_mday
!= 1) {
46 thetime
= thetime
- (time_t)86400; /* go back 24 hours */
47 localtime_r(&thetime
, &tm
);
50 /* Determine previous and next months ... for links */
51 previous_month
= thetime
- (time_t)864000L; /* back 10 days */
52 next_month
= thetime
+ (time_t)(31L * 86400L); /* ahead 31 days */
54 /* Now back up until we're on the user's preferred start day */
55 localtime_r(&thetime
, &tm
);
56 while (tm
.tm_wday
!= weekstart
) {
57 thetime
= thetime
- (time_t)86400; /* go back 24 hours */
58 localtime_r(&thetime
, &tm
);
61 wprintf("<div class=\"mini_calendar\" id=\"%s\">\n", div_id
);
63 /* Previous month link */
64 localtime_r(&previous_month
, &tm
);
65 wprintf("<a href=\"javascript:minical_change_month(%d,%d);\">«</a>",
66 (int)(tm
.tm_year
)+1900, tm
.tm_mon
+ 1);
68 wc_strftime(colheader_label
, sizeof colheader_label
, "%B", &starting_tm
);
69 wprintf(" "
70 "<span class=\"mini_calendar_month_label\">"
73 " ", colheader_label
, year
);
76 localtime_r(&next_month
, &tm
);
77 wprintf("<a href=\"javascript:minical_change_month(%d,%d);\">»</a>",
78 (int)(tm
.tm_year
)+1900, tm
.tm_mon
+ 1);
80 wprintf("<table border=0 cellpadding=1 cellspacing=1 class=\"mini_calendar_days\">"
82 colheader_time
= thetime
;
84 colheader_time
= thetime
+ (i
* 86400) ;
85 localtime_r(&colheader_time
, &colheader_tm
);
86 wc_strftime(colheader_label
, sizeof colheader_label
, "%A", &colheader_tm
);
87 wprintf("<th>%c</th>", colheader_label
[0]);
93 /* Now do 35 or 42 days */
94 for (i
= 0; i
< 42; ++i
) {
95 localtime_r(&thetime
, &tm
);
99 /* Before displaying Sunday, start a new row */
104 if (tm
.tm_mon
== month
-1) {
105 snprintf(url
, sizeof url
, urlformat
,
106 tm
.tm_year
+1900, tm
.tm_mon
+1, tm
.tm_mday
);
107 wprintf("<td><a href=\"%s\">%d</a></td>", url
, tm
.tm_mday
);
110 wprintf("<td> </td>");
113 /* After displaying one week, end the row */
120 thetime
+= (time_t)86400; /* ahead 24 hours */
123 wprintf("</table>" /* end of inner table */
126 /* javascript for previous and next month */
127 len
= strlen(urlformat
);
128 for (i
=0; i
<len
; ++i
) {
129 sprintf(&escaped_urlformat
[i
*2], "%02X", urlformat
[i
]);
132 StrBufAppendPrintf(WC
->trailing_javascript
,
133 " function minical_change_month(year, month) { \n"
134 " p = 'year=' + year + '&month=' + month \n"
135 " + '&urlformat=%s&r=' + CtdlRandomString(); \n"
136 " new Ajax.Updater('%s', 'mini_calendar', \n"
137 " { method: 'get', parameters: p, evalScripts: true } ); \n"
140 escaped_urlformat
, div_id
146 * ajax embedder for the above mini calendar
148 void ajax_mini_calendar(void) {
151 char *escaped_urlformat
;
153 escaped_urlformat
= bstr("urlformat");
154 len
= strlen(escaped_urlformat
) * 2 ;
155 for (i
=0; i
<len
; ++i
) {
156 urlformat
[i
] = xtoi(&escaped_urlformat
[i
*2], 2);
160 embeddable_mini_calendar( ibstr("year"), ibstr("month"), urlformat
);
165 * Display one day of a whole month view of a calendar
167 void calendar_month_view_display_events(int year
, int month
, int day
)
174 icalproperty
*p
= NULL
;
175 icalproperty
*q
= NULL
;
176 struct icaltimetype t
;
177 struct icaltimetype end_t
;
178 struct icaltimetype today_start_t
;
179 struct icaltimetype today_end_t
;
180 struct tm starting_tm
;
182 int all_day_event
= 0;
188 if (GetCount(WCC
->disp_cal_items
) == 0) {
189 wprintf("<br /><br /><br />\n");
194 * Create an imaginary event which spans the 24 hours of today. Any events which
195 * overlap with this one take place at least partially in this day. We have to
196 * convert it from a struct tm in order to make it UTC.
198 memset(&starting_tm
, 0, sizeof(struct tm
));
199 starting_tm
.tm_year
= year
- 1900;
200 starting_tm
.tm_mon
= month
- 1;
201 starting_tm
.tm_mday
= day
;
202 starting_tm
.tm_hour
= 0;
203 starting_tm
.tm_min
= 0;
204 today_start_t
= icaltime_from_timet_with_zone(mktime(&starting_tm
), 0, icaltimezone_get_utc_timezone());
205 today_start_t
.is_utc
= 1;
207 memset(&ending_tm
, 0, sizeof(struct tm
));
208 ending_tm
.tm_year
= year
- 1900;
209 ending_tm
.tm_mon
= month
- 1;
210 ending_tm
.tm_mday
= day
;
211 ending_tm
.tm_hour
= 23;
212 ending_tm
.tm_min
= 59;
213 today_end_t
= icaltime_from_timet_with_zone(mktime(&ending_tm
), 0, icaltimezone_get_utc_timezone());
214 today_end_t
.is_utc
= 1;
217 * Now loop through our list of events to see which ones occur today.
219 Pos
= GetNewHashPos(WCC
->disp_cal_items
, 0);
220 while (GetNextHashPos(WCC
->disp_cal_items
, Pos
, &hklen
, &HashKey
, &vCal
)) {
221 Cal
= (disp_cal
*)vCal
;
223 q
= icalcomponent_get_first_property(Cal
->cal
, ICAL_DTSTART_PROPERTY
);
225 t
= icalproperty_get_dtstart(q
);
228 memset(&t
, 0, sizeof t
);
230 q
= icalcomponent_get_first_property(Cal
->cal
, ICAL_DTEND_PROPERTY
);
232 end_t
= icalproperty_get_dtend(q
);
235 memset(&end_t
, 0, sizeof end_t
);
237 if (t
.is_date
) all_day_event
= 1;
241 show_event
= ((t
.year
== year
) && (t
.month
== month
) && (t
.day
== day
));
245 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 class=\"event%s\" href=\"display_edit_event?"
263 "msgnum=%ld?calview=month?year=%d?month=%d?day=%d\""
265 (Cal
->unread
)?"_unread":"_read",
270 wprintf("<i>%s: %s</i><br />", _("From"), Cal
->from
);
271 wprintf("<i>%s</i> ", _("Summary:"));
272 escputs((char *)icalproperty_get_comment(p
));
275 q
= icalcomponent_get_first_property(
277 ICAL_LOCATION_PROPERTY
);
279 wprintf("<i>%s</i> ", _("Location:"));
280 escputs((char *)icalproperty_get_comment(q
));
285 * Only show start/end times if we're actually looking at the VEVENT
286 * component. Otherwise it shows bogus dates for e.g. timezones
288 if (icalcomponent_isa(Cal
->cal
) == ICAL_VEVENT_COMPONENT
) {
290 q
= icalcomponent_get_first_property(Cal
->cal
, ICAL_DTSTART_PROPERTY
);
292 t
= icalproperty_get_dtstart(q
);
297 memset(&d_tm
, 0, sizeof d_tm
);
298 d_tm
.tm_year
= t
.year
- 1900;
299 d_tm
.tm_mon
= t
.month
- 1;
300 d_tm
.tm_mday
= t
.day
;
301 wc_strftime(d_str
, sizeof d_str
, "%x", &d_tm
);
302 wprintf("<i>%s</i> %s<br>",
306 tt
= icaltime_as_timet(t
);
307 webcit_fmt_date(buf
, tt
, 1);
308 wprintf("<i>%s</i> %s<br>",
309 _("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 webcit_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>");
355 * Display one day of a whole month view of a calendar
357 void calendar_month_view_brief_events(time_t thetime
, const char *daycolor
) {
371 struct icaltimetype t
;
373 int month
, day
, year
;
374 int all_day_event
= 0;
378 time_format
= get_time_format_cached ();
380 if (time_format
== WC_TIMEFORMAT_24
) timeformat
="%k:%M";
381 else timeformat
="%I:%M %p";
383 localtime_r(&thetime
, &today_tm
);
384 month
= today_tm
.tm_mon
+ 1;
385 day
= today_tm
.tm_mday
;
386 year
= today_tm
.tm_year
+ 1900;
388 Pos
= GetNewHashPos(WCC
->disp_cal_items
, 0);
389 while (GetNextHashPos(WCC
->disp_cal_items
, Pos
, &hklen
, &HashKey
, &vCal
)) {
390 Cal
= (disp_cal
*)vCal
;
391 p
= icalcomponent_get_first_property(Cal
->cal
, ICAL_DTSTART_PROPERTY
);
393 t
= icalproperty_get_dtstart(p
);
394 event_tt
= icaltime_as_timet(t
);
396 if (t
.is_date
) all_day_event
= 1;
397 else all_day_event
= 0;
400 gmtime_r(&event_tts
, &event_tms
);
403 localtime_r(&event_tts
, &event_tms
);
405 /* \todo epoch &! daymask */
406 if ((event_tms
.tm_year
== today_tm
.tm_year
)
407 && (event_tms
.tm_mon
== today_tm
.tm_mon
)
408 && (event_tms
.tm_mday
== today_tm
.tm_mday
)) {
414 p
= icalcomponent_get_first_property(
416 ICAL_SUMMARY_PROPERTY
);
417 e
= icalcomponent_get_first_property(
419 ICAL_DTEND_PROPERTY
);
420 if ((p
!= NULL
) && (e
!= NULL
)) {
423 t
= icalproperty_get_dtend(e
);
424 event_tte
= icaltime_as_timet(t
);
425 localtime_r(&event_tte
, &event_tme
);
426 difftime
=(event_tte
-event_tts
)/60;
427 hours
=(int)(difftime
/ 60);
428 minutes
=difftime
% 60;
429 wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
431 "<a class=\"event%s\" href=\"display_edit_event?msgnum=%ld?calview=calbrief?year=%s?month=%s?day=%s\">",
434 (Cal
->unread
)?"_unread":"_read",
443 icalproperty_get_comment(p
));
444 /* \todo: allso ammitime format */
445 wc_strftime(&sbuf
[0], sizeof(sbuf
), timeformat
, &event_tms
);
446 wc_strftime(&ebuf
[0], sizeof(sbuf
), timeformat
, &event_tme
);
448 wprintf("</a></font></td>"
449 "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
466 * view one month. pretty view
468 void calendar_month_view(int year
, int month
, int day
) {
469 struct tm starting_tm
;
473 time_t previous_month
;
475 time_t colheader_time
;
476 struct tm colheader_tm
;
477 char colheader_label
[32];
481 * Determine what day to start. If an impossible value is found, start on Sunday.
483 get_pref_long("weekstart", &weekstart
, 17);
484 if (weekstart
> 6) weekstart
= 0;
487 * Now back up to the 1st of the month...
489 memset(&starting_tm
, 0, sizeof(struct tm
));
491 starting_tm
.tm_year
= year
- 1900;
492 starting_tm
.tm_mon
= month
- 1;
493 starting_tm
.tm_mday
= day
;
494 thetime
= mktime(&starting_tm
);
496 memcpy(&tm
, &starting_tm
, sizeof(struct tm
));
497 while (tm
.tm_mday
!= 1) {
498 thetime
= thetime
- (time_t)86400; /* go back 24 hours */
499 localtime_r(&thetime
, &tm
);
502 /* Determine previous and next months ... for links */
503 previous_month
= thetime
- (time_t)864000L; /* back 10 days */
504 next_month
= thetime
+ (time_t)(31L * 86400L); /* ahead 31 days */
506 /* Now back up until we're on the user's preferred start day */
507 localtime_r(&thetime
, &tm
);
508 while (tm
.tm_wday
!= weekstart
) {
509 thetime
= thetime
- (time_t)86400; /* go back 24 hours */
510 localtime_r(&thetime
, &tm
);
513 /* Outer table (to get the background color) */
514 wprintf("<div class=\"fix_scrollbar_bug\">"
515 "<table class=\"calendar\"> \n <tr><td>");
517 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
519 wprintf("<td align=center>");
521 localtime_r(&previous_month
, &tm
);
522 wprintf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
523 (int)(tm
.tm_year
)+1900, tm
.tm_mon
+ 1);
524 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
526 wc_strftime(colheader_label
, sizeof colheader_label
, "%B", &starting_tm
);
527 wprintf(" "
528 "<font size=+1 color=\"#FFFFFF\">"
531 " ", colheader_label
, year
);
533 localtime_r(&next_month
, &tm
);
534 wprintf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
535 (int)(tm
.tm_year
)+1900, tm
.tm_mon
+ 1);
536 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
538 wprintf("</td></tr></table>\n");
540 /* Inner table (the real one) */
541 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
542 "bgcolor=#204B78 id=\"inner_month\"><tr>");
543 colheader_time
= thetime
;
544 for (i
=0; i
<7; ++i
) {
545 colheader_time
= thetime
+ (i
* 86400) ;
546 localtime_r(&colheader_time
, &colheader_tm
);
547 wc_strftime(colheader_label
, sizeof colheader_label
, "%A", &colheader_tm
);
548 wprintf("<th align=center width=14%%>"
549 "<font color=\"#FFFFFF\">%s</font></th>", colheader_label
);
555 /* Now do 35 or 42 days */
556 localtime_r(&thetime
, &tm
);
557 for (i
= 0; i
<42; ++i
) {
559 /* Before displaying the first day of the week, start a new row */
564 wprintf("<td class=\"cal%s\"><div class=\"day\">",
565 ((tm
.tm_mon
!= month
-1) ? "out" :
566 ((tm
.tm_wday
==0 || tm
.tm_wday
==6) ? "weekend" :
569 if ((i
==0) || (tm
.tm_mday
== 1)) {
570 wc_strftime(colheader_label
, sizeof colheader_label
, "%B", &tm
);
571 wprintf("%s ", colheader_label
);
573 wprintf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">"
580 /* put the data here, stupid */
581 calendar_month_view_display_events(
589 /* After displaying the last day of the week, end the row */
594 thetime
+= (time_t)86400; /* ahead 24 hours */
595 localtime_r(&thetime
, &tm
);
597 if ( ((i
% 7) == 6) && (tm
.tm_mon
!= month
-1) && (tm
.tm_mday
< 15) ) {
598 i
= 100; /* break out of the loop */
602 wprintf("</table>" /* end of inner table */
603 "</td></tr></table>" /* end of outer table */
607 * Initialize the bubble tooltips.
609 * Yes, this is as stupid as it looks. Instead of just making the call
610 * to btt_enableTooltips() straight away, we have to create a timer event
611 * and let it initialize as an event after 1 millisecond. This is to
612 * work around a bug in Internet Explorer that causes it to crash if we
613 * manipulate the innerHTML of various DOM nodes while the page is still
614 * being rendered. See http://www.shaftek.org/blog/archives/000212.html
615 * for more information.
617 StrBufAppendPrintf(WC
->trailing_javascript
,
618 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); \n"
623 * view one month. brief view
625 void calendar_brief_month_view(int year
, int month
, int day
) {
626 struct tm starting_tm
;
630 time_t previous_month
;
632 char month_label
[32];
634 /* Determine what day to start.
635 * First, back up to the 1st of the month...
637 memset(&starting_tm
, 0, sizeof(struct tm
));
638 starting_tm
.tm_year
= year
- 1900;
639 starting_tm
.tm_mon
= month
- 1;
640 starting_tm
.tm_mday
= day
;
641 thetime
= mktime(&starting_tm
);
643 memcpy(&tm
, &starting_tm
, sizeof(struct tm
));
644 while (tm
.tm_mday
!= 1) {
645 thetime
= thetime
- (time_t)86400; /* go back 24 hours */
646 localtime_r(&thetime
, &tm
);
649 /* Determine previous and next months ... for links */
650 previous_month
= thetime
- (time_t)864000L; /* back 10 days */
651 next_month
= thetime
+ (time_t)(31L * 86400L); /* ahead 31 days */
653 /* Now back up until we're on a Sunday */
654 localtime_r(&thetime
, &tm
);
655 while (tm
.tm_wday
!= 0) {
656 thetime
= thetime
- (time_t)86400; /* go back 24 hours */
657 localtime_r(&thetime
, &tm
);
660 /* Outer table (to get the background color) */
661 wprintf("<div class=\"fix_scrollbar_bug\">"
662 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
663 "bgcolor=#204B78><TR><TD>\n");
665 wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
667 wprintf("<td align=center>");
669 localtime_r(&previous_month
, &tm
);
670 wprintf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
671 (int)(tm
.tm_year
)+1900, tm
.tm_mon
+ 1);
672 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
674 wc_strftime(month_label
, sizeof month_label
, "%B", &tm
);
675 wprintf(" "
676 "<font size=+1 color=\"#FFFFFF\">"
679 " ", month_label
, year
);
681 localtime_r(&next_month
, &tm
);
682 wprintf("<a href=\"readfwd?calview=month?year=%d?month=%d?day=1\">",
683 (int)(tm
.tm_year
)+1900, tm
.tm_mon
+ 1);
684 wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
686 wprintf("</td></tr></table>\n");
688 /* Inner table (the real one) */
689 wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
690 "bgcolor=#EEEECC><TR>");
692 wprintf("<tr><td colspan=\"100%%\">\n");
695 for (i
= 0; i
< 35; ++i
) {
696 char weeknumber
[255];
697 char weekday_name
[32];
699 localtime_r(&thetime
, &tm
);
702 /* Before displaying Sunday, start a new CELL */
704 wc_strftime(&weeknumber
[0], sizeof(weeknumber
), "%U", &tm
);
705 wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%%'> <tr><th colspan='4'>%s %s</th></tr>"
706 " <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
716 daycolor
=((tm
.tm_mon
!= month
-1) ? "DDDDDD" :
717 ((tm
.tm_wday
==0 || tm
.tm_wday
==6) ? "EEEECC" :
721 wc_strftime(weekday_name
, sizeof weekday_name
, "%A", &tm
);
722 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
723 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
725 weekday_name
,tm
.tm_mday
,
728 /* put the data of one day here, stupid */
729 calendar_month_view_brief_events(thetime
, daycolor
);
732 /* After displaying Saturday, end the row */
734 wprintf("</td></tr></table>\n");
737 thetime
+= (time_t)86400; /* ahead 24 hours */
740 wprintf("</table>" /* end of inner table */
741 "</td></tr></table>" /* end of outer table */
746 * Calendar week view -- not implemented yet, this is a stub function
748 void calendar_week_view(int year
, int month
, int day
) {
749 wprintf("<center><i>week view FIXME</i></center><br />\n");
755 * Display events for a particular hour of a particular day.
756 * (Specify hour < 0 to show "all day" events)
758 * dstart and dend indicate which hours our "daytime" begins and end
760 void calendar_day_view_display_events(time_t thetime
,
772 icalproperty
*p
= NULL
;
773 icalproperty
*q
= NULL
;
779 int all_day_event
= 0;
780 int ongoing_event
= 0;
783 struct icaltimetype t
;
784 struct icaltimetype end_t
;
785 struct icaltimetype today_start_t
;
786 struct icaltimetype today_end_t
;
787 struct tm starting_tm
;
800 if (GetCount(WCC
->disp_cal_items
) == 0) {
801 /* nothing to display */
805 /* Create an imaginary event which spans the current day. Any events which
806 * overlap with this one take place at least partially in this day.
808 memset(&starting_tm
, 0, sizeof(struct tm
));
809 starting_tm
.tm_year
= year
- 1900;
810 starting_tm
.tm_mon
= month
- 1;
811 starting_tm
.tm_mday
= day
;
812 starting_tm
.tm_hour
= 0;
813 starting_tm
.tm_min
= 0;
814 today_start_t
= icaltime_from_timet_with_zone(mktime(&starting_tm
), 0, icaltimezone_get_utc_timezone());
815 today_start_t
.is_utc
= 1;
817 memset(&ending_tm
, 0, sizeof(struct tm
));
818 ending_tm
.tm_year
= year
- 1900;
819 ending_tm
.tm_mon
= month
- 1;
820 ending_tm
.tm_mday
= day
;
821 ending_tm
.tm_hour
= 23;
822 ending_tm
.tm_min
= 59;
823 today_end_t
= icaltime_from_timet_with_zone(mktime(&ending_tm
), 0, icaltimezone_get_utc_timezone());
824 today_end_t
.is_utc
= 1;
826 /* Now loop through our list of events to see which ones occur today.
828 Pos
= GetNewHashPos(WCC
->disp_cal_items
, 0);
829 while (GetNextHashPos(WCC
->disp_cal_items
, Pos
, &hklen
, &HashKey
, &vCal
)) {
830 Cal
= (disp_cal
*)vCal
;
835 q
= icalcomponent_get_first_property(Cal
->cal
, ICAL_DTSTART_PROPERTY
);
837 t
= icalproperty_get_dtstart(q
);
838 event_tt
= icaltime_as_timet(t
);
839 localtime_r(&event_tt
, &event_te
);
842 memset(&t
, 0, sizeof t
);
844 q
= icalcomponent_get_first_property(Cal
->cal
, ICAL_DTEND_PROPERTY
);
846 end_t
= icalproperty_get_dtend(q
);
847 event_tte
= icaltime_as_timet(end_t
);
848 localtime_r(&event_tte
, &event_tm
);
851 memset(&end_t
, 0, sizeof end_t
);
853 if (t
.is_date
) all_day_event
= 1;
857 show_event
= ((t
.year
== year
) && (t
.month
== month
) && (t
.day
== day
) && (notime_events
));
861 show_event
= ical_ctdl_is_overlap(t
, end_t
, today_start_t
, today_end_t
);
864 /* If we determined that this event occurs today, then display it.
866 p
= icalcomponent_get_first_property(Cal
->cal
,ICAL_SUMMARY_PROPERTY
);
868 if ((show_event
) && (p
!= NULL
)) {
870 if ((event_te
.tm_mday
!= day
) || (event_tm
.tm_mday
!= day
)) ongoing_event
= 1;
872 if (all_day_event
&& notime_events
)
874 wprintf("<li class=\"event_framed%s\"> "
875 "<a href=\"display_edit_event?"
876 "msgnum=%ld?calview=day?year=%d?month=%d?day=%d\" "
877 " class=\"event_title\" "
879 (Cal
->unread
)?"_unread":"_read",
880 Cal
->cal_msgnum
, year
, month
, day
);
881 wprintf("<i>%s</i><br />", _("All day event"));
882 wprintf("<i>%s: %s</i><br />", _("From"), Cal
->from
);
883 wprintf("<i>%s</i> ", _("Summary:"));
884 escputs((char *) icalproperty_get_comment(p
));
886 q
= icalcomponent_get_first_property(Cal
->cal
,ICAL_LOCATION_PROPERTY
);
888 wprintf("<i>%s</i> ", _("Location:"));
889 escputs((char *)icalproperty_get_comment(q
));
892 memset(&d_tm
, 0, sizeof d_tm
);
893 d_tm
.tm_year
= t
.year
- 1900;
894 d_tm
.tm_mon
= t
.month
- 1;
895 d_tm
.tm_mday
= t
.day
;
896 wc_strftime(d_str
, sizeof d_str
, "%x", &d_tm
);
897 wprintf("<i>%s</i> %s<br>",_("Date:"), d_str
);
898 q
= icalcomponent_get_first_property(Cal
->cal
,ICAL_DESCRIPTION_PROPERTY
);
900 wprintf("<i>%s</i> ", _("Notes:"));
901 escputs((char *)icalproperty_get_comment(q
));
905 escputs((char *) icalproperty_get_comment(p
));
906 wprintf("</a> <span>(");
907 wprintf(_("All day event"));
908 wprintf(")</span></li>\n");
910 else if (ongoing_event
&& notime_events
)
912 wprintf("<li class=\"event_framed%s\"> "
913 "<a href=\"display_edit_event?"
914 "msgnum=%ld&calview=day?year=%d?month=%d?day=%d\" "
915 " class=\"event_title\" "
917 (Cal
->unread
)?"_unread":"_read",
918 Cal
->cal_msgnum
, year
, month
, day
);
919 wprintf("<i>%s</i><br />", _("Ongoing event"));
920 wprintf("<i>%s: %s</i><br />", _("From"), Cal
->from
);
921 wprintf("<i>%s</i> ", _("Summary:"));
922 escputs((char *) icalproperty_get_comment(p
));
924 q
= icalcomponent_get_first_property(Cal
->cal
,ICAL_LOCATION_PROPERTY
);
926 wprintf("<i>%s</i> ", _("Location:"));
927 escputs((char *)icalproperty_get_comment(q
));
930 webcit_fmt_date(buf
, event_tt
, 1);
931 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf
);
932 webcit_fmt_date(buf
, event_tte
, 1);
933 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf
);
934 q
= icalcomponent_get_first_property(Cal
->cal
,ICAL_DESCRIPTION_PROPERTY
);
936 wprintf("<i>%s</i> ", _("Notes:"));
937 escputs((char *)icalproperty_get_comment(q
));
941 escputs((char *) icalproperty_get_comment(p
));
942 wprintf("</a> <span>(");
943 wprintf(_("Ongoing event"));
944 wprintf(")</span></li>\n");
946 else if (!all_day_event
&& !notime_events
)
950 if (event_te
.tm_mday
!= day
) event_te
.tm_hour
= 0;
951 if (event_tm
.tm_mday
!= day
) event_tm
.tm_hour
= 24;
953 /* Calculate the location of the top of the box */
954 if (event_te
.tm_hour
< dstart
) {
955 startmin
= diffmin
= event_te
.tm_min
/ 6;
956 top
= (event_te
.tm_hour
* 10) + startmin
;
958 else if ((event_te
.tm_hour
>= dstart
) && (event_te
.tm_hour
<= dend
)) {
959 startmin
= diffmin
= (event_te
.tm_min
/ 2);
960 top
= (dstart
* 10) + ((event_te
.tm_hour
- dstart
) * 30) + startmin
;
962 else if (event_te
.tm_hour
>dend
) {
963 startmin
= diffmin
= event_te
.tm_min
/ 6;
964 top
= (dstart
* 10) + ((dend
- dstart
- 1) * 30) + ((event_tm
.tm_hour
- dend
+ 1) * 10) + startmin
;
967 /* should never get here */
970 /* Calculate the location of the bottom of the box */
971 if (event_tm
.tm_hour
< dstart
) {
972 endmin
= diffmin
= event_tm
.tm_min
/ 6;
973 bottom
= (event_tm
.tm_hour
* 10) + endmin
;
975 else if ((event_tm
.tm_hour
>= dstart
) && (event_tm
.tm_hour
<= dend
)) {
976 endmin
= diffmin
= (event_tm
.tm_min
/ 2);
977 bottom
= (dstart
* 10) + ((event_tm
.tm_hour
- dstart
) * 30) + endmin
;
979 else if (event_tm
.tm_hour
>dend
) {
980 endmin
= diffmin
= event_tm
.tm_min
/ 6;
981 bottom
= (dstart
* 10) + ((dend
- dstart
+ 1) * 30) + ((event_tm
.tm_hour
- dend
- 1) * 10) + endmin
;
984 /* should never get here */
987 wprintf("<dd class=\"event_framed%s\" "
988 "style=\"position: absolute; "
989 "top:%dpx; left:%dpx; "
991 (Cal
->unread
)?"_unread":"_read",
992 top
, (gap
* 40), (bottom
-top
)
994 wprintf("<a href=\"display_edit_event?"
995 "msgnum=%ld?calview=day?year=%d?month=%d?day=%d?hour=%d\" "
996 "class=\"event_title\" "
998 Cal
->cal_msgnum
, year
, month
, day
, t
.hour
);
999 wprintf("<i>%s: %s</i><br />", _("From"), Cal
->from
);
1000 wprintf("<i>%s</i> ", _("Summary:"));
1001 escputs((char *) icalproperty_get_comment(p
));
1003 q
= icalcomponent_get_first_property(Cal
->cal
,ICAL_LOCATION_PROPERTY
);
1005 wprintf("<i>%s</i> ", _("Location:"));
1006 escputs((char *)icalproperty_get_comment(q
));
1009 webcit_fmt_date(buf
, event_tt
, 1);
1010 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf
);
1011 webcit_fmt_date(buf
, event_tte
, 1);
1012 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf
);
1013 q
= icalcomponent_get_first_property(Cal
->cal
,ICAL_DESCRIPTION_PROPERTY
);
1015 wprintf("<i>%s</i> ", _("Notes:"));
1016 escputs((char *)icalproperty_get_comment(q
));
1021 escputs((char *) icalproperty_get_comment(p
));
1022 wprintf("</a></dd>\n");
1026 DeleteHashPos(&Pos
);
1032 void calendar_day_view(int year
, int month
, int day
) {
1034 struct icaltimetype today
, yesterday
, tomorrow
;
1042 int extratimeline
= 0;
1045 time_format
= get_time_format_cached ();
1046 get_pref_long("daystart", &daystart
, 8);
1047 get_pref_long("dayend", &dayend
, 17);
1049 /* when loading daystart/dayend, replace missing, corrupt, or impossible values with defaults */
1050 if ((daystart
< 0) || (dayend
< 2) || (daystart
>= 23) || (dayend
> 23) || (dayend
<= daystart
)) {
1056 memset(&d_tm
, 0, sizeof d_tm
);
1057 d_tm
.tm_year
= year
- 1900;
1058 d_tm
.tm_mon
= month
- 1;
1060 today_t
= mktime(&d_tm
);
1062 /* Figure out the dates for "yesterday" and "tomorrow" links */
1064 memset(&today
, 0, sizeof(struct icaltimetype
));
1066 today
.month
= month
;
1070 memcpy(&yesterday
, &today
, sizeof(struct icaltimetype
));
1072 yesterday
= icaltime_normalize(yesterday
);
1074 memcpy(&tomorrow
, &today
, sizeof(struct icaltimetype
));
1076 tomorrow
= icaltime_normalize(tomorrow
);
1078 wprintf("<div class=\"fix_scrollbar_bug\">");
1080 /* Inner table (the real one) */
1081 wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
1083 /* Innermost cell (contains hours etc.) */
1084 wprintf("<td class=\"events_of_the_day\" >");
1085 wprintf("<dl class=\"events\" >");
1087 /* Now the middle of the day... */
1089 extratimeline
= timeline
/ 3;
1091 for (hour
= 0; hour
< daystart
; ++hour
) { /* could do HEIGHT=xx */
1092 wprintf("<dt class=\"extrahour\" "
1094 "position: absolute; "
1095 "top: %dpx; left: 0px; "
1098 "<a href=\"display_edit_event?msgnum=0"
1099 "?calview=day?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
1100 (hour
* extratimeline
), extratimeline
,
1101 year
, month
, day
, hour
1104 if (time_format
== WC_TIMEFORMAT_24
) {
1105 wprintf("%2d:00</a> ", hour
);
1108 wprintf("%d:00%s</a> ",
1109 (hour
<= 12 ? hour
: hour
-12),
1110 (hour
< 12 ? "am" : "pm")
1117 gap
= daystart
* extratimeline
;
1119 for (hour
= daystart
; hour
<= dayend
; ++hour
) { /* could do HEIGHT=xx */
1120 wprintf("<dt class=\"hour\" "
1122 "position: absolute; "
1123 "top: %ldpx; left: 0px; "
1126 "<a href=\"display_edit_event?msgnum=0?calview=day"
1127 "?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
1128 gap
+ ((hour
- daystart
) * timeline
), timeline
,
1129 year
, month
, day
, hour
1132 if (time_format
== WC_TIMEFORMAT_24
) {
1133 wprintf("%2d:00</a> ", hour
);
1136 wprintf("%d:00%s</a> ",
1137 (hour
<= 12 ? hour
: hour
-12),
1138 (hour
< 12 ? "am" : "pm")
1145 gap
= gap
+ ((dayend
- daystart
+ 1) * timeline
);
1147 for (hour
= (dayend
+ 1); hour
< 24; ++hour
) { /* could do HEIGHT=xx */
1148 wprintf("<dt class=\"extrahour\" "
1150 "position: absolute; "
1151 "top: %ldpx; left: 0px; "
1154 "<a href=\"display_edit_event?msgnum=0?calview=day"
1155 "?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
1156 gap
+ ((hour
- dayend
- 1) * extratimeline
), extratimeline
,
1157 year
, month
, day
, hour
1160 if (time_format
== WC_TIMEFORMAT_24
) {
1161 wprintf("%2d:00</a> ", hour
);
1164 wprintf("%d:00%s</a> ",
1165 (hour
<= 12 ? hour
: hour
-12),
1166 (hour
< 12 ? "am" : "pm")
1173 /* Display events with start and end times on this day */
1174 calendar_day_view_display_events(today_t
, year
, month
, day
, 0, daystart
, dayend
);
1177 wprintf("</td>"); /* end of innermost table */
1179 /* Display extra events (start/end times not present or not today) in the middle column */
1180 wprintf("<td class=\"extra_events\">");
1184 /* Display all-day events */
1185 calendar_day_view_display_events(today_t
, year
, month
, day
, 1, daystart
, dayend
);
1189 wprintf("</td>"); /* end extra on the middle */
1191 wprintf("<td width=20%% align=center valign=top>"); /* begin stuff-on-the-right */
1193 /* Begin todays-date-with-left-and-right-arrows */
1194 wprintf("<table border=0 width=100%% "
1195 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
1199 wprintf("<td align=center>");
1200 wprintf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">",
1201 yesterday
.year
, yesterday
.month
, yesterday
.day
);
1202 wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
1205 wc_strftime(d_str
, sizeof d_str
,
1207 "<font size=+2>%B</font><br />"
1208 "<font size=+3>%d</font><br />"
1209 "<font size=+2>%Y</font><br />"
1213 wprintf("%s", d_str
);
1216 wprintf("<td align=center>");
1217 wprintf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">",
1218 tomorrow
.year
, tomorrow
.month
, tomorrow
.day
);
1219 wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
1220 " border=0></a>\n");
1223 wprintf("</tr></table>\n");
1224 /* End todays-date-with-left-and-right-arrows */
1226 /* Embed a mini month calendar in this space */
1227 wprintf("<br />\n");
1228 embeddable_mini_calendar(year
, month
, "readfwd?calview=day?year=%d?month=%d?day=%d");
1230 wprintf("</font></center>\n");
1232 wprintf("</td></tr>"); /* end stuff-on-the-right */
1234 wprintf("</table>" /* end of inner table */
1237 StrBufAppendPrintf(WC
->trailing_javascript
,
1238 " setTimeout(\"btt_enableTooltips('inner_day')\", 1); \n"
1244 * Display today's events. Returns the number of items displayed.
1246 int calendar_summary_view(void) {
1248 const char *HashKey
;
1253 struct icaltimetype t
;
1258 int all_day_event
= 0;
1259 char timestring
[SIZ
];
1260 wcsession
*WCC
= WC
;
1261 int num_displayed
= 0;
1263 if (GetCount(WC
->disp_cal_items
) == 0) {
1268 localtime_r(&now
, &today_tm
);
1270 Pos
= GetNewHashPos(WCC
->disp_cal_items
, 0);
1271 while (GetNextHashPos(WCC
->disp_cal_items
, Pos
, &hklen
, &HashKey
, &vCal
)) {
1272 Cal
= (disp_cal
*)vCal
;
1273 p
= icalcomponent_get_first_property(Cal
->cal
, ICAL_DTSTART_PROPERTY
);
1275 t
= icalproperty_get_dtstart(p
);
1276 event_tt
= icaltime_as_timet(t
);
1283 fmt_time(timestring
, event_tt
);
1285 if (all_day_event
) {
1286 gmtime_r(&event_tt
, &event_tm
);
1289 localtime_r(&event_tt
, &event_tm
);
1292 if ( (event_tm
.tm_year
== today_tm
.tm_year
)
1293 && (event_tm
.tm_mon
== today_tm
.tm_mon
)
1294 && (event_tm
.tm_mday
== today_tm
.tm_mday
)
1297 p
= icalcomponent_get_first_property(Cal
->cal
, ICAL_SUMMARY_PROPERTY
);
1301 if (WCC
->wc_view
== VIEW_TASKS
) {
1302 wprintf("<a href=\"display_edit_task"
1304 "?return_to_summary=1"
1308 escputs(ChrPtr(WCC
->wc_roomname
));
1312 wprintf("<a href=\"display_edit_event"
1320 today_tm
.tm_year
+ 1900,
1321 today_tm
.tm_mon
+ 1,
1324 escputs(ChrPtr(WCC
->wc_roomname
));
1327 escputs((char *) icalproperty_get_comment(p
));
1328 if (!all_day_event
) {
1329 wprintf(" (%s)", timestring
);
1331 wprintf("</a><br />\n");
1337 DeleteHashPos(&Pos
);
1338 DeleteHash(&WC
->disp_cal_items
);
1339 return(num_displayed
);
1343 * Parse the URL variables in order to determine the scope and display of a calendar view
1345 void parse_calendar_view_request(struct calview
*c
) {
1351 /* In case no date was specified, go with today */
1353 localtime_r(&now
, &tm
);
1354 c
->year
= tm
.tm_year
+ 1900;
1355 c
->month
= tm
.tm_mon
+ 1;
1356 c
->day
= tm
.tm_mday
;
1358 /* Now see if a date was specified */
1359 if (havebstr("year")) c
->year
= ibstr("year");
1360 if (havebstr("month")) c
->month
= ibstr("month");
1361 if (havebstr("day")) c
->day
= ibstr("day");
1363 /* How would you like that cooked? */
1364 if (havebstr("calview")) {
1365 strcpy(calview
, bstr("calview"));
1368 strcpy(calview
, "month");
1371 /* Display the selected view */
1372 if (!strcasecmp(calview
, "day")) {
1373 c
->view
= calview_day
;
1375 else if (!strcasecmp(calview
, "week")) {
1376 c
->view
= calview_week
;
1378 else if (!strcasecmp(calview
, "summary")) { /* shouldn't ever happen, but just in case */
1379 c
->view
= calview_day
;
1382 if (WC
->wc_view
== VIEW_CALBRIEF
) {
1383 c
->view
= calview_brief
;
1386 c
->view
= calview_month
;
1390 /* Now try and set the lower and upper bounds so that we don't
1391 * burn too many cpu cycles parsing data way in the past or future
1394 tm
.tm_year
= c
->year
- 1900;
1395 tm
.tm_mon
= c
->month
- 1;
1396 tm
.tm_mday
= c
->day
;
1399 if (c
->view
== calview_month
) span
= 3888000;
1400 if (c
->view
== calview_brief
) span
= 3888000;
1401 if (c
->view
== calview_week
) span
= 604800;
1402 if (c
->view
== calview_day
) span
= 86400;
1403 if (c
->view
== calview_summary
) span
= 86400;
1405 c
->lower_bound
= now
- span
;
1406 c
->upper_bound
= now
+ span
;
1412 * Render a calendar view from data previously loaded into memory
1414 void render_calendar_view(struct calview
*c
)
1416 if (c
->view
== calview_day
) {
1417 calendar_day_view(c
->year
, c
->month
, c
->day
);
1419 else if (c
->view
== calview_week
) {
1420 calendar_week_view(c
->year
, c
->month
, c
->day
);
1423 if (WC
->wc_view
== VIEW_CALBRIEF
) {
1424 calendar_brief_month_view(c
->year
, c
->month
, c
->day
);
1427 calendar_month_view(c
->year
, c
->month
, c
->day
);
1431 /* Free the in-memory list of calendar items */
1432 DeleteHash(&WC
->disp_cal_items
);
1437 * Helper function for do_tasks_view(). Returns the due date/time of a vtodo.
1439 time_t get_task_due_date(icalcomponent
*vtodo
) {
1442 if (vtodo
== NULL
) {
1447 * If we're looking at a fully encapsulated VCALENDAR
1448 * rather than a VTODO component, recurse into the data
1449 * structure until we get a VTODO.
1451 if (icalcomponent_isa(vtodo
) == ICAL_VCALENDAR_COMPONENT
) {
1452 return get_task_due_date(
1453 icalcomponent_get_first_component(
1454 vtodo
, ICAL_VTODO_COMPONENT
1459 p
= icalcomponent_get_first_property(vtodo
, ICAL_DUE_PROPERTY
);
1461 return(icaltime_as_timet(icalproperty_get_due(p
)));
1470 * Compare the due dates of two tasks (this is for sorting)
1472 int task_due_cmp(const void *vtask1
, const void *vtask2
) {
1473 disp_cal
* Task1
= (disp_cal
*)GetSearchPayload(vtask1
);
1474 disp_cal
* Task2
= (disp_cal
*)GetSearchPayload(vtask2
);
1479 t1
= get_task_due_date(Task1
->cal
);
1480 t2
= get_task_due_date(Task2
->cal
);
1481 if (t1
< t2
) return(-1);
1482 if (t1
> t2
) return(1);
1487 * qsort filter to move completed tasks to bottom of task list
1489 int task_completed_cmp(const void *vtask1
, const void *vtask2
) {
1490 disp_cal
* Task1
= (disp_cal
*)GetSearchPayload(vtask1
);
1491 /* disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2); */
1493 icalproperty_status t1
= icalcomponent_get_status((Task1
)->cal
);
1494 /* icalproperty_status t2 = icalcomponent_get_status(((struct disp_cal *)task2)->cal); */
1496 if (t1
== ICAL_STATUS_COMPLETED
)
1504 * do the whole task view stuff
1506 void do_tasks_view(void) {
1508 const char *HashKey
;
1516 wcsession
*WCC
= WC
;
1518 wprintf("<div class=\"fix_scrollbar_bug\">"
1519 "<table class=\"calendar_view_background\"><tbody id=\"taskview\">\n<tr>\n"
1521 wprintf(_("Completed?"));
1522 wprintf("</th><th>");
1523 wprintf(_("Name of task"));
1524 wprintf("</th><th>");
1525 wprintf(_("Date due"));
1526 wprintf("</th><th>");
1527 wprintf(_("Category"));
1528 wprintf(" (<select id=\"selectcategory\"><option value=\"showall\">%s</option></select>)</th></tr>\n",
1531 nItems
= GetCount(WC
->disp_cal_items
);
1533 /* Sort them if necessary
1535 SortByPayload(WC->disp_cal_items, task_due_cmp);
1537 * this shouldn't be neccessary, since we sort by the start time.
1540 /* And then again, by completed */
1542 SortByPayload(WC
->disp_cal_items
,
1543 task_completed_cmp
);
1546 Pos
= GetNewHashPos(WCC
->disp_cal_items
, 0);
1547 while (GetNextHashPos(WCC
->disp_cal_items
, Pos
, &hklen
, &HashKey
, &vCal
)) {
1548 icalproperty_status todoStatus
;
1550 Cal
= (disp_cal
*)vCal
;
1551 wprintf("<tr><td>");
1552 todoStatus
= icalcomponent_get_status(Cal
->cal
);
1553 wprintf("<input type=\"checkbox\" name=\"completed\" value=\"completed\" ");
1554 if (todoStatus
== ICAL_STATUS_COMPLETED
) {
1555 wprintf("checked=\"checked\" ");
1557 wprintf("disabled=\"disabled\">\n</td><td>");
1558 p
= icalcomponent_get_first_property(Cal
->cal
,
1559 ICAL_SUMMARY_PROPERTY
);
1560 wprintf("<a href=\"display_edit_task?msgnum=%ld?taskrm=", Cal
->cal_msgnum
);
1561 urlescputs(ChrPtr(WC
->wc_roomname
));
1563 /* wprintf("<img align=middle "
1564 "src=\"static/taskmanag_16x.gif\" border=0> "); */
1566 escputs((char *)icalproperty_get_comment(p
));
1571 due
= get_task_due_date(Cal
->cal
);
1572 wprintf("<td><span");
1574 webcit_fmt_date(buf
, due
, 0);
1580 wprintf("</span></td>");
1582 p
= icalcomponent_get_first_property(Cal
->cal
,
1583 ICAL_CATEGORIES_PROPERTY
);
1585 escputs((char *)icalproperty_get_categories(p
));
1591 wprintf("</tbody></table></div>\n");
1594 DeleteHash(&WC
->disp_cal_items
);
1595 DeleteHashPos(&Pos
);