19caa74fa1f9b9406391c1ad07848946af87246c
[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         }
105
106         if (calendar_summary_view() < 1) {
107                 wprintf("<i>");
108                 wprintf(_("(None)"));
109                 wprintf("</i><br />\n");
110         }
111 }
112
113
114 /*
115  * Calendar section
116  */
117 void calendar_section(void) {
118         int num_msgs = 0;
119         HashPos *at;
120         const char *HashKey;
121         long HKLen;
122         void *vMsg;
123         message_summary *Msg;
124         wcsession *WCC = WC;
125         struct calview c;
126         StrBuf *Buf;
127
128         Buf = NewStrBufPlain(HKEY("_CALENDAR_"));
129         gotoroom(Buf);
130         FreeStrBuf(&Buf);
131         if ( (WC->wc_view != VIEW_CALENDAR) && (WC->wc_view != VIEW_CALBRIEF) ) {
132                 num_msgs = 0;
133         }
134         else {
135                 num_msgs = load_msg_ptrs("MSGS ALL", 0);
136         }
137
138         parse_calendar_view_request(&c);
139
140         if (num_msgs > 0) {
141                 at = GetNewHashPos(WCC->summ, 0);
142                 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
143                         Msg = (message_summary*) vMsg;          
144                         load_calendar_item(Msg, 0, &c);
145                 }
146         }
147         if (calendar_summary_view() < 1) {
148                 wprintf("<i>");
149                 wprintf(_("(Nothing)"));
150                 wprintf("</i><br />\n");
151         }
152 }
153
154 /*
155  * Server info section (fluff, really)
156  */
157 void server_info_section(void) {
158         char message[512];
159
160         snprintf(message, sizeof message,
161                 _("You are connected to %s, running %s with %s, server build %s and located in %s.  Your system administrator is %s."),
162                  ChrPtr(serv_info.serv_humannode),
163                  ChrPtr(serv_info.serv_software),
164                  PACKAGE_STRING,
165                  ChrPtr(serv_info.serv_svn_revision),
166                  ChrPtr(serv_info.serv_bbs_city),
167                  ChrPtr(serv_info.serv_sysadm));
168         escputs(message);
169 }
170
171 /*
172  * Now let's do three columns of crap.  All portals and all groupware
173  * clients seem to want to do three columns, so we'll do three
174  * columns too.  Conformity is not inherently a virtue, but there are
175  * a lot of really shallow people out there, and even though they're
176  * not people I consider worthwhile, I still want them to use WebCit.
177  */
178 void summary_inner_div(void) {
179         wprintf("<div class=\"fix_scrollbar_bug\">"
180                 "<table width=\"100%%\" cellspacing=\"10\" cellpadding=\"0\">"
181                 "<tr valign=top>");
182
183         /*
184          * Column One
185          */
186         wprintf("<td width=33%%>");
187         wprintf("<div class=\"box\">"); 
188         wprintf("<div class=\"boxlabel\">");    
189         wprintf(_("Messages"));
190         wprintf("</div><div class=\"boxcontent\">");    
191         wprintf("<div id=\"msg_inner\">");      
192         new_messages_section();
193         wprintf("</div></div></div>");
194         wprintf("</td>");
195
196         /*
197          * Column Two 
198          */
199         wprintf("<td width=33%%>");
200         wprintf("<div class=\"box\">"); 
201         wprintf("<div class=\"boxlabel\">");    
202         wprintf(_("Tasks"));
203         wprintf("</div><div class=\"boxcontent\">");    
204         wprintf("<div id=\"tasks_inner\">");    
205         tasks_section();
206         wprintf("</div></div></div>");
207         wprintf("</td>");
208
209         /*
210          * Column Three
211          */
212         wprintf("<td width=33%%>");
213         wprintf("<div class=\"box\">"); 
214         wprintf("<div class=\"boxlabel\">");    
215         wprintf(_("Today&nbsp;on&nbsp;your&nbsp;calendar"));
216         wprintf("</div><div class=\"boxcontent\">");    
217         wprintf("<div id=\"calendar_inner\">"); 
218         calendar_section();
219         wprintf("</div></div></div>");
220         wprintf("</td>");
221
222         wprintf("</tr><tr valign=top>");
223
224         /*
225          * Row Two - Column One
226          */
227         wprintf("<td colspan=2>");
228         wprintf("<div class=\"box\">"); 
229         wprintf("<div class=\"boxlabel\">");    
230         wprintf(_("Who's&nbsp;online&nbsp;now"));
231         wprintf("</div><div class=\"boxcontent\">");    
232         wprintf("<div id=\"who_inner\">");      
233         do_template("wholistsummarysection", NULL);
234         wprintf("</div></div></div>");
235         wprintf("</td>");
236
237         /*
238          * Row Two - Column Two
239          */
240         wprintf("<td width=33%%>");
241         wprintf("<div class=\"box\">"); 
242         wprintf("<div class=\"boxlabel\">");    
243         wprintf(_("About&nbsp;this&nbsp;server"));
244         wprintf("</div><div class=\"boxcontent\">");    
245         wprintf("<div id=\"info_inner\">");     
246         server_info_section();
247         wprintf("</div></div></div>");
248         wprintf("</td>");
249
250
251         /*
252          * End of columns
253          */
254         wprintf("</tr></table>");
255 }
256
257
258 /*
259  * Display this user's summary page
260  */
261 void summary(void) {
262         char title[256];
263
264         output_headers(1, 1, 2, 0, 0, 0);
265         wprintf("<div id=\"banner\">\n");
266         wprintf("<div class=\"room_banner\">");
267         wprintf("<img src=\"static/summscreen_48x.gif\">");
268         wprintf("<h1>");
269         snprintf(title, sizeof title, _("Summary page for %s"), ChrPtr(WC->wc_fullname));
270         escputs(title);
271         wprintf("</h1><h2>");
272         output_date();
273         wprintf("</h2></div>");
274         wprintf("<div id=\"actiondiv\">");
275         wprintf("<ul class=\"room_actions\">\n");
276         wprintf("<li class=\"start_page\">");
277         offer_start_page(NULL, &NoCtx);
278         wprintf("</li></ul>");
279         wprintf("</div>");
280         wprintf("</div>");
281
282         /*
283          * You guessed it ... we're going to refresh using ajax.
284          * In the future we might consider updating individual sections of the summary
285          * instead of the whole thing.
286          */
287         wprintf("<div id=\"content\" class=\"service\">\n");
288         summary_inner_div();
289         wprintf("</div>\n");
290
291         wprintf(
292                 "<script type=\"text/javascript\">                                      "
293                 " new Ajax.PeriodicalUpdater('msg_inner', 'new_messages_html',          "
294                 "                            { method: 'get', frequency: 60 }  );       "
295                 " new Ajax.PeriodicalUpdater('tasks_inner', 'tasks_inner_html',         "
296                 "                            { method: 'get', frequency: 120 }  );      "
297                 " new Ajax.PeriodicalUpdater('calendar_inner', 'calendar_inner_html',           "
298                 "                            { method: 'get', frequency: 90 }  );       "
299                 " new Ajax.PeriodicalUpdater('do_template', 'template=wholistsummarysection',   "
300                 "                            { method: 'get', frequency: 30 }  );       "
301                 "</script>                                                              \n"
302         );
303
304         wDumpContent(1);
305 }
306
307 void 
308 InitModule_SUMMARY
309 (void)
310 {
311         WebcitAddUrlHandler(HKEY("new_messages_html"), new_messages_section, AJAX);
312         WebcitAddUrlHandler(HKEY("tasks_inner_html"), tasks_section, AJAX);
313         WebcitAddUrlHandler(HKEY("calendar_inner_html"), calendar_section, AJAX);
314         WebcitAddUrlHandler(HKEY("mini_calendar"), ajax_mini_calendar, AJAX);
315         WebcitAddUrlHandler(HKEY("summary"), summary, 0);
316         WebcitAddUrlHandler(HKEY("summary_inner_div"), summary_inner_div, AJAX);
317 }
318