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