* Doxygen groups. Sorted the files into groups. so now we have a nice structure
[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
18         static char *wdays[7];
19         static char *months[12];
20
21         wdays[0] = _("Sunday");
22         wdays[1] = _("Monday");
23         wdays[2] = _("Tuesday");
24         wdays[3] = _("Wednesday");
25         wdays[4] = _("Thursday");
26         wdays[5] = _("Friday");
27         wdays[6] = _("Saturday");
28
29         months[0] = _("January");
30         months[1] = _("February");
31         months[2] = _("March");
32         months[3] = _("April");
33         months[4] = _("May");
34         months[5] = _("June");
35         months[6] = _("July");
36         months[7] = _("August");
37         months[8] = _("September");
38         months[9] = _("October");
39         months[10] = _("November");
40         months[11] = _("December");
41
42         time(&now);
43         localtime_r(&now, &tm);
44
45         wprintf("%s, %s %d, %d",
46                 wdays[tm.tm_wday],
47                 months[tm.tm_mon],
48                 tm.tm_mday,
49                 tm.tm_year + 1900
50         );
51 }
52
53
54
55
56 /**
57  * \brief Dummy section
58  */
59 void dummy_section(void) {
60         svprintf("BOXTITLE", WCS_STRING, "(dummy section)");
61         do_template("beginbox");
62         wprintf(_("(nothing)"));
63         do_template("endbox");
64 }
65
66
67 /**
68  * \brief New messages section
69  */
70 void new_messages_section(void) {
71         char buf[SIZ];
72         char room[SIZ];
73         int i;
74         int number_of_rooms_to_check;
75         char *rooms_to_check = "Mail|Lobby";
76
77         svprintf("BOXTITLE", WCS_STRING, _("Messages"));
78         do_template("beginbox");
79
80         number_of_rooms_to_check = num_tokens(rooms_to_check, '|');
81         if (number_of_rooms_to_check == 0) return;
82
83         wprintf("<TABLE BORDER=0 WIDTH=100%%>\n");
84         for (i=0; i<number_of_rooms_to_check; ++i) {
85                 extract_token(room, rooms_to_check, i, '|', sizeof room);
86
87                 serv_printf("GOTO %s", room);
88                 serv_getln(buf, sizeof buf);
89                 if (buf[0] == '2') {
90                         extract_token(room, &buf[4], 0, '|', sizeof room);
91                         wprintf("<TR><TD><a href=\"dotgoto?room=");
92                         urlescputs(room);
93                         wprintf("\">");
94                         escputs(room);
95                         wprintf("</A></TD><TD>%d/%d</TD></TR>\n",
96                                 extract_int(&buf[4], 1),
97                                 extract_int(&buf[4], 2)
98                         );
99                 }
100         }
101         wprintf("</TABLE>\n");
102         do_template("endbox");
103
104 }
105
106
107 /**
108  * \brief Wholist section
109  */
110 void wholist_section(void) {
111         char buf[SIZ];
112         char user[SIZ];
113
114         svprintf("BOXTITLE", WCS_STRING, _("Who's&nbsp;online&nbsp;now"));
115         do_template("beginbox");
116         serv_puts("RWHO");
117         serv_getln(buf, sizeof buf);
118         if (buf[0] == '1') while(serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
119                 extract_token(user, buf, 1, '|', sizeof user);
120                 escputs(user);
121                 wprintf("<br />\n");
122         }
123         do_template("endbox");
124 }
125
126
127 /**
128  * \brief Task list section
129  */
130 void tasks_section(void) {
131 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
132         int num_msgs = 0;
133         int i;
134 #endif
135
136         svprintf("BOXTITLE", WCS_STRING, _("Tasks"));
137         do_template("beginbox");
138 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
139         gotoroom("_TASKS_");
140         if (WC->wc_view != VIEW_TASKS) {
141                 num_msgs = 0;
142         }
143         else {
144                 num_msgs = load_msg_ptrs("MSGS ALL", 0);
145         }
146
147         if (num_msgs < 1) {
148                 wprintf("<i>");
149                 wprintf(_("(None)"));
150                 wprintf("</i><br />\n");
151         }
152         else {
153                 for (i=0; i<num_msgs; ++i) {
154                         display_task(WC->msgarr[i]);
155                 }
156         }
157
158         calendar_summary_view();
159
160 #else /* WEBCIT_WITH_CALENDAR_SERVICE */
161         wprintf("<I>");
162         wprintf(_("(This server does not support task lists)"));
163         wprintf("</I>\n");
164 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */
165         do_template("endbox");
166 }
167
168
169 /**
170  * \brief Calendar section
171  */
172 void calendar_section(void) {
173 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
174         int num_msgs = 0;
175         int i;
176 #endif
177
178         svprintf("BOXTITLE", WCS_STRING, _("Today&nbsp;on&nbsp;your&nbsp;calendar"));
179         do_template("beginbox");
180 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
181         gotoroom("_CALENDAR_");
182         if (WC->wc_view != VIEW_CALENDAR) {
183                 num_msgs = 0;
184         }
185         else {
186                 num_msgs = load_msg_ptrs("MSGS ALL", 0);
187         }
188
189         if (num_msgs < 1) {
190                 wprintf("<i>");
191                 wprintf(_("(Nothing)"));
192                 wprintf("</i><br />\n");
193         }
194         else {
195                 for (i=0; i<num_msgs; ++i) {
196                         display_calendar(WC->msgarr[i]);
197                 }
198                 calendar_summary_view();
199         }
200
201 #else /* WEBCIT_WITH_CALENDAR_SERVICE */
202         wprintf("<I>");
203         wprintf(_("(This server does not support calendars)"));
204         wprintf("</I>\n");
205 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */
206         do_template("endbox");
207 }
208
209 /**
210  * \brief Server info section (fluff, really)
211  */
212 void server_info_section(void) {
213         char message[512];
214
215         svprintf("BOXTITLE", WCS_STRING, _("About&nbsp;this&nbsp;server"));
216         do_template("beginbox");
217
218         snprintf(message, sizeof message,
219                 _("You are connected to %s, running %s with %s, and located in %s.  Your system administrator is %s."),
220                 serv_info.serv_humannode,
221                 serv_info.serv_software,
222                 SERVER,
223                 serv_info.serv_bbs_city,
224                 serv_info.serv_sysadm);
225         escputs(message);
226         do_template("endbox");
227 }
228
229 /**
230  * \brief summary of inner div????
231  */
232 void summary_inner_div(void) {
233         /**
234          * Now let's do three columns of crap.  All portals and all groupware
235          * clients seem to want to do three columns, so we'll do three
236          * columns too.  Conformity is not inherently a virtue, but there are
237          * a lot of really shallow people out there, and even though they're
238          * not people I consider worthwhile, I still want them to use WebCit.
239          */
240
241         wprintf("<div class=\"fix_scrollbar_bug\">"
242                 "<table border=0 width=100%%><tr valign=top>");
243
244         /**
245          * Column One
246          */
247         wprintf("<td width=33%%>");
248         wholist_section();
249
250         /**
251          * Column Two
252          */
253         wprintf("</td><td width=33%%>");
254         server_info_section();
255         wprintf("<br />");
256         tasks_section();
257
258         /**
259          * Column Three
260          */
261         wprintf("</td><td width=33%%>");
262         new_messages_section();
263         wprintf("<br />");
264         calendar_section();
265
266         /**
267          * End of columns
268          */
269         wprintf("</td></tr></table>");
270 }
271
272
273 /**
274  * \brief Display this user's summary page
275  */
276 void summary(void) {
277         char title[256];
278
279         output_headers(1, 1, 2, 0, 0, 0);
280         wprintf("<div id=\"banner\">\n");
281         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=#444455><TR>"
282                 "<TD><img src=\"static/summscreen_48x.gif\"></TD><TD>"
283                 "<SPAN CLASS=\"titlebar\">"
284         );
285
286         snprintf(title, sizeof title, _("Summary page for %s"), WC->wc_fullname);
287         escputs(title);
288         wprintf("</SPAN></TD><TD>\n");
289         wprintf("</TD><TD ALIGN=RIGHT><SPAN CLASS=\"titlebar\">");
290         output_date();
291         wprintf("</SPAN><br />");
292         offer_start_page();
293         wprintf("</TD></TR></TABLE>\n");
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>\n<div id=\"content\">\n");
301         summary_inner_div();
302         wprintf("</div>\n");
303
304         wprintf(
305                 "<script type=\"text/javascript\">                                      "
306                 " new Ajax.PeriodicalUpdater('content', 'summary_inner_div',            "
307                 "                            { method: 'get', frequency: 60 }  );       "
308                 "</script>                                                              \n"
309         );
310
311         wDumpContent(1);
312 }
313
314
315 /*@}*/