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 /****************************************************************************/
40 void calendar_month_view(int year, int month, int day) {
41 struct tm starting_tm;
45 time_t previous_month;
48 /* Determine what day to start.
49 * First, back up to the 1st of the month...
51 memset(&starting_tm, 0, sizeof(struct tm));
52 starting_tm.tm_year = year - 1900;
53 starting_tm.tm_mon = month;
54 starting_tm.tm_mday = day;
55 thetime = mktime(&starting_tm);
58 while (tm->tm_mday != 1) {
59 thetime = thetime - (time_t)86400; /* go back 24 hours */
60 tm = localtime(&thetime);
63 /* Determine previous and next months ... for links */
64 previous_month = thetime - (time_t)864000L; /* back 10 days */
65 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
67 /* Now back up until we're on a Sunday */
68 tm = localtime(&thetime);
69 while (tm->tm_wday != 0) {
70 thetime = thetime - (time_t)86400; /* go back 24 hours */
71 tm = localtime(&thetime);
74 wprintf("<CENTER><H2>");
76 tm = localtime(&previous_month);
77 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
78 (int)(tm->tm_year)+1900, tm->tm_mon);
79 wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/back.gif\" BORDER=0></A>\n");
81 wprintf(" %s %d ", months[month], year);
83 tm = localtime(&next_month);
84 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
85 (int)(tm->tm_year)+1900, tm->tm_mon + 1);
86 wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/forward.gif\" BORDER=0></A>\n");
90 wprintf("<TABLE border=1 width=100%%>");
92 wprintf("<TH>%s</TH>", days[i]);
96 for (i = 0; i < 35; ++i) {
97 tm = localtime(&thetime);
98 if (tm->tm_wday == 0) {
103 if ((i==0) || (tm->tm_mday == 1)) {
104 wprintf("%s ", months[tm->tm_mon]);
106 wprintf("%d", tm->tm_mday);
108 /* FIXME ... put the data here, stupid */
109 wprintf("<BR><BR><BR>");
113 if (tm->tm_wday == 6) {
117 thetime += (time_t)86400; /* ahead 24 hours */
120 wprintf("</TABLE></CENTER>\n");
124 void calendar_week_view(int year, int month, int day) {
125 wprintf("<CENTER><I>week view FIXME</I></CENTER><BR>\n");
129 void calendar_day_view(int year, int month, int day) {
130 wprintf("<CENTER><I>day view FIXME</I></CENTER><BR>\n");
135 void do_calendar_view(void) {
138 int year, month, day;
141 /* In case no date was specified, go with today */
143 tm = localtime(&now);
144 year = tm->tm_year + 1900;
148 /* Now see if a date was specified */
149 if (strlen(bstr("year")) > 0) year = atoi(bstr("year"));
150 if (strlen(bstr("month")) > 0) month = atoi(bstr("month"));
151 if (strlen(bstr("day")) > 0) day = atoi(bstr("day"));
153 /* How would you like that cooked? */
154 if (strlen(bstr("calview")) > 0) {
155 strcpy(calview, bstr("calview"));
158 strcpy(calview, "month");
161 /* Display the selected view */
162 if (!strcasecmp(calview, "day")) {
163 calendar_day_view(year, month, day);
165 else if (!strcasecmp(calview, "week")) {
166 calendar_week_view(year, month, day);
169 calendar_month_view(year, month, day);
174 #endif /* HAVE_ICAL_H */