* split tasks view into its own file
[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         wprintf("%s", buf);
23 }
24
25
26
27
28 /*
29  * Dummy section
30  */
31 void dummy_section(void) {
32         svput("BOXTITLE", WCS_STRING, "(dummy section)");
33         do_template("beginboxx", NULL);
34         wprintf(_("(nothing)"));
35         do_template("endbox", NULL);
36 }
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         wprintf("<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                         wprintf("<tr><td><a href=\"dotgoto?room=");
62                         urlescputs(room);
63                         wprintf("\">");
64                         escputs(room);
65                         wprintf("</a></td><td>%d/%d</td></tr>\n",
66                                 extract_int(&buf[4], 1),
67                                 extract_int(&buf[4], 2)
68                         );
69                 }
70         }
71         wprintf("</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         Buf = NewStrBufPlain(HKEY("_TASKS_"));
92         gotoroom(Buf);
93         FreeStrBuf(&Buf);
94         if (WCC->wc_view != VIEW_TASKS) {
95                 num_msgs = 0;
96         }
97         else {
98                 num_msgs = load_msg_ptrs("MSGS ALL", &Stat);
99         }
100
101         if (num_msgs > 0) {
102                 at = GetNewHashPos(WCC->summ, 0);
103                 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
104                         Msg = (message_summary*) vMsg;          
105                         tasks_LoadMsgFromServer(NULL, NULL, Msg, 0, 0);
106                 }
107                 DeleteHashPos(&at);
108         }
109
110         if (calendar_summary_view() < 1) {
111                 wprintf("<i>");
112                 wprintf(_("(None)"));
113                 wprintf("</i><br />\n");
114         }
115 }
116
117
118 /*
119  * Calendar section
120  */
121 void calendar_section(void) {
122         char cmd[SIZ];
123         int num_msgs = 0;
124         HashPos *at;
125         const char *HashKey;
126         long HKLen;
127         void *vMsg;
128         message_summary *Msg;
129         wcsession *WCC = WC;
130         calview c;
131         StrBuf *Buf;
132         void *v = &c;
133         SharedMessageStatus Stat;
134
135         memset(&Stat, 0, sizeof(SharedMessageStatus));
136         Buf = NewStrBufPlain(HKEY("_CALENDAR_"));
137         gotoroom(Buf);
138         FreeStrBuf(&Buf);
139         if ( (WC->wc_view != VIEW_CALENDAR) && (WC->wc_view != VIEW_CALBRIEF) ) {
140                 num_msgs = 0;
141         }
142         else {
143                 num_msgs = load_msg_ptrs("MSGS ALL", &Stat);
144         }
145         calendar_GetParamsGetServerCall(&Stat, 
146                                         &c,
147                                         readnew, 
148                                         cmd, 
149                                         sizeof(cmd));
150
151         if (num_msgs > 0) {
152                 at = GetNewHashPos(WCC->summ, 0);
153                 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
154                         Msg = (message_summary*) vMsg;          
155                         calendar_LoadMsgFromServer(NULL, &v, Msg, 0, 0);
156                 }
157                 DeleteHashPos(&at);
158         }
159         if (calendar_summary_view() < 1) {
160                 wprintf("<i>");
161                 wprintf(_("(Nothing)"));
162                 wprintf("</i><br />\n");
163         }
164 }
165
166 /*
167  * Server info section (fluff, really)
168  */
169 void server_info_section(void) {
170         char message[512];
171         wcsession *WCC = WC;
172
173         snprintf(message, sizeof message,
174                 _("You are connected to %s, running %s with %s, server build %s and located in %s.  Your system administrator is %s."),
175                  ChrPtr(WCC->serv_info->serv_humannode),
176                  ChrPtr(WCC->serv_info->serv_software),
177                  PACKAGE_STRING,
178                  ChrPtr(WCC->serv_info->serv_svn_revision),
179                  ChrPtr(WCC->serv_info->serv_bbs_city),
180                  ChrPtr(WCC->serv_info->serv_sysadm));
181         escputs(message);
182 }
183
184 /*
185  * Now let's do three columns of crap.  All portals and all groupware
186  * clients seem to want to do three columns, so we'll do three
187  * columns too.  Conformity is not inherently a virtue, but there are
188  * a lot of really shallow people out there, and even though they're
189  * not people I consider worthwhile, I still want them to use WebCit.
190  */
191 void summary_inner_div(void) {
192         wprintf("<div class=\"fix_scrollbar_bug\">"
193                 "<table width=\"100%%\" cellspacing=\"10\" cellpadding=\"0\">"
194                 "<tr valign=top>");
195
196         /*
197          * Column One
198          */
199         wprintf("<td width=33%%>");
200         wprintf("<div class=\"box\">"); 
201         wprintf("<div class=\"boxlabel\">");    
202         wprintf(_("Messages"));
203         wprintf("</div><div class=\"boxcontent\">");    
204         wprintf("<div id=\"msg_inner\">");      
205         new_messages_section();
206         wprintf("</div></div></div>");
207         wprintf("</td>");
208
209         /*
210          * Column Two 
211          */
212         wprintf("<td width=33%%>");
213         wprintf("<div class=\"box\">"); 
214         wprintf("<div class=\"boxlabel\">");    
215         wprintf(_("Tasks"));
216         wprintf("</div><div class=\"boxcontent\">");    
217         wprintf("<div id=\"tasks_inner\">");    
218         tasks_section();
219         wprintf("</div></div></div>");
220         wprintf("</td>");
221
222         /*
223          * Column Three
224          */
225         wprintf("<td width=33%%>");
226         wprintf("<div class=\"box\">"); 
227         wprintf("<div class=\"boxlabel\">");    
228         wprintf(_("Today&nbsp;on&nbsp;your&nbsp;calendar"));
229         wprintf("</div><div class=\"boxcontent\">");    
230         wprintf("<div id=\"calendar_inner\">"); 
231         calendar_section();
232         wprintf("</div></div></div>");
233         wprintf("</td>");
234
235         wprintf("</tr><tr valign=top>");
236
237         /*
238          * Row Two - Column One
239          */
240         wprintf("<td colspan=2>");
241         wprintf("<div class=\"box\">"); 
242         wprintf("<div class=\"boxlabel\">");    
243         wprintf(_("Who's&nbsp;online&nbsp;now"));
244         wprintf("</div><div class=\"boxcontent\">");    
245         wprintf("<div id=\"who_inner\">");      
246         do_template("wholistsummarysection", NULL);
247         wprintf("</div></div></div>");
248         wprintf("</td>");
249
250         /*
251          * Row Two - Column Two
252          */
253         wprintf("<td width=33%%>");
254         wprintf("<div class=\"box\">"); 
255         wprintf("<div class=\"boxlabel\">");    
256         wprintf(_("About&nbsp;this&nbsp;server"));
257         wprintf("</div><div class=\"boxcontent\">");    
258         wprintf("<div id=\"info_inner\">");     
259         server_info_section();
260         wprintf("</div></div></div>");
261         wprintf("</td>");
262
263
264         /*
265          * End of columns
266          */
267         wprintf("</tr></table>");
268 }
269
270
271 /*
272  * Display this user's summary page
273  */
274 void summary(void) {
275         char title[256];
276
277         output_headers(1, 1, 2, 0, 0, 0);
278         wprintf("<div id=\"banner\">\n");
279         wprintf("<div class=\"room_banner\">");
280         wprintf("<img src=\"static/summscreen_48x.gif\">");
281         wprintf("<h1>");
282         snprintf(title, sizeof title, _("Summary page for %s"), ChrPtr(WC->wc_fullname));
283         escputs(title);
284         wprintf("</h1><h2>");
285         output_date();
286         wprintf("</h2></div>");
287         wprintf("<div id=\"actiondiv\">");
288         wprintf("<ul class=\"room_actions\">\n");
289         wprintf("<li class=\"start_page\">");
290         offer_start_page(NULL, &NoCtx);
291         wprintf("</li></ul>");
292         wprintf("</div>");
293         wprintf("</div>");
294
295         /*
296          * You guessed it ... we're going to refresh using ajax.
297          * In the future we might consider updating individual sections of the summary
298          * instead of the whole thing.
299          */
300         wprintf("<div id=\"content\" class=\"service\">\n");
301         summary_inner_div();
302         wprintf("</div>\n");
303
304         wprintf(
305                 "<script type=\"text/javascript\">                                      "
306                 " new Ajax.PeriodicalUpdater('msg_inner', 'new_messages_html',          "
307                 "                            { method: 'get', frequency: 60 }  );       "
308                 " new Ajax.PeriodicalUpdater('tasks_inner', 'tasks_inner_html',         "
309                 "                            { method: 'get', frequency: 120 }  );      "
310                 " new Ajax.PeriodicalUpdater('calendar_inner', 'calendar_inner_html',           "
311                 "                            { method: 'get', frequency: 90 }  );       "
312                 " new Ajax.PeriodicalUpdater('do_template', 'template=wholistsummarysection',   "
313                 "                            { method: 'get', frequency: 30 }  );       "
314                 "</script>                                                              \n"
315         );
316
317         wDumpContent(1);
318 }
319
320 void 
321 InitModule_SUMMARY
322 (void)
323 {
324         WebcitAddUrlHandler(HKEY("new_messages_html"), new_messages_section, AJAX);
325         WebcitAddUrlHandler(HKEY("tasks_inner_html"), tasks_section, AJAX);
326         WebcitAddUrlHandler(HKEY("calendar_inner_html"), calendar_section, AJAX);
327         WebcitAddUrlHandler(HKEY("mini_calendar"), ajax_mini_calendar, AJAX);
328         WebcitAddUrlHandler(HKEY("summary"), summary, 0);
329         WebcitAddUrlHandler(HKEY("summary_inner_div"), summary_inner_div, AJAX);
330 }
331