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 /****************************************************************************/
39 void calendar_month_view_display_events(time_t thetime) {
43 struct icaltimetype t;
46 if (WC->num_cal == 0) {
47 wprintf("<BR><BR><BR>\n");
51 tm = localtime(&thetime);
52 month = tm->tm_mon + 1;
54 year = tm->tm_year + 1900;
56 for (i=0; i<(WC->num_cal); ++i) {
57 p = icalcomponent_get_first_property(WC->disp_cal[i],
58 ICAL_DTSTART_PROPERTY);
60 t = icalproperty_get_dtstart(p);
65 p = icalcomponent_get_first_property(
67 ICAL_SUMMARY_PROPERTY);
69 wprintf("<FONT SIZE=-1>"
70 "<A HREF=\"/display_edit_event?msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\">",
78 icalproperty_get_comment(p));
79 wprintf("</A></FONT>\n");
91 void calendar_month_view(int year, int month, int day) {
92 struct tm starting_tm;
96 time_t previous_month;
99 /* Determine what day to start.
100 * First, back up to the 1st of the month...
102 memset(&starting_tm, 0, sizeof(struct tm));
103 starting_tm.tm_year = year - 1900;
104 starting_tm.tm_mon = month - 1;
105 starting_tm.tm_mday = day;
106 thetime = mktime(&starting_tm);
109 while (tm->tm_mday != 1) {
110 thetime = thetime - (time_t)86400; /* go back 24 hours */
111 tm = localtime(&thetime);
114 /* Determine previous and next months ... for links */
115 previous_month = thetime - (time_t)864000L; /* back 10 days */
116 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
117 lprintf(9, "previous month is %s", asctime(localtime(&previous_month)));
118 lprintf(9, "next month is %s", asctime(localtime(&next_month)));
120 /* Now back up until we're on a Sunday */
121 tm = localtime(&thetime);
122 while (tm->tm_wday != 0) {
123 thetime = thetime - (time_t)86400; /* go back 24 hours */
124 tm = localtime(&thetime);
127 /* Outer table (to get the background color) */
128 wprintf("<TABLE width=100%% border=0 cellpadding=0 cellspacing=0 "
129 "bgcolor=#4444FF><TR><TD>\n");
131 wprintf("<TABLE width=100%% border=0 cellpadding=0 cellspacing=0>"
132 "<TR><TD align=left><font color=#FFFFFF>"
133 " <A HREF=\"/display_edit_event?msgnum=0\">"
134 "Add new calendar event</A>"
137 wprintf("<TD><CENTER><H3>");
139 tm = localtime(&previous_month);
140 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
141 (int)(tm->tm_year)+1900, tm->tm_mon + 1);
142 wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/back.gif\" BORDER=0></A>\n");
144 wprintf(" "
145 "<FONT COLOR=#FFFFFF>"
148 " ", months[month-1], year);
150 tm = localtime(&next_month);
151 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
152 (int)(tm->tm_year)+1900, tm->tm_mon + 1);
153 wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/forward.gif\" BORDER=0></A>\n");
155 wprintf("</H3></TD><TD align=right><font color=#FFFFFF size=-2>"
156 "Click on any date for day view "
157 "</FONT></TD></TR></TABLE>\n");
159 /* Inner table (the real one) */
160 wprintf("<TABLE width=100%% border=0 cellpadding=1 cellspacing=1 "
162 for (i=0; i<7; ++i) {
163 wprintf("<TH><FONT COLOR=#FFFFFF>%s</FONT></TH>", days[i]);
167 for (i = 0; i < 35; ++i) {
168 tm = localtime(&thetime);
169 if (tm->tm_wday == 0) {
173 wprintf("<TD BGCOLOR=FFFFFF WIDTH=14%% HEIGHT=60 VALIGN=TOP>"
175 if ((i==0) || (tm->tm_mday == 1)) {
176 wprintf("%s ", months[tm->tm_mon]);
178 wprintf("<A HREF=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
185 /* put the data here, stupid */
186 calendar_month_view_display_events(thetime);
190 if (tm->tm_wday == 6) {
194 thetime += (time_t)86400; /* ahead 24 hours */
197 wprintf("</TABLE>" /* end of inner table */
198 "</TD></TR></TABLE>" /* end of outer table */
203 void calendar_week_view(int year, int month, int day) {
204 wprintf("<CENTER><I>week view FIXME</I></CENTER><BR>\n");
208 void calendar_day_view(int year, int month, int day) {
209 struct tm starting_tm;
213 /* Determine what day we're viewing.
215 memset(&starting_tm, 0, sizeof(struct tm));
216 starting_tm.tm_year = year - 1900;
217 starting_tm.tm_mon = month - 1;
218 starting_tm.tm_mday = day;
219 thetime = mktime(&starting_tm);
222 /**********************************************************************/
224 /* Outer table (to get the background color) */
225 wprintf("<TABLE width=100%% border=0 cellpadding=0 cellspacing=0 "
226 "bgcolor=#4444FF><TR><TD>\n");
228 /* Inner table (the real one) */
229 wprintf("<TABLE width=100%% border=0 cellpadding=1 cellspacing=1 "
230 "bgcolor=#4444FF><TR>\n");
232 wprintf("<TD WIDTH=50%% VALIGN=top>"); /* begin stuff-on-the-left */
234 wprintf("<CENTER><H3><FONT COLOR=#FFFFFF>"
236 "</FONT></H3></CENTER>\n",
237 months[month-1], day, year);
239 wprintf("<CENTER><font color=#FFFFFF>"
240 " <A HREF=\"/display_edit_event?msgnum=0\">"
241 "Add new calendar event</A>"
244 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">"
245 "Back to month view</A>\n", year, month);
247 wprintf("</FONT></CENTER>\n");
249 wprintf("</TD>"); /* end stuff-on-the-left */
251 /* Innermost table (contains hours etc.) */
252 wprintf("<TD WIDTH=50%%>"
253 "<TABLE width=100%% border=0 cellpadding=1 cellspacing=1 "
254 "bgcolor=#4444FF>\n");
257 for (i = 0; i < 7; ++i) {
258 wprintf("<TR><TD BGCOLOR=FFFFFF HEIGHT=60 VALIGN=TOP>");
260 /* put the data here, stupid ... FIXME add hour */
261 calendar_month_view_display_events(thetime);
263 wprintf("</TD></TR>\n");
266 wprintf("</TABLE>" /* end of innermost table */
267 "</TD></TR></TABLE>" /* end of inner table */
268 "</TD></TR></TABLE>" /* end of outer table */
278 void do_calendar_view(void) {
282 int year, month, day;
285 /* In case no date was specified, go with today */
287 tm = localtime(&now);
288 year = tm->tm_year + 1900;
289 month = tm->tm_mon + 1;
292 /* Now see if a date was specified */
293 if (strlen(bstr("year")) > 0) year = atoi(bstr("year"));
294 if (strlen(bstr("month")) > 0) month = atoi(bstr("month"));
295 if (strlen(bstr("day")) > 0) day = atoi(bstr("day"));
297 /* How would you like that cooked? */
298 if (strlen(bstr("calview")) > 0) {
299 strcpy(calview, bstr("calview"));
302 strcpy(calview, "month");
305 /* Display the selected view */
306 if (!strcasecmp(calview, "day")) {
307 calendar_day_view(year, month, day);
309 else if (!strcasecmp(calview, "week")) {
310 calendar_week_view(year, month, day);
313 calendar_month_view(year, month, day);
316 /* Free the calendar stuff */
317 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
318 icalcomponent_free(WC->disp_cal[i]);
323 free(WC->cal_msgnum);
324 WC->cal_msgnum = NULL;
328 #endif /* HAVE_ICAL_H */