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