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