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