* Completed GroupDAV PUT. Untested.
[citadel.git] / webcit / summary.c
1 /* $Id$ */
2
3 #include <ctype.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <stdio.h>
7 #include <fcntl.h>
8 #include <signal.h>
9 #include <sys/types.h>
10 #include <sys/wait.h>
11 #include <sys/socket.h>
12 #include <sys/time.h>
13 #include <limits.h>
14 #include <netinet/in.h>
15 #include <netdb.h>
16 #include <string.h>
17 #include <time.h>
18 #include <pwd.h>
19 #include <errno.h>
20 #include <stdarg.h>
21 #include <pthread.h>
22 #include <signal.h>
23 #include "webcit.h"
24
25 /*
26  * Display today's date in a friendly format
27  */
28 void output_date(void) {
29         struct tm tm;
30         time_t now;
31
32         static char *wdays[] = {
33                 "Sunday", "Monday", "Tuesday", "Wednesday",
34                 "Thursday", "Friday", "Saturday"
35         };
36         static char *months[] = {
37                 "January", "February", "March", "April", "May", "June", "July",
38                 "August", "September", "October", "November", "December"
39         };
40
41         time(&now);
42         localtime_r(&now, &tm);
43
44         wprintf("%s, %s %d, %d",
45                 wdays[tm.tm_wday],
46                 months[tm.tm_mon],
47                 tm.tm_mday,
48                 tm.tm_year + 1900
49         );
50 }
51
52
53
54
55 /*
56  * Dummy section
57  */
58 void dummy_section(void) {
59         svprintf("BOXTITLE", WCS_STRING, "(dummy&nbsp;section)");
60         do_template("beginbox");
61         wprintf("(nothing)");
62         do_template("endbox");
63 }
64
65
66 /*
67  * New messages section
68  */
69 void new_messages_section(void) {
70         char buf[SIZ];
71         char room[SIZ];
72         int i;
73         int number_of_rooms_to_check;
74         char *rooms_to_check = "Mail|Lobby";
75
76         svprintf("BOXTITLE", WCS_STRING, "Messages");
77         do_template("beginbox");
78
79         number_of_rooms_to_check = num_tokens(rooms_to_check, '|');
80         if (number_of_rooms_to_check == 0) return;
81
82         wprintf("<TABLE BORDER=0 WIDTH=100%%>\n");
83         for (i=0; i<number_of_rooms_to_check; ++i) {
84                 extract(room, rooms_to_check, i);
85
86                 serv_printf("GOTO %s", room);
87                 serv_gets(buf);
88                 if (buf[0] == '2') {
89                         extract(room, &buf[4], 0);
90                         wprintf("<TR><TD><A HREF=\"/dotgoto?room=");
91                         urlescputs(room);
92                         wprintf("\">");
93                         escputs(room);
94                         wprintf("</A></TD><TD>%d/%d</TD></TR>\n",
95                                 extract_int(&buf[4], 1),
96                                 extract_int(&buf[4], 2)
97                         );
98                 }
99         }
100         wprintf("</TABLE>\n");
101         do_template("endbox");
102
103 }
104
105
106 /*
107  * Wholist section
108  */
109 void wholist_section(void) {
110         char buf[SIZ];
111         char user[SIZ];
112
113         svprintf("BOXTITLE", WCS_STRING, "Who's&nbsp;online&nbsp;now");
114         do_template("beginbox");
115         serv_puts("RWHO");
116         serv_gets(buf);
117         if (buf[0] == '1') while(serv_gets(buf), strcmp(buf, "000")) {
118                 extract(user, buf, 1);
119                 escputs(user);
120                 wprintf("<br />\n");
121         }
122         do_template("endbox");
123 }
124
125
126 /*
127  * Task list section
128  */
129 void tasks_section(void) {
130 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
131         int num_msgs = 0;
132         int i;
133 #endif
134
135         svprintf("BOXTITLE", WCS_STRING, "Tasks");
136         do_template("beginbox");
137 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
138         gotoroom("Tasks");
139         if (strcasecmp(WC->wc_roomname, "Tasks")) {
140                 num_msgs = 0;
141         }
142         else {
143                 num_msgs = load_msg_ptrs("MSGS ALL");
144         }
145
146         wprintf("FIXME start tasks<br>\n");
147         if (num_msgs < 1) {
148                 wprintf("<i>(None)</i><br />\n");
149         }
150         else {
151                 for (i=0; i<num_msgs; ++i) {
152                         display_task(WC->msgarr[i]);
153                 }
154         }
155         wprintf("FIXME end tasks<br>\n");
156
157 #else /* WEBCIT_WITH_CALENDAR_SERVICE */
158         wprintf("<I>(This server does not support task lists)</I>\n");
159 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */
160         do_template("endbox");
161 }
162
163
164 /*
165  * Calendar section
166  */
167 void calendar_section(void) {
168 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
169         int num_msgs = 0;
170         int i;
171 #endif
172
173         svprintf("BOXTITLE", WCS_STRING, "Today&nbsp;on&nbsp;your&nbsp;calendar");
174         do_template("beginbox");
175 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
176         gotoroom("Calendar");
177         if (strcasecmp(WC->wc_roomname, "Calendar")) {
178                 num_msgs = 0;
179         }
180         else {
181                 num_msgs = load_msg_ptrs("MSGS ALL");
182         }
183         wprintf("FIXME start calendar<br>\n");
184
185         if (num_msgs < 1) {
186                 wprintf("<i>(Nothing)</i><br />\n");
187         }
188         else {
189                 for (i=0; i<num_msgs; ++i) {
190                         display_calendar(WC->msgarr[i]);
191                 }
192                 calendar_summary_view();
193         }
194         wprintf("FIXME end calendar<br>\n");
195
196 #else /* WEBCIT_WITH_CALENDAR_SERVICE */
197         wprintf("<I>(This server does not support calendars)</I>\n");
198 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */
199         do_template("endbox");
200 }
201
202
203 /*
204  * Server info section (fluff, really)
205  */
206 void server_info_section(void) {
207         svprintf("BOXTITLE", WCS_STRING, "About&nbsp;this&nbsp;server");
208         do_template("beginbox");
209         wprintf("You are connected to ");
210         escputs(serv_info.serv_humannode);
211         wprintf(", running ");
212         escputs(serv_info.serv_software);
213         wprintf(", and located in ");
214         escputs(serv_info.serv_bbs_city);
215         wprintf(".<br />\nYour system administrator is ");
216         escputs(serv_info.serv_sysadm);
217         wprintf(".\n");
218         do_template("endbox");
219 }
220
221
222 /*
223  * Display this user's summary page
224  */
225 void summary(void) {
226
227         output_headers(1, 1, 2, 0, 1, 0, 0);
228         wprintf("<div id=\"banner\">\n");
229         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=#444455><TR>"
230                 "<TD><IMG SRC=\"/static/summary.gif\"></TD><TD>"
231                 "<SPAN CLASS=\"titlebar\">"
232                 "Summary page for ");
233         escputs(WC->wc_username);
234         wprintf("</SPAN></TD><TD>\n");
235         wprintf("</TD><TD ALIGN=RIGHT><SPAN CLASS=\"titlebar\">");
236         output_date();
237         wprintf("</SPAN><br />");
238         offer_start_page();
239         wprintf("</TD></TR></TABLE>\n");
240         wprintf("</div>\n<div id=\"content\">\n");
241
242         /*
243          * Now let's do three columns of crap.  All portals and all groupware
244          * clients seem to want to do three columns, so we'll do three
245          * columns too.  Conformity is not inherently a virtue, but there are
246          * a lot of really shallow people out there, and even though they're
247          * not people I consider worthwhile, I still want them to use WebCit.
248          */
249
250         wprintf("<TABLE WIDTH=100%% BORDER=0 CELLPADDING=10><TR VALIGN=TOP>");
251
252         /*
253          * Column One
254          */
255         wprintf("<TD WIDTH=33%%>");
256         wholist_section();
257
258         /*
259          * Column Two
260          */
261         wprintf("</TD><TD WIDTH=33%%>");
262         server_info_section();
263         wprintf("<br />");
264         tasks_section();
265
266         /*
267          * Column Three
268          */
269         wprintf("</TD><TD WIDTH=33%%>");
270         new_messages_section();
271         wprintf("<br />");
272         calendar_section();
273
274         /*
275          * End of columns
276          */
277         wprintf("</TD></TR></TABLE>\n");
278
279         wDumpContent(1);
280 }