* Add the Summary Page to the customizable iconbar
[citadel.git] / webcit / iconbar.c
1 /* $Id$ */
2
3 #include <ctype.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <stdio.h>
7 #include <fcntl.h>
8 #include <signal.h>
9 #include <sys/types.h>
10 #include <sys/wait.h>
11 #include <sys/socket.h>
12 #include <sys/time.h>
13 #include <limits.h>
14 #include <netinet/in.h>
15 #include <netdb.h>
16 #include <string.h>
17 #include <time.h>
18 #include <pwd.h>
19 #include <errno.h>
20 #include <stdarg.h>
21 #include <pthread.h>
22 #include <signal.h>
23 #include "webcit.h"
24
25
26 /* Values for ib_displayas */
27 #define IB_PICTEXT      0
28 #define IB_PICONLY      1
29 #define IB_TEXTONLY     2
30
31 void do_iconbar(void) {
32         char iconbar[SIZ];
33         char buf[SIZ];
34         char key[SIZ], value[SIZ];
35         int i;
36
37         /* The initialized values of these variables also happen to
38          * specify the default values for users who haven't customized
39          * their iconbars.  These should probably be set in a master
40          * configuration somewhere.
41          */
42         int ib_displayas = 0;   /* pictures and text, pictures, text */
43         int ib_logo = 1;        /* Site logo */
44         int ib_summary = 0;     /* Summary page icon */
45         int ib_inbox = 0;       /* Inbox icon */
46         int ib_calendar = 0;    /* Calendar icon */
47         int ib_tasks = 0;       /* Tasks icon */
48         int ib_rooms = 1;       /* Rooms icon */
49         int ib_users = 1;       /* Users icon */
50         int ib_advanced = 1;    /* Advanced Options icon */
51         int ib_logoff = 1;      /* Logoff button */
52         int ib_citadel = 1;     /* 'Powered by Citadel' logo */
53         /*
54          */
55
56         get_preference("iconbar", iconbar);
57         for (i=0; i<num_tokens(iconbar, ','); ++i) {
58                 extract_token(buf, iconbar, i, ',');
59                 extract_token(key, buf, 0, '=');
60                 extract_token(value, buf, 1, '=');
61
62                 if (!strcasecmp(key, "ib_displayas")) ib_displayas = atoi(value);
63                 if (!strcasecmp(key, "ib_logo")) ib_logo = atoi(value);
64                 if (!strcasecmp(key, "ib_summary")) ib_summary = atoi(value);
65                 if (!strcasecmp(key, "ib_inbox")) ib_inbox = atoi(value);
66                 if (!strcasecmp(key, "ib_calendar")) ib_calendar = atoi(value);
67                 if (!strcasecmp(key, "ib_tasks")) ib_tasks = atoi(value);
68                 if (!strcasecmp(key, "ib_rooms")) ib_rooms = atoi(value);
69                 if (!strcasecmp(key, "ib_users")) ib_users = atoi(value);
70                 if (!strcasecmp(key, "ib_advanced")) ib_advanced = atoi(value);
71                 if (!strcasecmp(key, "ib_logoff")) ib_logoff = atoi(value);
72                 if (!strcasecmp(key, "ib_citadel")) ib_citadel = atoi(value);
73
74         }
75
76
77         output_headers(11);
78         do_template("beginbox_nt");
79
80         wprintf("<center>\n");
81
82         if (ib_logo) if (ib_displayas != IB_TEXTONLY) wprintf(
83                 "\"<IMG BORDER=\"0\" WIDTH=\"48\" "
84                         "HEIGHT=\"48\" SRC=\"/image&name=hello\" ALT=\"&nbsp;\">"
85                         "<BR>\n"
86         );
87
88         if (ib_summary) {
89                 wprintf("<SPAN CLASS=\"iconbar_link\">"
90                         "<A HREF=\"/summary\" "
91                         "TITLE=\"Your summary page\" "
92                         "TARGET=\"workspace\">"
93                 );
94                 if (ib_displayas != IB_TEXTONLY) {
95                         wprintf("<IMG BORDER=\"0\" WIDTH=\"32\" HEIGHT=\"32\" "
96                                 "SRC=\"/static/summary.gif\"><BR>");
97                 }
98                 if (ib_displayas != IB_PICONLY) {
99                         wprintf("Summary<BR>");
100                 }
101                 wprintf("</A></SPAN>\n");
102         }
103
104         if (ib_inbox) {
105                 wprintf("<SPAN CLASS=\"iconbar_link\">"
106                         "<A HREF=\"/dotgoto?room=_MAIL_\" "
107                         "TITLE=\"Go to your e-mail inbox\" "
108                         "TARGET=\"workspace\">"
109                 );
110                 if (ib_displayas != IB_TEXTONLY) {
111                         wprintf("<IMG BORDER=\"0\" WIDTH=\"32\" HEIGHT=\"32\" "
112                                 "SRC=\"/static/mail.gif\"><BR>");
113                 }
114                 if (ib_displayas != IB_PICONLY) {
115                         wprintf("Mail<BR>");
116                 }
117                 wprintf("</A></SPAN>\n");
118         }
119
120         if (ib_calendar) {
121                 wprintf("<SPAN CLASS=\"iconbar_link\">"
122                         "<A HREF=\"/dotgoto?room=Calendar\" "
123                         "TITLE=\"Go to your personal calendar\" "
124                         "TARGET=\"workspace\">"
125                 );
126                 if (ib_displayas != IB_TEXTONLY) {
127                         wprintf("<IMG BORDER=\"0\" WIDTH=\"32\" HEIGHT=\"32\" "
128                         "SRC=\"/static/vcalendar.gif\"><BR>");
129                 }
130                 if (ib_displayas != IB_PICONLY) {
131                         wprintf("Calendar<BR>");
132                 }
133                 wprintf("</A></SPAN>\n");
134         }
135
136         if (ib_tasks)  {
137                 wprintf("<SPAN CLASS=\"iconbar_link\">"
138                         "<A HREF=\"/dotgoto?room=Tasks\" "
139                         "TITLE=\"Go to your personal task list\" "
140                         "TARGET=\"workspace\">"
141                 );
142                 if (ib_displayas != IB_TEXTONLY) {
143                         wprintf("<IMG BORDER=\"0\" WIDTH=\"32\" HEIGHT=\"32\" "
144                         "SRC=\"/static/vcalendar.gif\"><BR>");
145                 }
146                 if (ib_displayas != IB_PICONLY) {
147                         wprintf("Tasks<BR>");
148                 }
149                 wprintf("</A></SPAN>\n");
150         }
151
152         if (ib_rooms) {
153                 wprintf("<SPAN CLASS=\"iconbar_link\">"
154                         "<A HREF=\"/knrooms\" TITLE=\"Shows a list of all "
155                         "Rooms that you have access to\" TARGET=\"workspace\">"
156                 );
157                 if (ib_displayas != IB_TEXTONLY) {
158                         wprintf("<IMG BORDER=\"0\" WIDTH=\"32\" HEIGHT=\"32\" "
159                         "SRC=\"/static/rooms-icon.gif\"><BR>");
160                 }
161                 if (ib_displayas != IB_PICONLY) {
162                         wprintf("Rooms<BR>");
163                 }
164                 wprintf("</A></SPAN>\n");
165         }
166
167         if (ib_users) {
168                 wprintf("<SPAN CLASS=\"iconbar_link\">"
169                         "<A HREF=\"/whobbs\" TITLE=\"See who is online right now\" "
170                         "TARGET=\"workspace\">"
171                 );
172                 if (ib_displayas != IB_TEXTONLY) {
173                         wprintf("<IMG BORDER=\"0\" WIDTH=\"32\" HEIGHT=\"32\" "
174                         "SRC=\"/static/users-icon.gif\"><BR>");
175                 }
176                 if (ib_displayas != IB_PICONLY) {
177                         wprintf("Users<BR>");
178                 }
179                 wprintf("</A></SPAN>\n");
180         }
181
182         if (ib_advanced) {
183                 wprintf("<SPAN CLASS=\"iconbar_link\">"
184                         "<A HREF=\"/display_main_menu\" "
185                         "TITLE=\"Advanced Options Menu: Advanced Room commands, "
186                         "Account Info, and Chat\" "
187                         "TARGET=\"workspace\">"
188                 );
189                 if (ib_displayas != IB_TEXTONLY) {
190                         wprintf("<IMG BORDER=\"0\" WIDTH=\"32\" HEIGHT=\"32\" "
191                         "SRC=\"/static/advanced-icon.gif\"><BR>");
192                 }
193                 if (ib_displayas != IB_PICONLY) {
194                         wprintf("Advanced options<BR>");
195                 }
196                 wprintf("</A></SPAN>\n");
197         }
198
199         if (ib_logoff) {
200                 wprintf("<SPAN CLASS=\"iconbar_link\">"
201                         "<A HREF=\"/termquit\" TITLE=\"Log off\" TARGET=\"_top\" "
202                         "onClick=\"return confirm('Log off now?');\">"
203                 );
204                 if (ib_displayas != IB_TEXTONLY) {
205                 wprintf("<IMG BORDER=\"0\" WIDTH=\"32\" HEIGHT=\"32\" "
206                         "SRC=\"/static/exit-icon.gif\"><BR>");
207                 }
208                 if (ib_displayas != IB_PICONLY) {
209                         wprintf("Log off<BR>");
210                 }
211                 wprintf("</A></SPAN>\n");
212         }
213
214         wprintf(
215                 "<SPAN CLASS=\"customize\">"
216                 "<A HREF=\"/display_customize_iconbar\" "
217                 "TITLE=\"Customize this menu\" "
218                 "TARGET=\"workspace\">customize this menu</A>"
219                 "</SPAN><BR>\n"
220         );
221
222         if (ib_citadel) if (ib_displayas != IB_TEXTONLY) wprintf(
223                 "<SPAN CLASS=\"powered_by\">"
224                 "<A HREF=\"http://uncensored.citadel.org/citadel\" "
225                 "TITLE=\"Find out more about Citadel/UX\" TARGET=\"aboutcit\" "
226                 "onMouseOver=\"window.status='Find out more about "
227                 "Citadel/UX'; return true;\">powered by<BR><IMG "
228                 "BORDER=\"0\" WIDTH=\"48\" HEIGHT=\"48\" "
229                 "SRC=\"/static/citadel-logo.jpg\" ALT=\"CITADEL/UX\"></A>"
230                 "</SPAN>\n"
231         );
232
233         wprintf("</CENTER>\n");
234         do_template("endbox");
235         wDumpContent(2);
236 }
237
238
239
240 void display_customize_iconbar(void) {
241         char iconbar[SIZ];
242         char buf[SIZ];
243         char key[SIZ], value[SIZ];
244         int i;
245
246         /* The initialized values of these variables also happen to
247          * specify the default values for users who haven't customized
248          * their iconbars.  These should probably be set in a master
249          * configuration somewhere.
250          */
251         int ib_displayas = IB_PICTEXT;  /* pictures and text, pictures, text */
252         int ib_logo = 1;        /* Site logo */
253         int ib_summary = 0;     /* Summary page icon */
254         int ib_inbox = 0;       /* Inbox icon */
255         int ib_calendar = 0;    /* Calendar icon */
256         int ib_tasks = 0;       /* Tasks icon */
257         int ib_rooms = 1;       /* Rooms icon */
258         int ib_users = 1;       /* Users icon */
259         int ib_advanced = 1;    /* Advanced Options icon */
260         int ib_logoff = 1;      /* Logoff button */
261         int ib_citadel = 1;     /* 'Powered by Citadel' logo */
262         /*
263          */
264
265         get_preference("iconbar", iconbar);
266         for (i=0; i<num_tokens(iconbar, ','); ++i) {
267                 extract_token(buf, iconbar, i, ',');
268                 extract_token(key, buf, 0, '=');
269                 extract_token(value, buf, 1, '=');
270
271                 if (!strcasecmp(key, "ib_displayas")) ib_displayas = atoi(value);
272                 if (!strcasecmp(key, "ib_logo")) ib_logo = atoi(value);
273                 if (!strcasecmp(key, "ib_summary")) ib_summary = atoi(value);
274                 if (!strcasecmp(key, "ib_inbox")) ib_inbox = atoi(value);
275                 if (!strcasecmp(key, "ib_calendar")) ib_calendar = atoi(value);
276                 if (!strcasecmp(key, "ib_tasks")) ib_tasks = atoi(value);
277                 if (!strcasecmp(key, "ib_rooms")) ib_rooms = atoi(value);
278                 if (!strcasecmp(key, "ib_users")) ib_users = atoi(value);
279                 if (!strcasecmp(key, "ib_advanced")) ib_advanced = atoi(value);
280                 if (!strcasecmp(key, "ib_logoff")) ib_logoff = atoi(value);
281                 if (!strcasecmp(key, "ib_citadel")) ib_citadel = atoi(value);
282
283         }
284
285         output_headers(3);
286         svprintf("BOXTITLE", WCS_STRING, "Customize the icon bar");
287         do_template("beginbox");
288
289         wprintf("<FORM METHOD=\"POST\" ACTION=\"/commit_iconbar\">\n");
290
291         wprintf("<CENTER>"
292                 "Display icons as: ");
293         for (i=0; i<=2; ++i) {
294                 wprintf("<INPUT TYPE=\"radio\" NAME=\"ib_displayas\" VALUE=\"%d\"", i);
295                 if (ib_displayas == i) wprintf(" CHECKED");
296                 wprintf(">");
297                 if (i == IB_PICTEXT) wprintf("pictures and text");
298                 if (i == IB_PICONLY) wprintf("pictures only");
299                 if (i == IB_TEXTONLY) wprintf("text only");
300                 wprintf("\n");
301         }
302         wprintf("<BR><BR>\n");
303
304         wprintf("Select the icons you would like to see displayed "
305                 "in the &quot;icon bar&quot; menu on the left side of the "
306                 "screen.</CENTER><BR>\n"
307         );
308
309         wprintf("<TABLE border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
310
311         wprintf("<TR BGCOLOR=\"#CCCCCC\"><TD>"
312                 "<INPUT TYPE=\"checkbox\" NAME=\"ib_logo\" VALUE=\"yes\" %s>"
313                 "</TD><TD>"
314                 "<IMG BORDER=\"0\" WIDTH=\"48\" HEIGHT=\"48\" "
315                 "SRC=\"/image&name=hello\" ALT=\"&nbsp;\">"
316                 "</TD><TD>"
317                 "<B>Site logo</B><BR>"
318                 "A graphic describing this site"
319                 "</TD></TR>\n",
320                 (ib_logo ? "CHECKED" : "")
321         );
322
323         wprintf("<TR><TD>"
324                 "<INPUT TYPE=\"checkbox\" NAME=\"ib_summary\" VALUE=\"yes\" %s>"
325                 "</TD><TD>"
326                 "<IMG BORDER=\"0\" WIDTH=\"48\" HEIGHT=\"48\" "
327                 "SRC=\"/static/summary.gif\" ALT=\"&nbsp;\">"
328                 "</TD><TD>"
329                 "<B>Summary</B><BR>"
330                 "Your summary page"
331                 "</TD></TR>\n",
332                 (ib_summary ? "CHECKED" : "")
333         );
334
335         wprintf("<TR BGCOLOR=\"#CCCCCC\"><TD>"
336                 "<INPUT TYPE=\"checkbox\" NAME=\"ib_inbox\" VALUE=\"yes\" %s>"
337                 "</TD><TD>"
338                 "<IMG BORDER=\"0\" WIDTH=\"48\" HEIGHT=\"48\" "
339                 "SRC=\"/static/mail.gif\" ALT=\"&nbsp;\">"
340                 "</TD><TD>"
341                 "<B>Mail (inbox)</B><BR>"
342                 "A shortcut to your e-mail Inbox."
343                 "</TD></TR>\n",
344                 (ib_inbox ? "CHECKED" : "")
345         );
346
347 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
348         wprintf("<TR><TD>"
349                 "<INPUT TYPE=\"checkbox\" NAME=\"ib_calendar\" "
350                 "VALUE=\"yes\" %s>"
351                 "</TD><TD>"
352                 "<IMG BORDER=\"0\" WIDTH=\"48\" HEIGHT=\"48\" "
353                 "SRC=\"/static/vcalendar.gif\" ALT=\"&nbsp;\">"
354                 "</TD><TD>"
355                 "<B>Calendar</B><BR>"
356                 "A shortcut to your personal calendar."
357                 "</TD></TR>\n",
358                 (ib_calendar ? "CHECKED" : "")
359         );
360
361         wprintf("<TR BGCOLOR=\"#CCCCCC\"><TD>"
362                 "<INPUT TYPE=\"checkbox\" NAME=\"ib_tasks\" VALUE=\"yes\" %s>"
363                 "</TD><TD>"
364                 "<IMG BORDER=\"0\" WIDTH=\"48\" HEIGHT=\"48\" "
365                 "SRC=\"/static/vcalendar.gif\" ALT=\"&nbsp;\">"
366                 "</TD><TD>"
367                 "<B>Tasks</B><BR>"
368                 "A shortcut to your personal task list."
369                 "</TD></TR>\n",
370                 (ib_tasks ? "CHECKED" : "")
371         );
372 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */
373
374         wprintf("<TR><TD>"
375                 "<INPUT TYPE=\"checkbox\" NAME=\"ib_rooms\" VALUE=\"yes\" %s>"
376                 "</TD><TD>"
377                 "<IMG BORDER=\"0\" WIDTH=\"48\" HEIGHT=\"48\" "
378                 "SRC=\"/static/rooms-icon.gif\" ALT=\"&nbsp;\">"
379                 "</TD><TD>"
380                 "<B>Rooms</B><BR>"
381                 "Clicking this icon displays a list of all accesible "
382                 "rooms (or folders) available."
383                 "</TD></TR>\n",
384                 (ib_rooms ? "CHECKED" : "")
385         );
386
387         wprintf("<TR BGCOLOR=\"#CCCCCC\"><TD>"
388                 "<INPUT TYPE=\"checkbox\" NAME=\"ib_users\" VALUE=\"yes\" %s>"
389                 "</TD><TD>"
390                 "<IMG BORDER=\"0\" WIDTH=\"48\" HEIGHT=\"48\" "
391                 "SRC=\"/static/users-icon.gif\" ALT=\"&nbsp;\">"
392                 "</TD><TD>"
393                 "<B>Users</B><BR>"
394                 "Clicking this icon displays a list of all users "
395                 "currently logged in."
396                 "</TD></TR>\n",
397                 (ib_users ? "CHECKED" : "")
398         );
399
400         wprintf("<TR><TD>"
401                 "<INPUT TYPE=\"checkbox\" NAME=\"ib_advanced\" "
402                 "VALUE=\"yes\" %s>"
403                 "</TD><TD>"
404                 "<IMG BORDER=\"0\" WIDTH=\"48\" HEIGHT=\"48\" "
405                 "SRC=\"/static/advanced-icon.gif\" ALT=\"&nbsp;\">"
406                 "</TD><TD>"
407                 "<B>Advanced options</B><BR>"
408                 "Access to the complete menu of Citadel functions."
409                 "</TD></TR>\n",
410                 (ib_advanced ? "CHECKED" : "")
411         );
412
413         wprintf("<TR BGCOLOR=\"#CCCCCC\"><TD>"
414                 "<INPUT TYPE=\"checkbox\" NAME=\"ib_logoff\" "
415                 "VALUE=\"yes\" %s>"
416                 "</TD><TD>"
417                 "<IMG BORDER=\"0\" WIDTH=\"48\" HEIGHT=\"48\" "
418                 "SRC=\"/static/exit-icon.gif\" ALT=\"&nbsp;\">"
419                 "</TD><TD>"
420                 "<B>Log off</B><BR>"
421                 "Exit from the Citadel system.  If you remove this icon "
422                 "then you will have no way out!"
423                 "</TD></TR>\n",
424                 (ib_logoff ? "CHECKED" : "")
425         );
426         wprintf("<TR><TD>"
427                 "<INPUT TYPE=\"checkbox\" NAME=\"ib_citadel\" "
428                 "VALUE=\"yes\" %s>"
429                 "</TD><TD>"
430                 "<IMG BORDER=\"0\" WIDTH=\"48\" HEIGHT=\"48\" "
431                 "SRC=\"/static/citadel-logo.jpg\" ALT=\"&nbsp;\">"
432                 "</TD><TD>"
433                 "<B>Citadel logo</B><BR>"
434                 "Displays the &quot;Powered by Citadel&quot; graphic"
435                 "</TD></TR>\n",
436                 (ib_citadel ? "CHECKED" : "")
437         );
438
439         wprintf("</TABLE><BR>\n"
440                 "<CENTER>"
441                 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">"
442                 "&nbsp;"
443                 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">"
444                 "</CENTER></FORM>\n"
445         );
446
447         do_template("endbox");
448         wDumpContent(2);
449 }
450
451
452 void commit_iconbar(void) {
453         char iconbar[SIZ];
454         int i;
455
456         char *boxen[] = {
457                 "ib_logo",
458                 "ib_summary",
459                 "ib_inbox",
460                 "ib_calendar",
461                 "ib_tasks",
462                 "ib_rooms",
463                 "ib_users",
464                 "ib_advanced",
465                 "ib_logoff",
466                 "ib_citadel"
467         };
468
469         if (strcmp(bstr("sc"), "OK")) {
470                 display_main_menu();
471                 return;
472         }
473
474         sprintf(iconbar, "ib_displayas=%d,", atoi(bstr("ib_displayas")));
475
476         for (i=0; i<(sizeof(boxen)/sizeof(char *)); ++i) {
477                 sprintf(&iconbar[strlen(iconbar)], ",%s=", boxen[i]);
478                 if (!strcasecmp(bstr(boxen[i]), "yes")) {
479                         sprintf(&iconbar[strlen(iconbar)], "1");
480                 }
481                 else {
482                         sprintf(&iconbar[strlen(iconbar)], "0");
483                 }
484         }
485
486         set_preference("iconbar", iconbar);
487
488         output_headers(3);
489         do_template("beginbox_nt");
490         wprintf(
491                 "<IMG SRC=\"/static/advanced-icon.gif\" "
492                 "onLoad=\"javascript:top['iconbarframe'].location.reload();\">"
493                 "&nbsp;"
494                 "Your icon bar has been updated.  Please select any of its "
495                 "choices to continue.\n"
496         );
497         do_template("endbox");
498         wDumpContent(2);
499 }