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