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