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