use the same way to display all banners and services contents
[citadel.git] / webcit / summary.c
1 /*
2  * $Id$
3  */
4 /**
5  * \defgroup SymaryFuncs Displays the "Summary Page"
6  * \ingroup WebcitDisplayItems
7  */
8 /*@{*/
9 #include "webcit.h"
10
11 /**
12  * \brief Display today's date in a friendly format
13  */
14 void output_date(void) {
15         struct tm tm;
16         time_t now;
17         char buf[128];
18
19         time(&now);
20         localtime_r(&now, &tm);
21
22         wc_strftime(buf, 32, "%A, %x", &tm);
23         wprintf("%s", buf);
24 }
25
26
27
28
29 /**
30  * \brief Dummy section
31  */
32 void dummy_section(void) {
33         svprintf("BOXTITLE", WCS_STRING, "(dummy section)");
34         do_template("beginbox");
35         wprintf(_("(nothing)"));
36         do_template("endbox");
37 }
38
39
40 /**
41  * \brief New messages section
42  */
43 void new_messages_section(void) {
44         char buf[SIZ];
45         char room[SIZ];
46         int i;
47         int number_of_rooms_to_check;
48         char *rooms_to_check = "Mail|Lobby";
49
50
51         number_of_rooms_to_check = num_tokens(rooms_to_check, '|');
52         if (number_of_rooms_to_check == 0) return;
53
54         wprintf("<table border=0 width=100%%>\n");
55         for (i=0; i<number_of_rooms_to_check; ++i) {
56                 extract_token(room, rooms_to_check, i, '|', sizeof room);
57
58                 serv_printf("GOTO %s", room);
59                 serv_getln(buf, sizeof buf);
60                 if (buf[0] == '2') {
61                         extract_token(room, &buf[4], 0, '|', sizeof room);
62                         wprintf("<tr><td><a href=\"dotgoto?room=");
63                         urlescputs(room);
64                         wprintf("\">");
65                         escputs(room);
66                         wprintf("</a></td><td>%d/%d</td></tr>\n",
67                                 extract_int(&buf[4], 1),
68                                 extract_int(&buf[4], 2)
69                         );
70                 }
71         }
72         wprintf("</table>\n");
73
74 }
75
76
77 /**
78  * \brief Wholist section
79  */
80 void wholist_section(void) {
81         char buf[SIZ];
82         char user[SIZ];
83         time_t last_activity;
84         time_t now;
85
86         serv_puts("TIME");
87         serv_getln(buf, sizeof buf);
88         if (buf[0] == '2') {
89                 now = extract_long(&buf[4], 0);
90         }
91         else {
92                 now = time(NULL);
93         }
94
95         serv_puts("RWHO");
96         serv_getln(buf, sizeof buf);
97         if (buf[0] == '1') while(serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
98                 extract_token(user, buf, 1, '|', sizeof user);
99                 last_activity = extract_long(buf, 5);
100                 if (strcmp(user, NLI)) {
101                         wprintf("<li class=\"");
102                         if ((now - last_activity) > 900L) {
103                                 wprintf("inactiveuser");
104                         }
105                         else {
106                                 wprintf("activeuser");
107                         }
108                         wprintf("\"><a href=\"showuser?who=");
109                         urlescputs(user);
110                         wprintf("\">");
111                         escputs(user);
112                         wprintf("</a></li>");
113                 }
114         }
115 }
116
117
118 /**
119  * \brief Task list section
120  */
121 void tasks_section(void) {
122 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
123         int num_msgs = 0;
124         int i;
125 #endif
126
127 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
128         gotoroom("_TASKS_");
129         if (WC->wc_view != VIEW_TASKS) {
130                 num_msgs = 0;
131         }
132         else {
133                 num_msgs = load_msg_ptrs("MSGS ALL", 0);
134         }
135
136         if (num_msgs < 1) {
137                 wprintf("<i>");
138                 wprintf(_("(None)"));
139                 wprintf("</i><br />\n");
140         }
141         else {
142                 for (i=0; i<num_msgs; ++i) {
143                         display_task(WC->msgarr[i]);
144                 }
145         }
146
147         calendar_summary_view();
148
149 #else /* WEBCIT_WITH_CALENDAR_SERVICE */
150         wprintf("<i>");
151         wprintf(_("(This server does not support task lists)"));
152         wprintf("</i>\n");
153 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */
154 }
155
156
157 /**
158  * \brief Calendar section
159  */
160 void calendar_section(void) {
161 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
162         int num_msgs = 0;
163         int i;
164 #endif
165
166 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
167         gotoroom("_CALENDAR_");
168         if ( (WC->wc_view != VIEW_CALENDAR) && (WC->wc_view != VIEW_CALBRIEF) ) {
169                 num_msgs = 0;
170         }
171         else {
172                 num_msgs = load_msg_ptrs("MSGS ALL", 0);
173         }
174
175         if (num_msgs < 1) {
176                 wprintf("<i>");
177                 wprintf(_("(Nothing)"));
178                 wprintf("</i><br />\n");
179         }
180         else {
181                 for (i=0; i<num_msgs; ++i) {
182                         display_calendar(WC->msgarr[i]);
183                 }
184                 calendar_summary_view();
185         }
186
187 #else /* WEBCIT_WITH_CALENDAR_SERVICE */
188         wprintf("<i>");
189         wprintf(_("(This server does not support calendars)"));
190         wprintf("</i>\n");
191 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */
192 }
193
194 /**
195  * \brief Server info section (fluff, really)
196  */
197 void server_info_section(void) {
198         char message[512];
199
200         snprintf(message, sizeof message,
201                 _("You are connected to %s, running %s with %s, and located in %s.  Your system administrator is %s."),
202                 serv_info.serv_humannode,
203                 serv_info.serv_software,
204                 SERVER,
205                 serv_info.serv_bbs_city,
206                 serv_info.serv_sysadm);
207         escputs(message);
208 }
209
210 /**
211  * \brief summary of inner div????
212  */
213
214
215
216 void summary_inner_div(void) {
217         /**
218          * Now let's do three columns of crap.  All portals and all groupware
219          * clients seem to want to do three columns, so we'll do three
220          * columns too.  Conformity is not inherently a virtue, but there are
221          * a lot of really shallow people out there, and even though they're
222          * not people I consider worthwhile, I still want them to use WebCit.
223          */
224
225         wprintf("<div class=\"fix_scrollbar_bug\">"
226                 "<table border=0 width=100%%><tr valign=top>");
227
228         /**
229          * Column One
230          */
231         wprintf("<td width=33%%>");
232         wprintf("<div class=\"box\">"); 
233         wprintf("<div class=\"boxlabel\">");    
234         wprintf(_("Messages"));
235         wprintf("</div><div class=\"boxcontent\">");    
236         wprintf("<div id=\"msg_inner\">");      
237         new_messages_section();
238         wprintf("</div></div></div>");
239         wprintf("</td>");
240
241         /**
242          * Column Two 
243          */
244         wprintf("<td width=33%%>");
245         wprintf("<div class=\"box\">"); 
246         wprintf("<div class=\"boxlabel\">");    
247         wprintf(_("Tasks"));
248         wprintf("</div><div class=\"boxcontent\">");    
249         wprintf("<div id=\"tasks_inner\">");    
250         tasks_section();
251         wprintf("</div></div></div>");
252         wprintf("</td>");
253
254         /**
255          * Column Three
256          */
257         wprintf("<td width=33%%>");
258         wprintf("<div class=\"box\">"); 
259         wprintf("<div class=\"boxlabel\">");    
260         wprintf(_("Today&nbsp;on&nbsp;your&nbsp;calendar"));
261         wprintf("</div><div class=\"boxcontent\">");    
262         wprintf("<div id=\"calendar_inner\">"); 
263         calendar_section();
264         wprintf("</div></div></div>");
265         wprintf("</td>");
266
267         wprintf("</tr><tr valign=top>");
268         wprintf("<td colspan=3><br/></td>");
269         wprintf("</tr><tr valign=top>");
270
271         /**
272          * Row Two - Column One
273          */
274         wprintf("<td colspan=2>");
275         wprintf("<div class=\"box\">"); 
276         wprintf("<div class=\"boxlabel\">");    
277         wprintf(_("Who's&nbsp;online&nbsp;now"));
278         wprintf("</div><div class=\"boxcontent\">");    
279         wprintf("<div id=\"who_inner\">");      
280         who_inner_div(); 
281         wprintf("</div></div></div>");
282         wprintf("</td>");
283
284         /**
285          * Row Two - Column Two
286          */
287         wprintf("<td width=33%%>");
288         wprintf("<div class=\"box\">"); 
289         wprintf("<div class=\"boxlabel\">");    
290         wprintf(_("About&nbsp;this&nbsp;server"));
291         wprintf("</div><div class=\"boxcontent\">");    
292         wprintf("<div id=\"info_inner\">");     
293         server_info_section();
294         wprintf("</div></div></div>");
295         wprintf("</td>");
296
297
298         /**
299          * End of columns
300          */
301         wprintf("</tr></table>");
302 }
303
304
305 /**
306  * \brief Display this user's summary page
307  */
308 void summary(void) {
309         char title[256];
310
311         output_headers(1, 1, 2, 0, 0, 0);
312         wprintf("<div id=\"banner\">\n");
313         wprintf("<img src=\"static/summscreen_48x.gif\">");
314         wprintf("<h1>");
315         snprintf(title, sizeof title, _("Summary page for %s"), WC->wc_fullname);
316         escputs(title);
317         wprintf("</h1><h2>");
318         output_date();
319         wprintf("</h2>");
320         wprintf("<ul><li class=\"start_page\">");
321         offer_start_page();
322         wprintf("</li></ul>");
323         wprintf("</div>");
324
325         /**
326          * You guessed it ... we're going to refresh using ajax.
327          * In the future we might consider updating individual sections of the summary
328          * instead of the whole thing.
329          */
330         wprintf("<div id=\"content\" class=\"service\">\n");
331         summary_inner_div();
332         wprintf("</div>\n");
333
334         wprintf(
335                 "<script type=\"text/javascript\">                                      "
336                 " new Ajax.PeriodicalUpdater('msg_inner', 'new_messages_html',          "
337                 "                            { method: 'get', frequency: 60 }  );       "
338                 " new Ajax.PeriodicalUpdater('tasks_inner', 'tasks_inner_html',         "
339                 "                            { method: 'get', frequency: 120 }  );      "
340                 " new Ajax.PeriodicalUpdater('calendar_inner', 'calendar_inner_html',           "
341                 "                            { method: 'get', frequency: 90 }  );       "
342                 " new Ajax.PeriodicalUpdater('who_inner', 'who_inner_html',             "
343                 "                            { method: 'get', frequency: 30 }  );       "
344                 "</script>                                                              \n"
345         );
346
347         wDumpContent(1);
348 }
349
350
351 /*@}*/