e78399eabc0692e697a25b9cfabe6ea5aeea1245
[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                 PACKAGE_STRING,
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 width=\"100%%\" cellspacing=\"10px\" cellpadding=\"0\">"
227                 "<tr valign=top>");
228
229         /**
230          * Column One
231          */
232         wprintf("<td width=33%%>");
233         wprintf("<div class=\"box\">"); 
234         wprintf("<div class=\"boxlabel\">");    
235         wprintf(_("Messages"));
236         wprintf("</div><div class=\"boxcontent\">");    
237         wprintf("<div id=\"msg_inner\">");      
238         new_messages_section();
239         wprintf("</div></div></div>");
240         wprintf("</td>");
241
242         /**
243          * Column Two 
244          */
245         wprintf("<td width=33%%>");
246         wprintf("<div class=\"box\">"); 
247         wprintf("<div class=\"boxlabel\">");    
248         wprintf(_("Tasks"));
249         wprintf("</div><div class=\"boxcontent\">");    
250         wprintf("<div id=\"tasks_inner\">");    
251         tasks_section();
252         wprintf("</div></div></div>");
253         wprintf("</td>");
254
255         /**
256          * Column Three
257          */
258         wprintf("<td width=33%%>");
259         wprintf("<div class=\"box\">"); 
260         wprintf("<div class=\"boxlabel\">");    
261         wprintf(_("Today&nbsp;on&nbsp;your&nbsp;calendar"));
262         wprintf("</div><div class=\"boxcontent\">");    
263         wprintf("<div id=\"calendar_inner\">"); 
264         calendar_section();
265         wprintf("</div></div></div>");
266         wprintf("</td>");
267
268         wprintf("</tr><tr valign=top>");
269
270         /**
271          * Row Two - Column One
272          */
273         wprintf("<td colspan=2>");
274         wprintf("<div class=\"box\">"); 
275         wprintf("<div class=\"boxlabel\">");    
276         wprintf(_("Who's&nbsp;online&nbsp;now"));
277         wprintf("</div><div class=\"boxcontent\">");    
278         wprintf("<div id=\"who_inner\">");      
279         who_inner_div(); 
280         wprintf("</div></div></div>");
281         wprintf("</td>");
282
283         /**
284          * Row Two - Column Two
285          */
286         wprintf("<td width=33%%>");
287         wprintf("<div class=\"box\">"); 
288         wprintf("<div class=\"boxlabel\">");    
289         wprintf(_("About&nbsp;this&nbsp;server"));
290         wprintf("</div><div class=\"boxcontent\">");    
291         wprintf("<div id=\"info_inner\">");     
292         server_info_section();
293         wprintf("</div></div></div>");
294         wprintf("</td>");
295
296
297         /**
298          * End of columns
299          */
300         wprintf("</tr></table>");
301 }
302
303
304 /**
305  * \brief Display this user's summary page
306  */
307 void summary(void) {
308         char title[256];
309
310         output_headers(1, 1, 2, 0, 0, 0);
311         wprintf("<div id=\"banner\">\n");
312         wprintf("<div class=\"room_banner\">");
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></div>");
320         wprintf("<ul class=\"room_actions\">\n");
321         wprintf("<li class=\"start_page\">");
322         offer_start_page();
323         wprintf("</li></ul>");
324         wprintf("</div>");
325
326         /**
327          * You guessed it ... we're going to refresh using ajax.
328          * In the future we might consider updating individual sections of the summary
329          * instead of the whole thing.
330          */
331         wprintf("<div id=\"content\" class=\"service\">\n");
332         summary_inner_div();
333         wprintf("</div>\n");
334
335         wprintf(
336                 "<script type=\"text/javascript\">                                      "
337                 " new Ajax.PeriodicalUpdater('msg_inner', 'new_messages_html',          "
338                 "                            { method: 'get', frequency: 60 }  );       "
339                 " new Ajax.PeriodicalUpdater('tasks_inner', 'tasks_inner_html',         "
340                 "                            { method: 'get', frequency: 120 }  );      "
341                 " new Ajax.PeriodicalUpdater('calendar_inner', 'calendar_inner_html',           "
342                 "                            { method: 'get', frequency: 90 }  );       "
343                 " new Ajax.PeriodicalUpdater('who_inner', 'who_inner_html',             "
344                 "                            { method: 'get', frequency: 30 }  );       "
345                 "</script>                                                              \n"
346         );
347
348         wDumpContent(1);
349 }
350
351
352 /*@}*/