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