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