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