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\">",
74 icalproperty_get_comment(p));
75 wprintf("</A></FONT>\n");
87 void calendar_month_view(int year, int month, int day) {
88 struct tm starting_tm;
92 time_t previous_month;
95 /* Determine what day to start.
96 * First, back up to the 1st of the month...
98 memset(&starting_tm, 0, sizeof(struct tm));
99 starting_tm.tm_year = year - 1900;
100 starting_tm.tm_mon = month - 1;
101 starting_tm.tm_mday = day;
102 thetime = mktime(&starting_tm);
105 while (tm->tm_mday != 1) {
106 thetime = thetime - (time_t)86400; /* go back 24 hours */
107 tm = localtime(&thetime);
110 /* Determine previous and next months ... for links */
111 previous_month = thetime - (time_t)864000L; /* back 10 days */
112 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
113 lprintf(9, "previous month is %s", asctime(localtime(&previous_month)));
114 lprintf(9, "next month is %s", asctime(localtime(&next_month)));
116 /* Now back up until we're on a Sunday */
117 tm = localtime(&thetime);
118 while (tm->tm_wday != 0) {
119 thetime = thetime - (time_t)86400; /* go back 24 hours */
120 tm = localtime(&thetime);
123 /* Outer table (to get the background color) */
124 wprintf("<TABLE width=100%% border=0 cellpadding=0 cellspacing=0 "
125 "bgcolor=#4444FF><TR><TD>\n");
127 wprintf("<CENTER><H3>");
129 tm = localtime(&previous_month);
130 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
131 (int)(tm->tm_year)+1900, tm->tm_mon + 1);
132 wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/back.gif\" BORDER=0></A>\n");
134 wprintf(" "
135 "<FONT COLOR=#FFFFFF>"
138 " ", months[month-1], year);
140 tm = localtime(&next_month);
141 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
142 (int)(tm->tm_year)+1900, tm->tm_mon + 1);
143 wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/forward.gif\" BORDER=0></A>\n");
147 /* Inner table (the real one) */
148 wprintf("<TABLE width=100%% border=0 cellpadding=1 cellspacing=1 "
150 for (i=0; i<7; ++i) {
151 wprintf("<TH><FONT COLOR=#FFFFFF>%s</FONT></TH>", days[i]);
155 for (i = 0; i < 35; ++i) {
156 tm = localtime(&thetime);
157 if (tm->tm_wday == 0) {
161 wprintf("<TD BGCOLOR=FFFFFF WIDTH=14%% HEIGHT=60 VALIGN=TOP>"
163 if ((i==0) || (tm->tm_mday == 1)) {
164 wprintf("%s ", months[tm->tm_mon]);
166 wprintf("<A HREF=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
173 /* put the data here, stupid */
174 calendar_month_view_display_events(thetime);
178 if (tm->tm_wday == 6) {
182 thetime += (time_t)86400; /* ahead 24 hours */
185 wprintf("</TABLE>" /* end of inner table */
186 "</TD></TR></TABLE>" /* end of outer table */
191 void calendar_week_view(int year, int month, int day) {
192 wprintf("<CENTER><I>week view FIXME</I></CENTER><BR>\n");
196 void calendar_day_view(int year, int month, int day) {
197 struct tm starting_tm;
200 /* Determine what day we're viewing.
202 memset(&starting_tm, 0, sizeof(struct tm));
203 starting_tm.tm_year = year - 1900;
204 starting_tm.tm_mon = month - 1;
205 starting_tm.tm_mday = day;
206 thetime = mktime(&starting_tm);
208 wprintf("<CENTER><H3>%s %d, %d</H3></CENTER>\n",
209 months[month-1], day, year);
211 /* put the data here, stupid */
212 calendar_month_view_display_events(thetime);
214 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">"
215 "Back to month view</A><BR>\n", year, month);
221 void do_calendar_view(void) {
225 int year, month, day;
228 /* In case no date was specified, go with today */
230 tm = localtime(&now);
231 year = tm->tm_year + 1900;
232 month = tm->tm_mon + 1;
235 /* Now see if a date was specified */
236 if (strlen(bstr("year")) > 0) year = atoi(bstr("year"));
237 if (strlen(bstr("month")) > 0) month = atoi(bstr("month"));
238 if (strlen(bstr("day")) > 0) day = atoi(bstr("day"));
240 /* How would you like that cooked? */
241 if (strlen(bstr("calview")) > 0) {
242 strcpy(calview, bstr("calview"));
245 strcpy(calview, "month");
248 /* Display the selected view */
249 if (!strcasecmp(calview, "day")) {
250 calendar_day_view(year, month, day);
252 else if (!strcasecmp(calview, "week")) {
253 calendar_week_view(year, month, day);
256 calendar_month_view(year, month, day);
259 /* Free the calendar stuff */
260 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
261 icalcomponent_free(WC->disp_cal[i]);
266 free(WC->cal_msgnum);
267 WC->cal_msgnum = NULL;
271 #endif /* HAVE_ICAL_H */