iconbar : mark active/inactive user with CSS
[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("RWHO");
87         serv_getln(buf, sizeof buf);
88         if (buf[0] == '1') while(serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
89                 extract_token(user, buf, 1, '|', sizeof user);
90                 last_activity = extract_long(buf, 5);
91                 if (strcmp(user, NLI)) {
92                         wprintf("<li span=\"");
93                         if ((now - last_activity) > 900L) {
94                                 wprintf("inactiveuser");
95                         }
96                         else {
97                                 wprintf("activeuser");
98                         }
99                         wprintf("\"><a href=\"showuser?who=");
100                         urlescputs(user);
101                         wprintf("\">");
102                         escputs(user);
103                         wprintf("</a></li>");
104                 }
105         }
106 }
107
108
109 /**
110  * \brief Task list section
111  */
112 void tasks_section(void) {
113 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
114         int num_msgs = 0;
115         int i;
116 #endif
117
118 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
119         gotoroom("_TASKS_");
120         if (WC->wc_view != VIEW_TASKS) {
121                 num_msgs = 0;
122         }
123         else {
124                 num_msgs = load_msg_ptrs("MSGS ALL", 0);
125         }
126
127         if (num_msgs < 1) {
128                 wprintf("<i>");
129                 wprintf(_("(None)"));
130                 wprintf("</i><br />\n");
131         }
132         else {
133                 for (i=0; i<num_msgs; ++i) {
134                         display_task(WC->msgarr[i]);
135                 }
136         }
137
138         calendar_summary_view();
139
140 #else /* WEBCIT_WITH_CALENDAR_SERVICE */
141         wprintf("<i>");
142         wprintf(_("(This server does not support task lists)"));
143         wprintf("</i>\n");
144 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */
145 }
146
147
148 /**
149  * \brief 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 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
158         gotoroom("_CALENDAR_");
159         if ( (WC->wc_view != VIEW_CALENDAR) && (WC->wc_view != VIEW_CALBRIEF) ) {
160                 num_msgs = 0;
161         }
162         else {
163                 num_msgs = load_msg_ptrs("MSGS ALL", 0);
164         }
165
166         if (num_msgs < 1) {
167                 wprintf("<i>");
168                 wprintf(_("(Nothing)"));
169                 wprintf("</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>");
180         wprintf(_("(This server does not support calendars)"));
181         wprintf("</i>\n");
182 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */
183 }
184
185 /**
186  * \brief Server info section (fluff, really)
187  */
188 void server_info_section(void) {
189         char message[512];
190
191         snprintf(message, sizeof message,
192                 _("You are connected to %s, running %s with %s, and located in %s.  Your system administrator is %s."),
193                 serv_info.serv_humannode,
194                 serv_info.serv_software,
195                 SERVER,
196                 serv_info.serv_bbs_city,
197                 serv_info.serv_sysadm);
198         escputs(message);
199 }
200
201 /**
202  * \brief summary of inner div????
203  */
204
205
206
207 void summary_inner_div(void) {
208         /**
209          * Now let's do three columns of crap.  All portals and all groupware
210          * clients seem to want to do three columns, so we'll do three
211          * columns too.  Conformity is not inherently a virtue, but there are
212          * a lot of really shallow people out there, and even though they're
213          * not people I consider worthwhile, I still want them to use WebCit.
214          */
215
216         wprintf("<div class=\"fix_scrollbar_bug\">"
217                 "<table border=0 width=100%%><tr valign=top>");
218
219         /**
220          * Column One
221          */
222         wprintf("<td width=33%%>");
223         wprintf("<div class=\"box\">"); 
224         wprintf("<div class=\"boxlabel\">");    
225         wprintf(_("Messages"));
226         wprintf("</div><div class=\"boxcontent\">");    
227         wprintf("<div id=\"msg_inner\">");      
228         new_messages_section();
229         wprintf("</div></div></div>");
230         wprintf("</td>");
231
232         /**
233          * Column Two 
234          */
235         wprintf("<td width=33%%>");
236         wprintf("<div class=\"box\">"); 
237         wprintf("<div class=\"boxlabel\">");    
238         wprintf(_("Tasks"));
239         wprintf("</div><div class=\"boxcontent\">");    
240         wprintf("<div id=\"tasks_inner\">");    
241         tasks_section();
242         wprintf("</div></div></div>");
243         wprintf("</td>");
244
245         /**
246          * Column Three
247          */
248         wprintf("<td width=33%%>");
249         wprintf("<div class=\"box\">"); 
250         wprintf("<div class=\"boxlabel\">");    
251         wprintf(_("Today&nbsp;on&nbsp;your&nbsp;calendar"));
252         wprintf("</div><div class=\"boxcontent\">");    
253         wprintf("<div id=\"calendar_inner\">"); 
254         calendar_section();
255         wprintf("</div></div></div>");
256         wprintf("</td>");
257
258         wprintf("</tr><tr valign=top>");
259         wprintf("<td colspan=3><br/></td>");
260         wprintf("</tr><tr valign=top>");
261
262         /**
263          * Row Two - Column One
264          */
265         wprintf("<td colspan=2>");
266         wprintf("<div class=\"box\">"); 
267         wprintf("<div class=\"boxlabel\">");    
268         wprintf(_("Who's&nbsp;online&nbsp;now"));
269         wprintf("</div><div class=\"boxcontent\">");    
270         wprintf("<div id=\"who_inner\">");      
271         who_inner_div(); 
272         wprintf("</div></div></div>");
273         wprintf("</td>");
274
275         /**
276          * Row Two - Column Two
277          */
278         wprintf("<td width=33%%>");
279         wprintf("<div class=\"box\">"); 
280         wprintf("<div class=\"boxlabel\">");    
281         wprintf(_("About&nbsp;this&nbsp;server"));
282         wprintf("</div><div class=\"boxcontent\">");    
283         wprintf("<div id=\"info_inner\">");     
284         server_info_section();
285         wprintf("</div></div></div>");
286         wprintf("</td>");
287
288
289         /**
290          * End of columns
291          */
292         wprintf("</tr></table>");
293 }
294
295
296 /**
297  * \brief Display this user's summary page
298  */
299 void summary(void) {
300         char title[256];
301
302         output_headers(1, 1, 2, 0, 0, 0);
303         wprintf("<div id=\"banner\">\n");
304         wprintf("<div class=\"service_banner\">\n");
305         wprintf("<img src=\"static/summscreen_48x.gif\">");
306         wprintf("<h1>");
307         snprintf(title, sizeof title, _("Summary page for %s"), WC->wc_fullname);
308         escputs(title);
309         wprintf("</h1><h2>\n");
310         output_date();
311         wprintf("</h2></div>");
312         wprintf("<ul><li class=\"start_page\">");
313         offer_start_page();
314         wprintf("</li></ul>");
315         wprintf("</div>");
316
317         /**
318          * You guessed it ... we're going to refresh using ajax.
319          * In the future we might consider updating individual sections of the summary
320          * instead of the whole thing.
321          */
322         wprintf("<div id=\"content\">\n");
323         summary_inner_div();
324         wprintf("</div>\n");
325
326         wprintf(
327                 "<script type=\"text/javascript\">                                      "
328                 " new Ajax.PeriodicalUpdater('msg_inner', 'new_messages_html',          "
329                 "                            { method: 'get', frequency: 60 }  );       "
330                 " new Ajax.PeriodicalUpdater('tasks_inner', 'tasks_inner_html',         "
331                 "                            { method: 'get', frequency: 120 }  );      "
332                 " new Ajax.PeriodicalUpdater('calendar_inner', 'calendar_inner_html',           "
333                 "                            { method: 'get', frequency: 90 }  );       "
334                 " new Ajax.PeriodicalUpdater('who_inner', 'who_inner_html',             "
335                 "                            { method: 'get', frequency: 30 }  );       "
336                 "</script>                                                              \n"
337         );
338
339         wDumpContent(1);
340 }
341
342
343 /*@}*/