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