* Attempting to add a smart host in webcit was instead adding it as an RBL host....
[citadel.git] / webcit / summary.c
blob43c8e590dac5bffac585b0ab0115447fa5363ed3
1 /*
2 * $Id$
4 * Displays the "Summary Page"
5 */
7 #include "webcit.h"
9 /*
10 * Display today's date in a friendly format
12 void output_date(void) {
13 struct tm tm;
14 time_t now;
15 char buf[128];
17 time(&now);
18 localtime_r(&now, &tm);
20 wc_strftime(buf, 32, "%A, %x", &tm);
21 wprintf("%s", buf);
28 * Dummy section
30 void dummy_section(void) {
31 svput("BOXTITLE", WCS_STRING, "(dummy section)");
32 do_template("beginboxx", NULL);
33 wprintf(_("(nothing)"));
34 do_template("endbox", NULL);
39 * New messages section
41 void new_messages_section(void) {
42 char buf[SIZ];
43 char room[SIZ];
44 int i;
45 int number_of_rooms_to_check;
46 char *rooms_to_check = "Mail|Lobby";
49 number_of_rooms_to_check = num_tokens(rooms_to_check, '|');
50 if (number_of_rooms_to_check == 0) return;
52 wprintf("<table border=0 width=100%%>\n");
53 for (i=0; i<number_of_rooms_to_check; ++i) {
54 extract_token(room, rooms_to_check, i, '|', sizeof room);
56 serv_printf("GOTO %s", room);
57 serv_getln(buf, sizeof buf);
58 if (buf[0] == '2') {
59 extract_token(room, &buf[4], 0, '|', sizeof room);
60 wprintf("<tr><td><a href=\"dotgoto?room=");
61 urlescputs(room);
62 wprintf("\">");
63 escputs(room);
64 wprintf("</a></td><td>%d/%d</td></tr>\n",
65 extract_int(&buf[4], 1),
66 extract_int(&buf[4], 2)
70 wprintf("</table>\n");
76 * Task list section
78 void tasks_section(void) {
79 int num_msgs = 0;
80 HashPos *at;
81 const char *HashKey;
82 long HKLen;
83 void *vMsg;
84 message_summary *Msg;
85 wcsession *WCC = WC;
86 StrBuf *Buf;
88 Buf = NewStrBufPlain(HKEY("_TASKS_"));
89 gotoroom(Buf);
90 FreeStrBuf(&Buf);
91 if (WCC->wc_view != VIEW_TASKS) {
92 num_msgs = 0;
94 else {
95 num_msgs = load_msg_ptrs("MSGS ALL", 0);
98 if (num_msgs > 0) {
99 at = GetNewHashPos(WCC->summ, 0);
100 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
101 Msg = (message_summary*) vMsg;
102 display_task(Msg, 0);
106 if (calendar_summary_view() < 1) {
107 wprintf("<i>");
108 wprintf(_("(None)"));
109 wprintf("</i><br />\n");
115 * Calendar section
117 void calendar_section(void) {
118 int num_msgs = 0;
119 HashPos *at;
120 const char *HashKey;
121 long HKLen;
122 void *vMsg;
123 message_summary *Msg;
124 wcsession *WCC = WC;
125 struct calview c;
126 StrBuf *Buf;
128 Buf = NewStrBufPlain(HKEY("_CALENDAR_"));
129 gotoroom(Buf);
130 FreeStrBuf(&Buf);
131 if ( (WC->wc_view != VIEW_CALENDAR) && (WC->wc_view != VIEW_CALBRIEF) ) {
132 num_msgs = 0;
134 else {
135 num_msgs = load_msg_ptrs("MSGS ALL", 0);
138 parse_calendar_view_request(&c);
140 if (num_msgs > 0) {
141 at = GetNewHashPos(WCC->summ, 0);
142 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
143 Msg = (message_summary*) vMsg;
144 load_calendar_item(Msg, 0, &c);
147 if (calendar_summary_view() < 1) {
148 wprintf("<i>");
149 wprintf(_("(Nothing)"));
150 wprintf("</i><br />\n");
155 * Server info section (fluff, really)
157 void server_info_section(void) {
158 char message[512];
159 wcsession *WCC = WC;
161 snprintf(message, sizeof message,
162 _("You are connected to %s, running %s with %s, server build %s and located in %s. Your system administrator is %s."),
163 ChrPtr(WCC->serv_info->serv_humannode),
164 ChrPtr(WCC->serv_info->serv_software),
165 PACKAGE_STRING,
166 ChrPtr(WCC->serv_info->serv_svn_revision),
167 ChrPtr(WCC->serv_info->serv_bbs_city),
168 ChrPtr(WCC->serv_info->serv_sysadm));
169 escputs(message);
173 * Now let's do three columns of crap. All portals and all groupware
174 * clients seem to want to do three columns, so we'll do three
175 * columns too. Conformity is not inherently a virtue, but there are
176 * a lot of really shallow people out there, and even though they're
177 * not people I consider worthwhile, I still want them to use WebCit.
179 void summary_inner_div(void) {
180 wprintf("<div class=\"fix_scrollbar_bug\">"
181 "<table width=\"100%%\" cellspacing=\"10\" cellpadding=\"0\">"
182 "<tr valign=top>");
185 * Column One
187 wprintf("<td width=33%%>");
188 wprintf("<div class=\"box\">");
189 wprintf("<div class=\"boxlabel\">");
190 wprintf(_("Messages"));
191 wprintf("</div><div class=\"boxcontent\">");
192 wprintf("<div id=\"msg_inner\">");
193 new_messages_section();
194 wprintf("</div></div></div>");
195 wprintf("</td>");
198 * Column Two
200 wprintf("<td width=33%%>");
201 wprintf("<div class=\"box\">");
202 wprintf("<div class=\"boxlabel\">");
203 wprintf(_("Tasks"));
204 wprintf("</div><div class=\"boxcontent\">");
205 wprintf("<div id=\"tasks_inner\">");
206 tasks_section();
207 wprintf("</div></div></div>");
208 wprintf("</td>");
211 * Column Three
213 wprintf("<td width=33%%>");
214 wprintf("<div class=\"box\">");
215 wprintf("<div class=\"boxlabel\">");
216 wprintf(_("Today&nbsp;on&nbsp;your&nbsp;calendar"));
217 wprintf("</div><div class=\"boxcontent\">");
218 wprintf("<div id=\"calendar_inner\">");
219 calendar_section();
220 wprintf("</div></div></div>");
221 wprintf("</td>");
223 wprintf("</tr><tr valign=top>");
226 * Row Two - Column One
228 wprintf("<td colspan=2>");
229 wprintf("<div class=\"box\">");
230 wprintf("<div class=\"boxlabel\">");
231 wprintf(_("Who's&nbsp;online&nbsp;now"));
232 wprintf("</div><div class=\"boxcontent\">");
233 wprintf("<div id=\"who_inner\">");
234 do_template("wholistsummarysection", NULL);
235 wprintf("</div></div></div>");
236 wprintf("</td>");
239 * Row Two - Column Two
241 wprintf("<td width=33%%>");
242 wprintf("<div class=\"box\">");
243 wprintf("<div class=\"boxlabel\">");
244 wprintf(_("About&nbsp;this&nbsp;server"));
245 wprintf("</div><div class=\"boxcontent\">");
246 wprintf("<div id=\"info_inner\">");
247 server_info_section();
248 wprintf("</div></div></div>");
249 wprintf("</td>");
253 * End of columns
255 wprintf("</tr></table>");
260 * Display this user's summary page
262 void summary(void) {
263 char title[256];
265 output_headers(1, 1, 2, 0, 0, 0);
266 wprintf("<div id=\"banner\">\n");
267 wprintf("<div class=\"room_banner\">");
268 wprintf("<img src=\"static/summscreen_48x.gif\">");
269 wprintf("<h1>");
270 snprintf(title, sizeof title, _("Summary page for %s"), ChrPtr(WC->wc_fullname));
271 escputs(title);
272 wprintf("</h1><h2>");
273 output_date();
274 wprintf("</h2></div>");
275 wprintf("<div id=\"actiondiv\">");
276 wprintf("<ul class=\"room_actions\">\n");
277 wprintf("<li class=\"start_page\">");
278 offer_start_page(NULL, &NoCtx);
279 wprintf("</li></ul>");
280 wprintf("</div>");
281 wprintf("</div>");
284 * You guessed it ... we're going to refresh using ajax.
285 * In the future we might consider updating individual sections of the summary
286 * instead of the whole thing.
288 wprintf("<div id=\"content\" class=\"service\">\n");
289 summary_inner_div();
290 wprintf("</div>\n");
292 wprintf(
293 "<script type=\"text/javascript\"> "
294 " new Ajax.PeriodicalUpdater('msg_inner', 'new_messages_html', "
295 " { method: 'get', frequency: 60 } ); "
296 " new Ajax.PeriodicalUpdater('tasks_inner', 'tasks_inner_html', "
297 " { method: 'get', frequency: 120 } ); "
298 " new Ajax.PeriodicalUpdater('calendar_inner', 'calendar_inner_html', "
299 " { method: 'get', frequency: 90 } ); "
300 " new Ajax.PeriodicalUpdater('do_template', 'template=wholistsummarysection', "
301 " { method: 'get', frequency: 30 } ); "
302 "</script> \n"
305 wDumpContent(1);
308 void
309 InitModule_SUMMARY
310 (void)
312 WebcitAddUrlHandler(HKEY("new_messages_html"), new_messages_section, AJAX);
313 WebcitAddUrlHandler(HKEY("tasks_inner_html"), tasks_section, AJAX);
314 WebcitAddUrlHandler(HKEY("calendar_inner_html"), calendar_section, AJAX);
315 WebcitAddUrlHandler(HKEY("mini_calendar"), ajax_mini_calendar, AJAX);
316 WebcitAddUrlHandler(HKEY("summary"), summary, 0);
317 WebcitAddUrlHandler(HKEY("summary_inner_div"), summary_inner_div, AJAX);