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