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("<CENTER><H3>");
133 tm = localtime(&previous_month);
134 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
135 (int)(tm->tm_year)+1900, tm->tm_mon + 1);
136 wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/back.gif\" BORDER=0></A>\n");
138 wprintf(" "
139 "<FONT COLOR=#FFFFFF>"
142 " ", months[month-1], year);
144 tm = localtime(&next_month);
145 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
146 (int)(tm->tm_year)+1900, tm->tm_mon + 1);
147 wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/forward.gif\" BORDER=0></A>\n");
151 /* Inner table (the real one) */
152 wprintf("<TABLE width=100%% border=0 cellpadding=1 cellspacing=1 "
154 for (i=0; i<7; ++i) {
155 wprintf("<TH><FONT COLOR=#FFFFFF>%s</FONT></TH>", days[i]);
159 for (i = 0; i < 35; ++i) {
160 tm = localtime(&thetime);
161 if (tm->tm_wday == 0) {
165 wprintf("<TD BGCOLOR=FFFFFF WIDTH=14%% HEIGHT=60 VALIGN=TOP>"
167 if ((i==0) || (tm->tm_mday == 1)) {
168 wprintf("%s ", months[tm->tm_mon]);
170 wprintf("<A HREF=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
177 /* put the data here, stupid */
178 calendar_month_view_display_events(thetime);
182 if (tm->tm_wday == 6) {
186 thetime += (time_t)86400; /* ahead 24 hours */
189 wprintf("</TABLE>" /* end of inner table */
190 "</TD></TR></TABLE>" /* end of outer table */
195 void calendar_week_view(int year, int month, int day) {
196 wprintf("<CENTER><I>week view FIXME</I></CENTER><BR>\n");
200 void calendar_day_view(int year, int month, int day) {
201 struct tm starting_tm;
204 /* Determine what day we're viewing.
206 memset(&starting_tm, 0, sizeof(struct tm));
207 starting_tm.tm_year = year - 1900;
208 starting_tm.tm_mon = month - 1;
209 starting_tm.tm_mday = day;
210 thetime = mktime(&starting_tm);
212 wprintf("<CENTER><H3>%s %d, %d</H3></CENTER>\n",
213 months[month-1], day, year);
215 /* put the data here, stupid */
216 calendar_month_view_display_events(thetime);
218 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">"
219 "Back to month view</A><BR>\n", year, month);
225 void do_calendar_view(void) {
229 int year, month, day;
232 /* In case no date was specified, go with today */
234 tm = localtime(&now);
235 year = tm->tm_year + 1900;
236 month = tm->tm_mon + 1;
239 /* Now see if a date was specified */
240 if (strlen(bstr("year")) > 0) year = atoi(bstr("year"));
241 if (strlen(bstr("month")) > 0) month = atoi(bstr("month"));
242 if (strlen(bstr("day")) > 0) day = atoi(bstr("day"));
244 /* How would you like that cooked? */
245 if (strlen(bstr("calview")) > 0) {
246 strcpy(calview, bstr("calview"));
249 strcpy(calview, "month");
252 /* Display the selected view */
253 if (!strcasecmp(calview, "day")) {
254 calendar_day_view(year, month, day);
256 else if (!strcasecmp(calview, "week")) {
257 calendar_week_view(year, month, day);
260 calendar_month_view(year, month, day);
263 /* Free the calendar stuff */
264 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
265 icalcomponent_free(WC->disp_cal[i]);
270 free(WC->cal_msgnum);
271 WC->cal_msgnum = NULL;
275 #endif /* HAVE_ICAL_H */