]> code.citadel.org Git - citadel.git/blob - webcit/summary.c
46bed8fdec0eef8c29f49ad9fabff3a94e69d955
[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  * Display the title bar for a section
56  */
57 void section_title(char *title) {
58
59         wprintf("<TABLE width=100%% border=0 cellpadding=5 cellspacing=0>"
60                 "<TR><TD BGCOLOR=444455>"
61                 "<FONT COLOR=FFFFEE>");
62         escputs(title);
63         wprintf("</FONT></TD></TR></TABLE>\n");
64 }
65
66
67 /*
68  * Dummy section
69  */
70 void dummy_section(void) {
71         section_title("---");
72 }
73
74
75 /*
76  * New messages section
77  */
78 void new_messages_section(void) {
79         char buf[SIZ];
80         char room[SIZ];
81         int i;
82         int number_of_rooms_to_check;
83         char *rooms_to_check = "Mail|Lobby";
84
85         section_title("Messages");
86
87         number_of_rooms_to_check = num_tokens(rooms_to_check, '|');
88         if (number_of_rooms_to_check == 0) return;
89
90         wprintf("<TABLE BORDER=0 WIDTH=100%%>\n");
91         for (i=0; i<number_of_rooms_to_check; ++i) {
92                 extract(room, rooms_to_check, i);
93
94                 serv_printf("GOTO %s", room);
95                 serv_gets(buf);
96                 if (buf[0] == '2') {
97                         extract(room, &buf[4], 0);
98                         wprintf("<TR><TD><A HREF=\"/dotgoto?room=");
99                         urlescputs(room);
100                         wprintf("\">");
101                         escputs(room);
102                         wprintf("</A></TD><TD>%d/%d</TD></TR>\n",
103                                 extract_int(&buf[4], 1),
104                                 extract_int(&buf[4], 2)
105                         );
106                 }
107         }
108         wprintf("</TABLE>\n");
109
110 }
111
112
113 /*
114  * Wholist section
115  */
116 void wholist_section(void) {
117         char buf[SIZ];
118         char user[SIZ];
119
120         section_title("Who's online now");
121         serv_puts("RWHO");
122         serv_gets(buf);
123         if (buf[0] == '1') while(serv_gets(buf), strcmp(buf, "000")) {
124                 extract(user, buf, 1);
125                 escputs(user);
126                 wprintf("<BR>\n");
127         }
128 }
129
130
131 /*
132  * Task list section
133  */
134 void tasks_section(void) {
135         int num_msgs = 0;
136         int i;
137
138         section_title("Tasks");
139         gotoroom("Tasks", 0);
140         if (strcasecmp(WC->wc_roomname, "Tasks")) {
141                 wprintf("<i>(You do not have a task list)</i><BR>\n");
142                 return;
143         }
144
145         num_msgs = load_msg_ptrs("MSGS ALL");
146         if (num_msgs < 1) {
147                 wprintf("<i>(None)</i><BR>\n");
148                 return;
149         }
150
151         wprintf("<UL>");
152         for (i=0; i<num_msgs; ++i) {
153                 display_task(WC->msgarr[i]);
154         }
155         wprintf("</UL>\n");
156 }
157
158
159 /*
160  * Calendar section
161  */
162 void calendar_section(void) {
163         int num_msgs = 0;
164         int i;
165
166         section_title("Today on your calendar");
167 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
168         gotoroom("Calendar", 0);
169         if (strcasecmp(WC->wc_roomname, "Calendar")) {
170                 wprintf("<i>(You do not have a calendar)</i><BR>\n");
171                 return;
172         }
173
174         num_msgs = load_msg_ptrs("MSGS ALL");
175         if (num_msgs < 1) {
176                 wprintf("<i>(Nothing)</i><BR>\n");
177                 return;
178         }
179
180         for (i=0; i<num_msgs; ++i) {
181                 display_calendar(WC->msgarr[i]);
182         }
183
184         calendar_summary_view();
185 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */
186 }
187
188
189 /*
190  * Server info section (fluff, really)
191  */
192 void server_info_section(void) {
193         char buf[SIZ];
194         int i = 0;
195
196         section_title("About this server");
197         serv_puts("INFO");
198         serv_gets(buf);
199         if (buf[0] == '1') while(serv_gets(buf), strcmp(buf, "000")) {
200                 switch(i) {
201                         case 2:
202                                 wprintf("You are connected to ");
203                                 escputs(buf);
204                                 wprintf(", ");
205                                 break;
206                         case 4: wprintf("running ");
207                                 escputs(buf);
208                                 wprintf(", ");
209                                 break;
210                         case 6: wprintf("and located in ");
211                                 escputs(buf);
212                                 wprintf(".<BR>\n");
213                                 break;
214                         case 7: wprintf("Your system administrator is ");
215                                 escputs(buf);
216                                 wprintf(".\n");
217                                 break;
218                 }
219                 ++i;
220         }
221 }
222         
223
224
225
226 /*
227  * Display this user's summary page
228  */
229 void summary(void) {
230         output_headers(7);
231
232         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>"
233                 "<FONT SIZE=+1 COLOR=\"FFFFFF\">"
234                 "<B>Summary page for ");
235         escputs(WC->wc_username);
236         wprintf("</B><FONT></TD><TD>\n");
237         offer_start_page();
238         wprintf("</TD><TD ALIGN=RIGHT><FONT COLOR=\"FFFFFF\">");
239         output_date();
240         wprintf("</FONT></TD></TR></TABLE>\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><BR>");
264         tasks_section();
265
266         /*
267          * Column Three
268          */
269         wprintf("</TD><TD WIDTH=33%%>");
270         new_messages_section();
271         wprintf("<BR><BR>");
272         calendar_section();
273
274         /*
275          * End of columns
276          */
277         wprintf("</TD></TR></TABLE>\n");
278
279         wDumpContent(1);
280 }