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);
130 memcpy(&tm, &starting_tm, sizeof(struct tm));
131 while (tm.tm_mday != 1) {
132 thetime = thetime - (time_t)86400; /* go back 24 hours */
133 memcpy(&tm, localtime(&thetime), sizeof(struct tm));
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 memcpy(&tm, localtime(&thetime), sizeof(struct tm));
142 while (tm.tm_wday != 0) {
143 thetime = thetime - (time_t)86400; /* go back 24 hours */
144 memcpy(&tm, localtime(&thetime), sizeof(struct tm));
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 memcpy(&tm, localtime(&previous_month), sizeof(struct tm));
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 memcpy(&tm, localtime(&next_month), sizeof(struct tm));
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 memcpy(&tm, localtime(&thetime), sizeof(struct tm));
193 /* Before displaying Sunday, start a new row */
198 wprintf("<TD BGCOLOR=%s WIDTH=14%% HEIGHT=60 VALIGN=TOP><B>",
199 ((tm.tm_mon != month-1) ? "DDDDDD" :
200 ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
203 if ((i==0) || (tm.tm_mday == 1)) {
204 wprintf("%s ", months[tm.tm_mon]);
206 wprintf("<A HREF=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
213 /* put the data here, stupid */
214 calendar_month_view_display_events(thetime);
218 /* After displaying Saturday, end the row */
223 thetime += (time_t)86400; /* ahead 24 hours */
226 wprintf("</TABLE>" /* end of inner table */
227 "</TD></TR></TABLE>" /* end of outer table */
232 void calendar_week_view(int year, int month, int day) {
233 wprintf("<CENTER><I>week view FIXME</I></CENTER><BR>\n");
238 * Display events for a particular hour of a particular day.
239 * (Specify hour < 0 to show "all day" events)
241 void calendar_day_view_display_events(int year, int month,
245 struct icaltimetype t;
248 int all_day_event = 0;
250 if (WC->num_cal == 0) {
251 wprintf("<BR><BR><BR>\n");
255 for (i=0; i<(WC->num_cal); ++i) {
256 p = icalcomponent_get_first_property(WC->disp_cal[i],
257 ICAL_DTSTART_PROPERTY);
259 t = icalproperty_get_dtstart(p);
260 event_tt = icaltime_as_timet(t);
261 event_tm = localtime(&event_tt);
262 if ((event_tm->tm_year == (year-1900))
263 && (event_tm->tm_mon == (month-1))
264 && (event_tm->tm_mday == day)
265 && ( ((event_tm->tm_hour == hour)&&(!t.is_date)) || ((hour<0)&&(t.is_date)) )
268 if (t.is_date) all_day_event = 1;
270 p = icalcomponent_get_first_property(
272 ICAL_SUMMARY_PROPERTY);
276 wprintf("<TABLE border=1 cellpadding=2><TR>"
277 "<TD BGCOLOR=#CCCCCC>"
281 wprintf("<FONT SIZE=-1>"
282 "<A HREF=\"/display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d\">",
287 icalproperty_get_comment(p));
288 wprintf("</A></FONT><BR>\n");
291 wprintf("</TD></TR></TABLE>");
304 void calendar_day_view(int year, int month, int day) {
306 struct icaltimetype today, yesterday, tomorrow;
309 /* Figure out the dates for "yesterday" and "tomorrow" links */
311 memset(&today, 0, sizeof(struct icaltimetype));
317 memcpy(&yesterday, &today, sizeof(struct icaltimetype));
319 yesterday = icaltime_normalize(yesterday);
321 memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
323 tomorrow = icaltime_normalize(tomorrow);
326 /* Outer table (to get the background color) */
327 wprintf("<TABLE width=100%% border=0 cellpadding=0 cellspacing=0 "
328 "bgcolor=#4444FF><TR><TD>\n");
330 /* Inner table (the real one) */
331 wprintf("<TABLE width=100%% border=0 cellpadding=1 cellspacing=1 "
332 "bgcolor=#4444FF><TR>\n");
334 /* Innermost table (contains hours etc.) */
335 wprintf("<TD WIDTH=80%%>"
336 "<TABLE width=100%% border=0 cellpadding=1 cellspacing=1 "
337 "bgcolor=#4444FF>\n");
339 /* Display events before 8:00 (hour=-1 is all-day events) */
341 "<TD BGCOLOR=CCCCDD VALIGN=MIDDLE WIDTH=10%%></TD>"
342 "<TD BGCOLOR=FFFFFF VALIGN=TOP>");
343 for (hour = (-1); hour <= 7; ++hour) {
344 calendar_day_view_display_events(year, month, day, hour);
346 wprintf("</TD></TR>\n");
348 /* Now the middle of the day... */
349 for (hour = 8; hour <= 17; ++hour) { /* could do HEIGHT=xx */
350 wprintf("<TR HEIGHT=30><TD BGCOLOR=CCCCDD ALIGN=MIDDLE "
351 "VALIGN=MIDDLE WIDTH=10%%>");
352 wprintf("<A HREF=\"/display_edit_event?msgnum=0"
353 "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
354 year, month, day, hour
356 wprintf("%d:00%s</A> ",
357 (hour <= 12 ? hour : hour-12),
358 (hour < 12 ? "am" : "pm")
360 wprintf("</TD><TD BGCOLOR=FFFFFF VALIGN=TOP>");
362 /* put the data here, stupid */
363 calendar_day_view_display_events(year, month, day, hour);
365 wprintf("</TD></TR>\n");
368 /* Display events after 5:00... */
370 "<TD BGCOLOR=CCCCDD VALIGN=MIDDLE WIDTH=10%%></TD>"
371 "<TD BGCOLOR=FFFFFF VALIGN=TOP>");
372 for (hour = 18; hour <= 23; ++hour) {
373 calendar_day_view_display_events(year, month, day, hour);
375 wprintf("</TD></TR>\n");
378 wprintf("</TABLE>" /* end of innermost table */
382 wprintf("<TD WIDTH=20%% VALIGN=top>"); /* begin stuff-on-the-right */
385 /* Begin todays-date-with-left-and-right-arrows */
386 wprintf("<CENTER><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=1><TR>\n");
389 "<A HREF=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
390 yesterday.year, yesterday.month, yesterday.day
392 wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/back.gif\" BORDER=0></A>"
395 wprintf("<TD ALIGN=MIDDLE><FONT COLOR=#FFFFFF>"
396 "<H2>%s</H2><H1>%d</H1><H3>%d</H3>"
398 months[month-1], day, year);
401 "<A HREF=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
402 tomorrow.year, tomorrow.month, tomorrow.day
404 wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/forward.gif\""
405 " BORDER=0></A></TD>\n");
407 wprintf("</TR></TABLE></CENTER>\n");
408 /* End todays-date-with-left-and-right-arrows */
410 wprintf("<CENTER><font color=#FFFFFF>"
411 " <A HREF=\"/display_edit_event?msgnum=0"
412 "&year=%d&month=%d&day=%d\">"
413 "Add new calendar event</A>"
418 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">"
419 "Back to month view</A>\n", year, month);
421 wprintf("</FONT></CENTER>\n");
423 wprintf("</TD>"); /* end stuff-on-the-right */
427 wprintf("</TR></TABLE>" /* end of inner table */
428 "</TD></TR></TABLE>" /* end of outer table */
436 * Display today's events.
438 void calendar_summary_view(void) {
441 struct icaltimetype t;
446 int all_day_event = 0;
447 char timestring[SIZ];
449 if (WC->num_cal == 0) {
454 memcpy(&today_tm, localtime(&now), sizeof(struct tm));
458 for (i=0; i<(WC->num_cal); ++i) {
459 p = icalcomponent_get_first_property(WC->disp_cal[i],
460 ICAL_DTSTART_PROPERTY);
462 t = icalproperty_get_dtstart(p);
463 event_tt = icaltime_as_timet(t);
464 fmt_time(timestring, event_tt);
465 memcpy(&event_tm, localtime(&event_tt), sizeof(struct tm));
466 if ( (event_tm.tm_year == today_tm.tm_year)
467 && (event_tm.tm_mon == today_tm.tm_mon)
468 && (event_tm.tm_mday == today_tm.tm_mday)
471 if (t.is_date) all_day_event = 1;
473 p = icalcomponent_get_first_property(
475 ICAL_SUMMARY_PROPERTY);
479 icalproperty_get_comment(p));
480 wprintf(" (%s)\n", timestring);
486 free_calendar_buffer();
491 void free_calendar_buffer(void) {
493 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
494 icalcomponent_free(WC->disp_cal[i]);
499 free(WC->cal_msgnum);
500 WC->cal_msgnum = NULL;
506 void do_calendar_view(void) {
509 int year, month, day;
512 /* In case no date was specified, go with today */
514 memcpy(&tm, localtime(&now), sizeof(struct tm));
515 year = tm.tm_year + 1900;
516 month = tm.tm_mon + 1;
519 /* Now see if a date was specified */
520 if (strlen(bstr("year")) > 0) year = atoi(bstr("year"));
521 if (strlen(bstr("month")) > 0) month = atoi(bstr("month"));
522 if (strlen(bstr("day")) > 0) day = atoi(bstr("day"));
524 /* How would you like that cooked? */
525 if (strlen(bstr("calview")) > 0) {
526 strcpy(calview, bstr("calview"));
529 strcpy(calview, "month");
532 /* Display the selected view */
533 if (!strcasecmp(calview, "day")) {
534 calendar_day_view(year, month, day);
536 else if (!strcasecmp(calview, "week")) {
537 calendar_week_view(year, month, day);
540 calendar_month_view(year, month, day);
543 /* Free the calendar stuff */
544 free_calendar_buffer();
548 #endif /* HAVE_ICAL_H */