]> code.citadel.org Git - citadel.git/blob - webcit/calendar_view.c
* Presentation changes to calendar month view
[citadel.git] / webcit / calendar_view.c
1 /*
2  * $Id$
3  *
4  *
5  */
6
7 #include <ctype.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <stdio.h>
11 #include <fcntl.h>
12 #include <signal.h>
13 #include <sys/types.h>
14 #include <sys/wait.h>
15 #include <sys/socket.h>
16 #include <limits.h>
17 #include <netinet/in.h>
18 #include <netdb.h>
19 #include <string.h>
20 #include <pwd.h>
21 #include <errno.h>
22 #include <stdarg.h>
23 #include <pthread.h>
24 #include <signal.h>
25 #include <time.h>
26 #include "webcit.h"
27 #include "webserver.h"
28
29 #ifndef HAVE_ICAL_H
30
31 void do_calendar_view(void) {   /* stub for non-libical builds */
32         wprintf("<CENTER><I>Calendar view not available</I></CENTER><BR>\n");
33 }
34
35 #else   /* HAVE_ICAL_H */
36
37 /****************************************************************************/
38
39
40 void calendar_month_view(int year, int month, int day) {
41         struct tm starting_tm;
42         struct tm *tm;
43         time_t thetime;
44         int i;
45         time_t previous_month;
46         time_t next_month;
47
48         /* Determine what day to start.
49          * First, back up to the 1st of the month...
50          */
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);
56
57         tm = &starting_tm;
58         while (tm->tm_mday != 1) {
59                 thetime = thetime - (time_t)86400;      /* go back 24 hours */
60                 tm = localtime(&thetime);
61         }
62
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 */
66
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);
72         }
73
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");
77
78         wprintf("<CENTER><H3>");
79
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");
84
85         wprintf("&nbsp;&nbsp;"
86                 "<FONT COLOR=#FFFFFF>"
87                 "%s %d"
88                 "</FONT>"
89                 "&nbsp;&nbsp;", months[month], year);
90
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");
95
96         wprintf("</H3>");
97
98         /* Inner table (the real one) */
99         wprintf("<TABLE width=100%% border=0 cellpadding=1 cellspacing=1 "
100                 "bgcolor=#4444FF>");
101         for (i=0; i<7; ++i) {
102                 wprintf("<TH><FONT COLOR=#FFFFFF>%s</FONT></TH>", days[i]);
103         }
104
105         /* Now do 35 days */
106         for (i = 0; i < 35; ++i) {
107                 tm = localtime(&thetime);
108                 if (tm->tm_wday == 0) {
109                         wprintf("<TR>");
110                 }
111
112                 wprintf("<TD BGCOLOR=FFFFFF WIDTH=14%%>");
113                 if ((i==0) || (tm->tm_mday == 1)) {
114                         wprintf("%s ", months[tm->tm_mon]);
115                 }
116                 wprintf("%d", tm->tm_mday);
117
118                 /* FIXME ... put the data here, stupid */
119                 wprintf("<BR><BR><BR>");
120
121                 wprintf("</TD>");
122
123                 if (tm->tm_wday == 6) {
124                         wprintf("</TR>\n");
125                 }
126
127                 thetime += (time_t)86400;               /* ahead 24 hours */
128         }
129
130         wprintf("</TABLE>"                      /* end of inner table */
131                 "</TD></TR></TABLE>"            /* end of outer table */
132                 "</CENTER>\n");
133 }
134
135
136 void calendar_week_view(int year, int month, int day) {
137         wprintf("<CENTER><I>week view FIXME</I></CENTER><BR>\n");
138 }
139
140
141 void calendar_day_view(int year, int month, int day) {
142         wprintf("<CENTER><I>day view FIXME</I></CENTER><BR>\n");
143 }
144
145
146
147 void do_calendar_view(void) {
148         time_t now;
149         struct tm *tm;
150         int year, month, day;
151         char calview[SIZ];
152
153         /* In case no date was specified, go with today */
154         now = time(NULL);
155         tm = localtime(&now);
156         year = tm->tm_year + 1900;
157         month = tm->tm_mon;
158         day = tm->tm_mday;
159
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"));
164
165         /* How would you like that cooked? */
166         if (strlen(bstr("calview")) > 0) {
167                 strcpy(calview, bstr("calview"));
168         }
169         else {
170                 strcpy(calview, "month");
171         }
172
173         /* Display the selected view */
174         if (!strcasecmp(calview, "day")) {
175                 calendar_day_view(year, month, day);
176         }
177         else if (!strcasecmp(calview, "week")) {
178                 calendar_week_view(year, month, day);
179         }
180         else {
181                 calendar_month_view(year, month, day);
182         }
183 }
184
185
186 #endif  /* HAVE_ICAL_H */