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