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 /* Outer table (to get the background color) */
75 wprintf("<TABLE width=100%% border=0 cellpadding=0 cellspacing=0 "
76 "bgcolor=#4444FF><TR><TD>\n");
78 wprintf("<CENTER><H3>");
80 tm = localtime(&previous_month);
81 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
82 (int)(tm->tm_year)+1900, tm->tm_mon);
83 wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/back.gif\" BORDER=0></A>\n");
85 wprintf(" "
86 "<FONT COLOR=#FFFFFF>"
89 " ", months[month], year);
91 tm = localtime(&next_month);
92 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
93 (int)(tm->tm_year)+1900, tm->tm_mon + 1);
94 wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/forward.gif\" BORDER=0></A>\n");
98 /* Inner table (the real one) */
99 wprintf("<TABLE width=100%% border=0 cellpadding=1 cellspacing=1 "
101 for (i=0; i<7; ++i) {
102 wprintf("<TH><FONT COLOR=#FFFFFF>%s</FONT></TH>", days[i]);
106 for (i = 0; i < 35; ++i) {
107 tm = localtime(&thetime);
108 if (tm->tm_wday == 0) {
112 wprintf("<TD BGCOLOR=FFFFFF WIDTH=14%%>");
113 if ((i==0) || (tm->tm_mday == 1)) {
114 wprintf("%s ", months[tm->tm_mon]);
116 wprintf("%d", tm->tm_mday);
118 /* FIXME ... put the data here, stupid */
119 wprintf("<BR><BR><BR>");
123 if (tm->tm_wday == 6) {
127 thetime += (time_t)86400; /* ahead 24 hours */
130 wprintf("</TABLE>" /* end of inner table */
131 "</TD></TR></TABLE>" /* end of outer table */
136 void calendar_week_view(int year, int month, int day) {
137 wprintf("<CENTER><I>week view FIXME</I></CENTER><BR>\n");
141 void calendar_day_view(int year, int month, int day) {
142 wprintf("<CENTER><I>day view FIXME</I></CENTER><BR>\n");
147 void do_calendar_view(void) {
150 int year, month, day;
153 /* In case no date was specified, go with today */
155 tm = localtime(&now);
156 year = tm->tm_year + 1900;
160 /* Now see if a date was specified */
161 if (strlen(bstr("year")) > 0) year = atoi(bstr("year"));
162 if (strlen(bstr("month")) > 0) month = atoi(bstr("month"));
163 if (strlen(bstr("day")) > 0) day = atoi(bstr("day"));
165 /* How would you like that cooked? */
166 if (strlen(bstr("calview")) > 0) {
167 strcpy(calview, bstr("calview"));
170 strcpy(calview, "month");
173 /* Display the selected view */
174 if (!strcasecmp(calview, "day")) {
175 calendar_day_view(year, month, day);
177 else if (!strcasecmp(calview, "week")) {
178 calendar_week_view(year, month, day);
181 calendar_month_view(year, month, day);
186 #endif /* HAVE_ICAL_H */