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);
70 icalproperty_get_comment(p));
82 void calendar_month_view(int year, int month, int day) {
83 struct tm starting_tm;
87 time_t previous_month;
90 /* Determine what day to start.
91 * First, back up to the 1st of the month...
93 memset(&starting_tm, 0, sizeof(struct tm));
94 starting_tm.tm_year = year - 1900;
95 starting_tm.tm_mon = month;
96 starting_tm.tm_mday = day;
97 thetime = mktime(&starting_tm);
100 while (tm->tm_mday != 1) {
101 thetime = thetime - (time_t)86400; /* go back 24 hours */
102 tm = localtime(&thetime);
105 /* Determine previous and next months ... for links */
106 previous_month = thetime - (time_t)864000L; /* back 10 days */
107 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
109 /* Now back up until we're on a Sunday */
110 tm = localtime(&thetime);
111 while (tm->tm_wday != 0) {
112 thetime = thetime - (time_t)86400; /* go back 24 hours */
113 tm = localtime(&thetime);
116 /* Outer table (to get the background color) */
117 wprintf("<TABLE width=100%% border=0 cellpadding=0 cellspacing=0 "
118 "bgcolor=#4444FF><TR><TD>\n");
120 wprintf("<CENTER><H3>");
122 tm = localtime(&previous_month);
123 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
124 (int)(tm->tm_year)+1900, tm->tm_mon);
125 wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/back.gif\" BORDER=0></A>\n");
127 wprintf(" "
128 "<FONT COLOR=#FFFFFF>"
131 " ", months[month], year);
133 tm = localtime(&next_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/forward.gif\" BORDER=0></A>\n");
140 /* Inner table (the real one) */
141 wprintf("<TABLE width=100%% border=0 cellpadding=1 cellspacing=1 "
143 for (i=0; i<7; ++i) {
144 wprintf("<TH><FONT COLOR=#FFFFFF>%s</FONT></TH>", days[i]);
148 for (i = 0; i < 35; ++i) {
149 tm = localtime(&thetime);
150 if (tm->tm_wday == 0) {
154 wprintf("<TD BGCOLOR=FFFFFF WIDTH=14%% HEIGHT=60 VALIGN=TOP>"
156 if ((i==0) || (tm->tm_mday == 1)) {
157 wprintf("%s ", months[tm->tm_mon]);
159 wprintf("<A HREF=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
166 /* put the data here, stupid */
167 calendar_month_view_display_events(thetime);
171 if (tm->tm_wday == 6) {
175 thetime += (time_t)86400; /* ahead 24 hours */
178 wprintf("</TABLE>" /* end of inner table */
179 "</TD></TR></TABLE>" /* end of outer table */
184 void calendar_week_view(int year, int month, int day) {
185 wprintf("<CENTER><I>week view FIXME</I></CENTER><BR>\n");
189 void calendar_day_view(int year, int month, int day) {
190 wprintf("<CENTER><I>FIXME day view for %02d/%02d/%04d</I></CENTER><BR>\n", month, day, year);
193 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">"
194 "Back to month view</A><BR>\n", year, month);
199 void do_calendar_view(void) {
203 int year, month, day;
206 /* In case no date was specified, go with today */
208 tm = localtime(&now);
209 year = tm->tm_year + 1900;
213 /* Now see if a date was specified */
214 if (strlen(bstr("year")) > 0) year = atoi(bstr("year"));
215 if (strlen(bstr("month")) > 0) month = atoi(bstr("month"));
216 if (strlen(bstr("day")) > 0) day = atoi(bstr("day"));
218 /* How would you like that cooked? */
219 if (strlen(bstr("calview")) > 0) {
220 strcpy(calview, bstr("calview"));
223 strcpy(calview, "month");
226 /* Display the selected view */
227 if (!strcasecmp(calview, "day")) {
228 calendar_day_view(year, month, day);
230 else if (!strcasecmp(calview, "week")) {
231 calendar_week_view(year, month, day);
234 calendar_month_view(year, month, day);
237 /* Free the calendar stuff */
238 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
239 icalcomponent_free(WC->disp_cal[i]);
246 #endif /* HAVE_ICAL_H */