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);
98 lprintf(9, "Starting at %s", asctime(localtime(&thetime)));
101 while (tm->tm_mday != 1) {
102 thetime = thetime - (time_t)86400; /* go back 24 hours */
103 lprintf(9, "Backing off to %s", asctime(localtime(&thetime)));
104 tm = localtime(&thetime);
107 /* Determine previous and next months ... for links */
108 previous_month = thetime - (time_t)864000L; /* back 10 days */
109 next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
110 lprintf(9, "previous month is %s", asctime(localtime(&previous_month)));
111 lprintf(9, "next month is %s", asctime(localtime(&next_month)));
113 /* Now back up until we're on a Sunday */
114 tm = localtime(&thetime);
115 while (tm->tm_wday != 0) {
116 thetime = thetime - (time_t)86400; /* go back 24 hours */
117 lprintf(9, "Backing off to %s", asctime(localtime(&thetime)));
118 tm = localtime(&thetime);
121 /* Outer table (to get the background color) */
122 wprintf("<TABLE width=100%% border=0 cellpadding=0 cellspacing=0 "
123 "bgcolor=#4444FF><TR><TD>\n");
125 wprintf("<CENTER><H3>");
127 tm = localtime(&previous_month);
128 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
129 (int)(tm->tm_year)+1900, tm->tm_mon);
130 wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/back.gif\" BORDER=0></A>\n");
132 wprintf(" "
133 "<FONT COLOR=#FFFFFF>"
136 " ", months[month], year);
138 tm = localtime(&next_month);
139 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
140 (int)(tm->tm_year)+1900, tm->tm_mon + 1);
141 wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/forward.gif\" BORDER=0></A>\n");
145 /* Inner table (the real one) */
146 wprintf("<TABLE width=100%% border=0 cellpadding=1 cellspacing=1 "
148 for (i=0; i<7; ++i) {
149 wprintf("<TH><FONT COLOR=#FFFFFF>%s</FONT></TH>", days[i]);
153 for (i = 0; i < 35; ++i) {
154 tm = localtime(&thetime);
155 if (tm->tm_wday == 0) {
159 wprintf("<TD BGCOLOR=FFFFFF WIDTH=14%% HEIGHT=60 VALIGN=TOP>"
161 if ((i==0) || (tm->tm_mday == 1)) {
162 wprintf("%s ", months[tm->tm_mon]);
164 wprintf("<A HREF=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
171 /* put the data here, stupid */
172 calendar_month_view_display_events(thetime);
176 if (tm->tm_wday == 6) {
180 thetime += (time_t)86400; /* ahead 24 hours */
183 wprintf("</TABLE>" /* end of inner table */
184 "</TD></TR></TABLE>" /* end of outer table */
189 void calendar_week_view(int year, int month, int day) {
190 wprintf("<CENTER><I>week view FIXME</I></CENTER><BR>\n");
194 void calendar_day_view(int year, int month, int day) {
195 wprintf("<CENTER><I>FIXME day view for %02d/%02d/%04d</I></CENTER><BR>\n", month, day, year);
198 wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">"
199 "Back to month view</A><BR>\n", year, month);
204 void do_calendar_view(void) {
208 int year, month, day;
211 /* In case no date was specified, go with today */
213 tm = localtime(&now);
214 year = tm->tm_year + 1900;
218 /* Now see if a date was specified */
219 if (strlen(bstr("year")) > 0) year = atoi(bstr("year"));
220 if (strlen(bstr("month")) > 0) month = atoi(bstr("month"));
221 if (strlen(bstr("day")) > 0) day = atoi(bstr("day"));
223 /* How would you like that cooked? */
224 if (strlen(bstr("calview")) > 0) {
225 strcpy(calview, bstr("calview"));
228 strcpy(calview, "month");
231 /* Display the selected view */
232 if (!strcasecmp(calview, "day")) {
233 calendar_day_view(year, month, day);
235 else if (!strcasecmp(calview, "week")) {
236 calendar_week_view(year, month, day);
239 calendar_month_view(year, month, day);
242 /* Free the calendar stuff */
243 if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
244 icalcomponent_free(WC->disp_cal[i]);
251 #endif /* HAVE_ICAL_H */