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) {
47 struct icaltimetype t;
49 int all_day_event = 0;
51 if (WC->num_cal == 0) {
52 wprintf("<BR><BR><BR>\n");
56 memcpy(&today_tm, localtime(&thetime), sizeof(struct tm));
57 month = today_tm.tm_mon + 1;
58 day = today_tm.tm_mday;
59 year = today_tm.tm_year + 1900;
61 for (i=0; i<(WC->num_cal); ++i) {
62 p = icalcomponent_get_first_property(WC->disp_cal[i],
63 ICAL_DTSTART_PROPERTY);
65 t = icalproperty_get_dtstart(p);
66 event_tt = icaltime_as_timet(t);
67 memcpy(&event_tm, localtime(&event_tt), sizeof(struct tm));
68 if ((event_tm.tm_year == today_tm.tm_year)
69 && (event_tm.tm_mon == today_tm.tm_mon)
70 && (event_tm.tm_mday == today_tm.tm_mday)) {
72 if (t.is_date) all_day_event = 1;
73 else all_day_event = 0;
75 p = icalcomponent_get_first_property(
77 ICAL_SUMMARY_PROPERTY);
81 wprintf("<TABLE border=0 cellpadding=2><TR>"
82 "<TD BGCOLOR=#CCCCDD>"
86 wprintf("<FONT SIZE=-1>"
87 "<A HREF=\"/display_edit_event?msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\">",
95 icalproperty_get_comment(p));
96 wprintf("</A></FONT><BR>\n");
99 wprintf("</TD></TR></TABLE>");
113 void calendar_month_view(int year, int month, int day) {
114 struct tm starting_tm;
118 time_t previous_month;
121 /* Determine what day to start.
122 * First, back up to the 1st of the month...
124 memset(&starting_tm, 0, sizeof(struct tm));
125 starting_tm.tm_year = year - 1900;
126 starting_tm.tm_mon = month - 1;
127 starting_tm.tm_mday = day;
128 thetime = mktime(&starting_tm);
131 while (tm->tm_mday != 1) {
132 thetime = thetime - (time_t)86400; /* go back 24 hours */
133 tm = localtime(&thetime);
136 /* Determine previous and next months ... for links */
137 previous_month = thetime - (time_t)864000L; /* back 10 days */
138 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
140 /* Now back up until we're on a Sunday */
141 tm = localtime(&thetime);
142 while (tm->tm_wday != 0) {
143 thetime = thetime - (time_t)86400; /* go back 24 hours */
144 tm = localtime(&thetime);
147 /* Outer table (to get the background color) */
148 wprintf("<TABLE width=100%% border=0 cellpadding=0 cellspacing=0 "
149 "bgcolor=#4444FF><TR><TD>\n");
151 wprintf("<TABLE width=100%% border=0 cellpadding=0 cellspacing=0>"
152 "<TR><TD align=left><font color=#FFFFFF>"
153 " <A HREF=\"/display_edit_event?msgnum=0"
154 "&year=%d&month=%d&day=%d\">"
155 "Add new calendar event</A>"
160 wprintf("<TD><CENTER><H3>");
162 tm = localtime(&previous_month);
163 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
164 (int)(tm->tm_year)+1900, tm->tm_mon + 1);
165 wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/back.gif\" BORDER=0></A>\n");
167 wprintf(" "
168 "<FONT COLOR=#FFFFFF>"
171 " ", months[month-1], year);
173 tm = localtime(&next_month);
174 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
175 (int)(tm->tm_year)+1900, tm->tm_mon + 1);
176 wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/forward.gif\" BORDER=0></A>\n");
178 wprintf("</H3></TD><TD align=right><font color=#FFFFFF size=-2>"
179 "Click on any date for day view "
180 "</FONT></TD></TR></TABLE>\n");
182 /* Inner table (the real one) */
183 wprintf("<TABLE width=100%% border=0 cellpadding=1 cellspacing=1 "
185 for (i=0; i<7; ++i) {
186 wprintf("<TH><FONT COLOR=#FFFFFF>%s</FONT></TH>", days[i]);
190 for (i = 0; i < 35; ++i) {
191 tm = localtime(&thetime);
192 if (tm->tm_wday == 0) {
196 wprintf("<TD BGCOLOR=%s WIDTH=14%% HEIGHT=60 VALIGN=TOP><B>",
197 ((tm->tm_mon != month-1) ? "DDDDDD" :
198 ((tm->tm_wday==0 || tm->tm_wday==6) ? "EEEECC" :
201 if ((i==0) || (tm->tm_mday == 1)) {
202 wprintf("%s ", months[tm->tm_mon]);
204 wprintf("<A HREF=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
211 /* put the data here, stupid */
212 calendar_month_view_display_events(thetime);
216 if (tm->tm_wday == 6) {
220 thetime += (time_t)86400; /* ahead 24 hours */
223 wprintf("</TABLE>" /* end of inner table */
224 "</TD></TR></TABLE>" /* end of outer table */
229 void calendar_week_view(int year, int month, int day) {
230 wprintf("<CENTER><I>week view FIXME</I></CENTER><BR>\n");
235 * Display events for a particular hour of a particular day.
236 * (Specify hour < 0 to show "all day" events)
238 void calendar_day_view_display_events(int year, int month,
242 struct icaltimetype t;
245 int all_day_event = 0;
247 if (WC->num_cal == 0) {
248 wprintf("<BR><BR><BR>\n");
252 for (i=0; i<(WC->num_cal); ++i) {
253 p = icalcomponent_get_first_property(WC->disp_cal[i],
254 ICAL_DTSTART_PROPERTY);
256 t = icalproperty_get_dtstart(p);
257 event_tt = icaltime_as_timet(t);
258 event_tm = localtime(&event_tt);
259 if ((event_tm->tm_year == (year-1900))
260 && (event_tm->tm_mon == (month-1))
261 && (event_tm->tm_mday == day)
262 && ( ((event_tm->tm_hour == hour)&&(!t.is_date)) || ((hour<0)&&(t.is_date)) )
265 if (t.is_date) all_day_event = 1;
267 p = icalcomponent_get_first_property(
269 ICAL_SUMMARY_PROPERTY);
273 wprintf("<TABLE border=1 cellpadding=2><TR>"
274 "<TD BGCOLOR=#CCCCCC>"
278 wprintf("<FONT SIZE=-1>"
279 "<A HREF=\"/display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d\">",
284 icalproperty_get_comment(p));
285 wprintf("</A></FONT><BR>\n");
288 wprintf("</TD></TR></TABLE>");
301 void calendar_day_view(int year, int month, int day) {
303 struct icaltimetype today, yesterday, tomorrow;
306 /* Figure out the dates for "yesterday" and "tomorrow" links */
308 memset(&today, 0, sizeof(struct icaltimetype));
314 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
316 yesterday = icaltime_normalize(yesterday);
318 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
320 tomorrow = icaltime_normalize(tomorrow);
323 /* Outer table (to get the background color) */
324 wprintf("<TABLE width=100%% border=0 cellpadding=0 cellspacing=0 "
325 "bgcolor=#4444FF><TR><TD>\n");
327 /* Inner table (the real one) */
328 wprintf("<TABLE width=100%% border=0 cellpadding=1 cellspacing=1 "
329 "bgcolor=#4444FF><TR>\n");
331 /* Innermost table (contains hours etc.) */
332 wprintf("<TD WIDTH=80%%>"
333 "<TABLE width=100%% border=0 cellpadding=1 cellspacing=1 "
334 "bgcolor=#4444FF>\n");
336 /* Display events before 8:00 (hour=-1 is all-day events) */
338 "<TD BGCOLOR=CCCCDD VALIGN=MIDDLE WIDTH=10%%></TD>"
339 "<TD BGCOLOR=FFFFFF VALIGN=TOP>");
340 for (hour = (-1); hour <= 7; ++hour) {
341 calendar_day_view_display_events(year, month, day, hour);
343 wprintf("</TD></TR>\n");
345 /* Now the middle of the day... */
346 for (hour = 8; hour <= 17; ++hour) { /* could do HEIGHT=xx */
347 wprintf("<TR HEIGHT=30><TD BGCOLOR=CCCCDD ALIGN=MIDDLE "
348 "VALIGN=MIDDLE WIDTH=10%%>");
349 wprintf("<A HREF=\"/display_edit_event?msgnum=0"
350 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
351 year, month, day, hour
353 wprintf("%d:00%s</A> ",
354 (hour <= 12 ? hour : hour-12),
355 (hour < 12 ? "am" : "pm")
357 wprintf("</TD><TD BGCOLOR=FFFFFF VALIGN=TOP>");
359 /* put the data here, stupid */
360 calendar_day_view_display_events(year, month, day, hour);
362 wprintf("</TD></TR>\n");
365 /* Display events after 5:00... */
367 "<TD BGCOLOR=CCCCDD VALIGN=MIDDLE WIDTH=10%%></TD>"
368 "<TD BGCOLOR=FFFFFF VALIGN=TOP>");
369 for (hour = 18; hour <= 23; ++hour) {
370 calendar_day_view_display_events(year, month, day, hour);
372 wprintf("</TD></TR>\n");
375 wprintf("</TABLE>" /* end of innermost table */
379 wprintf("<TD WIDTH=20%% VALIGN=top>"); /* begin stuff-on-the-right */
382 /* Begin todays-date-with-left-and-right-arrows */
383 wprintf("<CENTER><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=1><TR>\n");
386 "<A HREF=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
387 yesterday.year, yesterday.month, yesterday.day
389 wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/back.gif\" BORDER=0></A>"
392 wprintf("<TD ALIGN=MIDDLE><FONT COLOR=#FFFFFF>"
393 "<H2>%s</H2><H1>%d</H1><H3>%d</H3>"
395 months[month-1], day, year);
398 "<A HREF=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
399 tomorrow.year, tomorrow.month, tomorrow.day
401 wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/forward.gif\""
402 " BORDER=0></A></TD>\n");
404 wprintf("</TR></TABLE></CENTER>\n");
405 /* End todays-date-with-left-and-right-arrows */
407 wprintf("<CENTER><font color=#FFFFFF>"
408 " <A HREF=\"/display_edit_event?msgnum=0"
409 "&year=%d&month=%d&day=%d\">"
410 "Add new calendar event</A>"
415 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">"
416 "Back to month view</A>\n", year, month);
418 wprintf("</FONT></CENTER>\n");
420 wprintf("</TD>"); /* end stuff-on-the-right */
424 wprintf("</TR></TABLE>" /* end of inner table */
425 "</TD></TR></TABLE>" /* end of outer table */
435 void do_calendar_view(void) {
439 int year, month, day;
442 /* In case no date was specified, go with today */
444 tm = localtime(&now);
445 year = tm->tm_year + 1900;
446 month = tm->tm_mon + 1;
449 /* Now see if a date was specified */
450 if (strlen(bstr("year")) > 0) year = atoi(bstr("year"));
451 if (strlen(bstr("month")) > 0) month = atoi(bstr("month"));
452 if (strlen(bstr("day")) > 0) day = atoi(bstr("day"));
454 /* How would you like that cooked? */
455 if (strlen(bstr("calview")) > 0) {
456 strcpy(calview, bstr("calview"));
459 strcpy(calview, "month");
462 /* Display the selected view */
463 if (!strcasecmp(calview, "day")) {
464 calendar_day_view(year, month, day);
466 else if (!strcasecmp(calview, "week")) {
467 calendar_week_view(year, month, day);
470 calendar_month_view(year, month, day);
473 /* Free the calendar stuff */
474 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
475 icalcomponent_free(WC->disp_cal[i]);
480 free(WC->cal_msgnum);
481 WC->cal_msgnum = NULL;
485 #endif /* HAVE_ICAL_H */