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