webcit_before_automake is now the trunk
[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         svprintf("BOXTITLE", WCS_STRING, _("Messages"));
51         do_template("beginbox");
52
53         number_of_rooms_to_check = num_tokens(rooms_to_check, '|');
54         if (number_of_rooms_to_check == 0) return;
55
56         wprintf("<table border=0 width=100%%>\n");
57         for (i=0; i<number_of_rooms_to_check; ++i) {
58                 extract_token(room, rooms_to_check, i, '|', sizeof room);
59
60                 serv_printf("GOTO %s", room);
61                 serv_getln(buf, sizeof buf);
62                 if (buf[0] == '2') {
63                         extract_token(room, &buf[4], 0, '|', sizeof room);
64                         wprintf("<tr><td><a href=\"dotgoto?room=");
65                         urlescputs(room);
66                         wprintf("\">");
67                         escputs(room);
68                         wprintf("</a></td><td>%d/%d</td></tr>\n",
69                                 extract_int(&buf[4], 1),
70                                 extract_int(&buf[4], 2)
71                         );
72                 }
73         }
74         wprintf("</table>\n");
75         do_template("endbox");
76
77 }
78
79
80 /**
81  * \brief Wholist section
82  */
83 void wholist_section(void) {
84         char buf[SIZ];
85         char user[SIZ];
86
87         svprintf("BOXTITLE", WCS_STRING, _("Who's&nbsp;online&nbsp;now"));
88         do_template("beginbox");
89         serv_puts("RWHO");
90         serv_getln(buf, sizeof buf);
91         if (buf[0] == '1') while(serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
92                 extract_token(user, buf, 1, '|', sizeof user);
93                 escputs(user);
94                 wprintf("<br />\n");
95         }
96         do_template("endbox");
97 }
98
99
100 /**
101  * \brief Task list section
102  */
103 void tasks_section(void) {
104 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
105         int num_msgs = 0;
106         int i;
107 #endif
108
109         svprintf("BOXTITLE", WCS_STRING, _("Tasks"));
110         do_template("beginbox");
111 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
112         gotoroom("_TASKS_");
113         if (WC->wc_view != VIEW_TASKS) {
114                 num_msgs = 0;
115         }
116         else {
117                 num_msgs = load_msg_ptrs("MSGS ALL", 0);
118         }
119
120         if (num_msgs < 1) {
121                 wprintf("<i>");
122                 wprintf(_("(None)"));
123                 wprintf("</i><br />\n");
124         }
125         else {
126                 for (i=0; i<num_msgs; ++i) {
127                         display_task(WC->msgarr[i]);
128                 }
129         }
130
131         calendar_summary_view();
132
133 #else /* WEBCIT_WITH_CALENDAR_SERVICE */
134         wprintf("<i>");
135         wprintf(_("(This server does not support task lists)"));
136         wprintf("</i>\n");
137 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */
138         do_template("endbox");
139 }
140
141
142 /**
143  * \brief Calendar section
144  */
145 void calendar_section(void) {
146 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
147         int num_msgs = 0;
148         int i;
149 #endif
150
151         svprintf("BOXTITLE", WCS_STRING, _("Today&nbsp;on&nbsp;your&nbsp;calendar"));
152         do_template("beginbox");
153 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
154         gotoroom("_CALENDAR_");
155         if ( (WC->wc_view != VIEW_CALENDAR) && (WC->wc_view != VIEW_CALBRIEF) ) {
156                 num_msgs = 0;
157         }
158         else {
159                 num_msgs = load_msg_ptrs("MSGS ALL", 0);
160         }
161
162         if (num_msgs < 1) {
163                 wprintf("<i>");
164                 wprintf(_("(Nothing)"));
165                 wprintf("</i><br />\n");
166         }
167         else {
168                 for (i=0; i<num_msgs; ++i) {
169                         display_calendar(WC->msgarr[i]);
170                 }
171                 calendar_summary_view();
172         }
173
174 #else /* WEBCIT_WITH_CALENDAR_SERVICE */
175         wprintf("<i>");
176         wprintf(_("(This server does not support calendars)"));
177         wprintf("</i>\n");
178 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */
179         do_template("endbox");
180 }
181
182 /**
183  * \brief Server info section (fluff, really)
184  */
185 void server_info_section(void) {
186         char message[512];
187
188         svprintf("BOXTITLE", WCS_STRING, _("About&nbsp;this&nbsp;server"));
189         do_template("beginbox");
190
191         snprintf(message, sizeof message,
192                 _("You are connected to %s, running %s with %s, and located in %s.  Your system administrator is %s."),
193                 serv_info.serv_humannode,
194                 serv_info.serv_software,
195                 SERVER,
196                 serv_info.serv_bbs_city,
197                 serv_info.serv_sysadm);
198         escputs(message);
199         do_template("endbox");
200 }
201
202 /**
203  * \brief summary of inner div????
204  */
205 void summary_inner_div(void) {
206         /**
207          * Now let's do three columns of crap.  All portals and all groupware
208          * clients seem to want to do three columns, so we'll do three
209          * columns too.  Conformity is not inherently a virtue, but there are
210          * a lot of really shallow people out there, and even though they're
211          * not people I consider worthwhile, I still want them to use WebCit.
212          */
213
214         wprintf("<div class=\"fix_scrollbar_bug\">"
215                 "<table border=0 width=100%%><tr valign=top>");
216
217         /**
218          * Column One
219          */
220         wprintf("<td width=33%%>");
221         wholist_section();
222
223         /**
224          * Column Two
225          */
226         wprintf("</td><td width=33%%>");
227         server_info_section();
228         wprintf("<br />");
229         tasks_section();
230
231         /**
232          * Column Three
233          */
234         wprintf("</td><td width=33%%>");
235         new_messages_section();
236         wprintf("<br />");
237         calendar_section();
238
239         /**
240          * End of columns
241          */
242         wprintf("</td></tr></table>");
243 }
244
245
246 /**
247  * \brief Display this user's summary page
248  */
249 void summary(void) {
250         char title[256];
251
252         output_headers(1, 1, 2, 0, 0, 0);
253         wprintf("<div id=\"banner\">\n");
254         wprintf("<table width=100%% border=0 bgcolor=#444455><tr>"
255                 "<td><img src=\"static/summscreen_48x.gif\"></td><td>"
256                 "<span class=\"titlebar\">"
257         );
258
259         snprintf(title, sizeof title, _("Summary page for %s"), WC->wc_fullname);
260         escputs(title);
261         wprintf("</span></td><td>\n");
262         wprintf("</td><td aling=right><span class=\"titlebar\">");
263         output_date();
264         wprintf("</span><br />");
265         offer_start_page();
266         wprintf("</td></tr></table>\n");
267
268         /**
269          * You guessed it ... we're going to refresh using ajax.
270          * In the future we might consider updating individual sections of the summary
271          * instead of the whole thing.
272          */
273         wprintf("</div>\n<div id=\"content\">\n");
274         summary_inner_div();
275         wprintf("</div>\n");
276
277         wprintf(
278                 "<script type=\"text/javascript\">                                      "
279                 " new Ajax.PeriodicalUpdater('content', 'summary_inner_div',            "
280                 "                            { method: 'get', frequency: 60 }  );       "
281                 "</script>                                                              \n"
282         );
283
284         wDumpContent(1);
285 }
286
287
288 /*@}*/