13 #include <sys/types.h>
15 #include <sys/socket.h>
17 #include <netinet/in.h>
27 #include "webserver.h"
31 void do_calendar_view(void) { /* stub for non-libical builds */
32 wprintf("<CENTER><I>Calendar view not available</I></CENTER><BR>\n");
35 #else /* HAVE_ICAL_H */
37 /****************************************************************************/
41 void calendar_month_view_display_events(time_t thetime) {
45 struct icaltimetype t;
47 int all_day_event = 0;
49 if (WC->num_cal == 0) {
50 wprintf("<BR><BR><BR>\n");
54 tm = localtime(&thetime);
55 month = tm->tm_mon + 1;
57 year = tm->tm_year + 1900;
59 for (i=0; i<(WC->num_cal); ++i) {
60 p = icalcomponent_get_first_property(WC->disp_cal[i],
61 ICAL_DTSTART_PROPERTY);
63 t = icalproperty_get_dtstart(p);
68 if (t.is_date) all_day_event = 1;
70 p = icalcomponent_get_first_property(
72 ICAL_SUMMARY_PROPERTY);
76 wprintf("<TABLE border=1 cellpadding=2><TR>"
77 "<TD BGCOLOR=#CCCCCC>"
81 wprintf("<FONT SIZE=-1>"
82 "<A HREF=\"/display_edit_event?msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\">",
90 icalproperty_get_comment(p));
91 wprintf("</A></FONT><BR>\n");
94 wprintf("</TD></TR></TABLE>");
108 void calendar_month_view(int year, int month, int day) {
109 struct tm starting_tm;
113 time_t previous_month;
116 /* Determine what day to start.
117 * First, back up to the 1st of the month...
119 memset(&starting_tm, 0, sizeof(struct tm));
120 starting_tm.tm_year = year - 1900;
121 starting_tm.tm_mon = month - 1;
122 starting_tm.tm_mday = day;
123 thetime = mktime(&starting_tm);
126 while (tm->tm_mday != 1) {
127 thetime = thetime - (time_t)86400; /* go back 24 hours */
128 tm = localtime(&thetime);
131 /* Determine previous and next months ... for links */
132 previous_month = thetime - (time_t)864000L; /* back 10 days */
133 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
135 /* Now back up until we're on a Sunday */
136 tm = localtime(&thetime);
137 while (tm->tm_wday != 0) {
138 thetime = thetime - (time_t)86400; /* go back 24 hours */
139 tm = localtime(&thetime);
142 /* Outer table (to get the background color) */
143 wprintf("<TABLE width=100%% border=0 cellpadding=0 cellspacing=0 "
144 "bgcolor=#4444FF><TR><TD>\n");
146 wprintf("<TABLE width=100%% border=0 cellpadding=0 cellspacing=0>"
147 "<TR><TD align=left><font color=#FFFFFF>"
148 " <A HREF=\"/display_edit_event?msgnum=0\">"
149 "Add new calendar event</A>"
152 wprintf("<TD><CENTER><H3>");
154 tm = localtime(&previous_month);
155 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
156 (int)(tm->tm_year)+1900, tm->tm_mon + 1);
157 wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/back.gif\" BORDER=0></A>\n");
159 wprintf(" "
160 "<FONT COLOR=#FFFFFF>"
163 " ", months[month-1], year);
165 tm = localtime(&next_month);
166 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
167 (int)(tm->tm_year)+1900, tm->tm_mon + 1);
168 wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/forward.gif\" BORDER=0></A>\n");
170 wprintf("</H3></TD><TD align=right><font color=#FFFFFF size=-2>"
171 "Click on any date for day view "
172 "</FONT></TD></TR></TABLE>\n");
174 /* Inner table (the real one) */
175 wprintf("<TABLE width=100%% border=0 cellpadding=1 cellspacing=1 "
177 for (i=0; i<7; ++i) {
178 wprintf("<TH><FONT COLOR=#FFFFFF>%s</FONT></TH>", days[i]);
182 for (i = 0; i < 35; ++i) {
183 tm = localtime(&thetime);
184 if (tm->tm_wday == 0) {
188 wprintf("<TD BGCOLOR=%s WIDTH=14%% HEIGHT=60 VALIGN=TOP><B>",
189 ((tm->tm_mon != month-1) ? "DDDDDD" :
190 ((tm->tm_wday==0 || tm->tm_wday==6) ? "EEEECC" :
193 if ((i==0) || (tm->tm_mday == 1)) {
194 wprintf("%s ", months[tm->tm_mon]);
196 wprintf("<A HREF=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
203 /* put the data here, stupid */
204 calendar_month_view_display_events(thetime);
208 if (tm->tm_wday == 6) {
212 thetime += (time_t)86400; /* ahead 24 hours */
215 wprintf("</TABLE>" /* end of inner table */
216 "</TD></TR></TABLE>" /* end of outer table */
221 void calendar_week_view(int year, int month, int day) {
222 wprintf("<CENTER><I>week view FIXME</I></CENTER><BR>\n");
227 * Display events for a particular hour of a particular day.
228 * (Specify hour < 0 to show "all day" events)
230 void calendar_day_view_display_events(int year, int month,
234 struct icaltimetype t;
235 int all_day_event = 0;
237 if (WC->num_cal == 0) {
238 wprintf("<BR><BR><BR>\n");
242 for (i=0; i<(WC->num_cal); ++i) {
243 p = icalcomponent_get_first_property(WC->disp_cal[i],
244 ICAL_DTSTART_PROPERTY);
246 t = icalproperty_get_dtstart(p);
248 && (t.month == month)
250 && ( ((t.hour == hour)&&(!t.is_date)) || ((hour<0)&&(t.is_date)) )
253 if (t.is_date) all_day_event = 1;
255 p = icalcomponent_get_first_property(
257 ICAL_SUMMARY_PROPERTY);
261 wprintf("<TABLE border=1 cellpadding=2><TR>"
262 "<TD BGCOLOR=#CCCCCC>"
266 wprintf("<FONT SIZE=-1>"
267 "<A HREF=\"/display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d\">",
272 icalproperty_get_comment(p));
273 wprintf("</A></FONT><BR>\n");
276 wprintf("</TD></TR></TABLE>");
289 void calendar_day_view(int year, int month, int day) {
291 struct icaltimetype today, yesterday, tomorrow;
294 /* Figure out the dates for "yesterday" and "tomorrow" links */
296 memset(&today, 0, sizeof(struct icaltimetype));
302 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
304 yesterday = icaltime_normalize(yesterday);
306 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
308 tomorrow = icaltime_normalize(tomorrow);
311 /* Outer table (to get the background color) */
312 wprintf("<TABLE width=100%% border=0 cellpadding=0 cellspacing=0 "
313 "bgcolor=#4444FF><TR><TD>\n");
315 /* Inner table (the real one) */
316 wprintf("<TABLE width=100%% border=0 cellpadding=1 cellspacing=1 "
317 "bgcolor=#4444FF><TR>\n");
319 wprintf("<TD WIDTH=50%% VALIGN=top>"); /* begin stuff-on-the-left */
321 wprintf("<CENTER><H3>");
322 wprintf("<A HREF=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
323 yesterday.year, yesterday.month, yesterday.day
325 wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/back.gif\" BORDER=0></A>\n");
326 wprintf(" <FONT COLOR=#FFFFFF>"
328 "</FONT> ",
329 months[month-1], day, year);
330 wprintf("<A HREF=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
331 tomorrow.year, tomorrow.month, tomorrow.day
333 wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/forward.gif\" BORDER=0></A>\n");
334 wprintf("</H3></CENTER>\n");
336 wprintf("<CENTER><font color=#FFFFFF>"
337 " <A HREF=\"/display_edit_event?msgnum=0\">"
338 "Add new calendar event</A>"
341 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">"
342 "Back to month view</A>\n", year, month);
344 wprintf("</FONT></CENTER>\n");
346 wprintf("</TD>"); /* end stuff-on-the-left */
348 /* Innermost table (contains hours etc.) */
349 wprintf("<TD WIDTH=50%%>"
350 "<TABLE width=100%% border=0 cellpadding=1 cellspacing=1 "
351 "bgcolor=#4444FF>\n");
353 /* Display events before 8:00 (hour=-1 is all-day events) */
354 wprintf("<TR><TD BGCOLOR=FFFFFF VALIGN=TOP>");
355 for (hour = (-1); hour <= 7; ++hour) {
356 calendar_day_view_display_events(year, month, day, hour);
358 wprintf("</TD></TR>\n");
360 /* Now the middle of the day... */
361 for (hour = 8; hour <= 17; ++hour) { /* could do HEIGHT=xx */
362 wprintf("<TR><TD BGCOLOR=FFFFFF VALIGN=TOP>");
364 (hour <= 12 ? hour : hour-12),
365 (hour < 12 ? "am" : "pm")
368 /* put the data here, stupid */
369 calendar_day_view_display_events(year, month, day, hour);
371 wprintf("</TD></TR>\n");
374 /* Display events after 5:00... */
375 wprintf("<TR><TD BGCOLOR=FFFFFF VALIGN=TOP>");
376 for (hour = 18; hour <= 23; ++hour) {
377 calendar_day_view_display_events(year, month, day, hour);
379 wprintf("</TD></TR>\n");
382 wprintf("</TABLE>" /* end of innermost table */
383 "</TD></TR></TABLE>" /* end of inner table */
384 "</TD></TR></TABLE>" /* end of outer table */
394 void do_calendar_view(void) {
398 int year, month, day;
401 /* In case no date was specified, go with today */
403 tm = localtime(&now);
404 year = tm->tm_year + 1900;
405 month = tm->tm_mon + 1;
408 /* Now see if a date was specified */
409 if (strlen(bstr("year")) > 0) year = atoi(bstr("year"));
410 if (strlen(bstr("month")) > 0) month = atoi(bstr("month"));
411 if (strlen(bstr("day")) > 0) day = atoi(bstr("day"));
413 /* How would you like that cooked? */
414 if (strlen(bstr("calview")) > 0) {
415 strcpy(calview, bstr("calview"));
418 strcpy(calview, "month");
421 /* Display the selected view */
422 if (!strcasecmp(calview, "day")) {
423 calendar_day_view(year, month, day);
425 else if (!strcasecmp(calview, "week")) {
426 calendar_week_view(year, month, day);
429 calendar_month_view(year, month, day);
432 /* Free the calendar stuff */
433 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
434 icalcomponent_free(WC->disp_cal[i]);
439 free(WC->cal_msgnum);
440 WC->cal_msgnum = NULL;
444 #endif /* HAVE_ICAL_H */