* First working version of the customizable iconbar. It contains a basic
[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 void do_iconbar(void) {
27         char iconbar[SIZ];
28         char buf[SIZ];
29         char key[SIZ], value[SIZ];
30         int i;
31
32         /* The initialized values of these variables also happen to
33          * specify the default values for users who haven't customized
34          * their iconbars.  These should probably be set in a master
35          * configuration somewhere.
36          */
37         int ib_logo = 1;        /* Site logo */
38         int ib_inbox = 0;       /* Inbox icon */
39         int ib_calendar = 0;    /* Calendar icon */
40         int ib_tasks = 0;       /* Tasks icon */
41         int ib_rooms = 1;       /* Rooms icon */
42         int ib_users = 1;       /* Users icon */
43         int ib_advanced = 1;    /* Advanced Options icon */
44         int ib_logoff = 1;      /* Logoff button */
45         int ib_citadel = 1;     /* 'Powered by Citadel' logo */
46         /*
47          */
48
49         get_preference("iconbar", iconbar);
50         for (i=0; i<num_tokens(iconbar, ','); ++i) {
51                 extract_token(buf, iconbar, i, ',');
52                 extract_token(key, buf, 0, '=');
53                 extract_token(value, buf, 1, '=');
54
55                 if (!strcasecmp(key, "ib_logo")) ib_logo = atoi(value);
56                 if (!strcasecmp(key, "ib_inbox")) ib_inbox = atoi(value);
57                 if (!strcasecmp(key, "ib_calendar")) ib_calendar = atoi(value);
58                 if (!strcasecmp(key, "ib_tasks")) ib_tasks = atoi(value);
59                 if (!strcasecmp(key, "ib_rooms")) ib_rooms = atoi(value);
60                 if (!strcasecmp(key, "ib_users")) ib_users = atoi(value);
61                 if (!strcasecmp(key, "ib_advanced")) ib_advanced = atoi(value);
62                 if (!strcasecmp(key, "ib_logoff")) ib_logoff = atoi(value);
63                 if (!strcasecmp(key, "ib_citadel")) ib_citadel = atoi(value);
64
65         }
66
67
68         output_headers(11);
69         do_template("beginbox_nt");
70
71         wprintf("<center>\n");
72
73         if (ib_logo) wprintf("\"<IMG BORDER=\"0\" WIDTH=\"48\" "
74                 "HEIGHT=\"48\" SRC=\"/image&name=hello\" ALT=\"&nbsp;\">"
75                 "<BR>\n"
76         );
77
78         if (ib_inbox) wprintf(
79                 "<SPAN CLASS=\"iconbar_link\">"
80                 "<A HREF=\"/dotgoto?room=_MAIL_\" "
81                 "TITLE=\"Go to your e-mail inbox\" "
82                 "TARGET=\"workspace\">"
83                 "<IMG BORDER=\"0\" WIDTH=\"32\" HEIGHT=\"32\" "
84                 "SRC=\"/static/mail.gif\">"
85                 "<BR>Mail</A></SPAN><BR>\n"
86         );
87
88         if (ib_calendar) wprintf(
89                 "<SPAN CLASS=\"iconbar_link\">"
90                 "<A HREF=\"/dotgoto?room=Calendar\" "
91                 "TITLE=\"Go to your personal calendar\" "
92                 "TARGET=\"workspace\">"
93                 "<IMG BORDER=\"0\" WIDTH=\"32\" HEIGHT=\"32\" "
94                 "SRC=\"/static/vcalendar.gif\">"
95                 "<BR>Calendar</A></SPAN><BR>\n"
96         );
97
98         if (ib_tasks) wprintf(
99                 "<SPAN CLASS=\"iconbar_link\">"
100                 "<A HREF=\"/dotgoto?room=Tasks\" "
101                 "TITLE=\"Go to your personal task list\" "
102                 "TARGET=\"workspace\">"
103                 "<IMG BORDER=\"0\" WIDTH=\"32\" HEIGHT=\"32\" "
104                 "SRC=\"/static/vcalendar.gif\">"
105                 "<BR>Tasks</A></SPAN><BR>\n"
106         );
107
108         if (ib_rooms) wprintf(
109                 "<SPAN CLASS=\"iconbar_link\">"
110                 "<A HREF=\"/knrooms\" TITLE=\"Shows a list of all "
111                 "Rooms that you have access to\" TARGET=\"workspace\">"
112                 "<IMG BORDER=\"0\" WIDTH=\"32\" HEIGHT=\"32\" "
113                 "SRC=\"/static/rooms-icon.gif\">"
114                 "<BR>Rooms</A></SPAN><BR>\n"
115         );
116
117         if (ib_users) wprintf(
118                 "<SPAN CLASS=\"iconbar_link\">"
119                 "<A HREF=\"/whobbs\" TITLE=\"See who is online right now\" "
120                 "TARGET=\"workspace\">"
121                 "<IMG BORDER=\"0\" WIDTH=\"32\" HEIGHT=\"32\" "
122                 "SRC=\"/static/users-icon.gif\">"
123                 "<BR>Users</A></SPAN><BR>\n"
124         );
125
126         if (ib_advanced) wprintf(
127                 "<SPAN CLASS=\"iconbar_link\">"
128                 "<A HREF=\"/display_main_menu\" "
129                 "TITLE=\"Advanced Options Menu: Advanced Room commands, "
130                 "Account Info, and Chat\" "
131                 "TARGET=\"workspace\">"
132                 "<IMG BORDER=\"0\" WIDTH=\"32\" HEIGHT=\"32\" "
133                 "SRC=\"/static/advanced-icon.gif\">"
134                 "<BR>Advanced options</A></SPAN><BR>\n"
135         );
136
137         if (ib_logoff) wprintf(
138                 "<SPAN CLASS=\"iconbar_link\">"
139                 "<A HREF=\"/termquit\" TITLE=\"Log off\" TARGET=\"_top\" "
140                 "onClick=\"return confirm('Log off now?');\">"
141                 "<IMG BORDER=\"0\" WIDTH=\"32\" HEIGHT=\"32\" "
142                 "SRC=\"/static/exit-icon.gif\">"
143                 "<BR>Log off</A></SPAN><BR>\n"
144         );
145
146         wprintf(
147                 "<SPAN CLASS=\"customize\">"
148                 "<A HREF=\"/display_customize_iconbar\" "
149                 "TITLE=\"Customize this menu\" "
150                 "TARGET=\"workspace\">customize this menu</A>"
151                 "</SPAN><BR>\n"
152         );
153
154         if (ib_citadel) wprintf(
155                 "<SPAN CLASS=\"powered_by\">"
156                 "<A HREF=\"http://uncensored.citadel.org/citadel\" "
157                 "TITLE=\"Find out more about Citadel/UX\" TARGET=\"aboutcit\" "
158                 "onMouseOver=\"window.status='Find out more about "
159                 "Citadel/UX'; return true;\">powered by<BR><IMG "
160                 "BORDER=\"0\" WIDTH=\"48\" HEIGHT=\"48\" "
161                 "SRC=\"/static/citadel-logo.jpg\" ALT=\"CITADEL/UX\"></A>"
162                 "</SPAN>\n"
163         );
164
165         wprintf("</CENTER>\n");
166         do_template("endbox");
167         wDumpContent(2);
168 }
169
170
171
172 void display_customize_iconbar(void) {
173         char iconbar[SIZ];
174         char buf[SIZ];
175         char key[SIZ], value[SIZ];
176         int i;
177
178         /* The initialized values of these variables also happen to
179          * specify the default values for users who haven't customized
180          * their iconbars.  These should probably be set in a master
181          * configuration somewhere.
182          */
183         int ib_logo = 1;        /* Site logo */
184         int ib_inbox = 0;       /* Inbox icon */
185         int ib_calendar = 0;    /* Calendar icon */
186         int ib_tasks = 0;       /* Tasks icon */
187         int ib_rooms = 1;       /* Rooms icon */
188         int ib_users = 1;       /* Users icon */
189         int ib_advanced = 1;    /* Advanced Options icon */
190         int ib_logoff = 1;      /* Logoff button */
191         int ib_citadel = 1;     /* 'Powered by Citadel' logo */
192         /*
193          */
194
195         get_preference("iconbar", iconbar);
196         for (i=0; i<num_tokens(iconbar, ','); ++i) {
197                 extract_token(buf, iconbar, i, ',');
198                 extract_token(key, buf, 0, '=');
199                 extract_token(value, buf, 1, '=');
200
201                 if (!strcasecmp(key, "ib_logo")) ib_logo = atoi(value);
202                 if (!strcasecmp(key, "ib_inbox")) ib_inbox = atoi(value);
203                 if (!strcasecmp(key, "ib_calendar")) ib_calendar = atoi(value);
204                 if (!strcasecmp(key, "ib_tasks")) ib_tasks = atoi(value);
205                 if (!strcasecmp(key, "ib_rooms")) ib_rooms = atoi(value);
206                 if (!strcasecmp(key, "ib_users")) ib_users = atoi(value);
207                 if (!strcasecmp(key, "ib_advanced")) ib_advanced = atoi(value);
208                 if (!strcasecmp(key, "ib_logoff")) ib_logoff = atoi(value);
209                 if (!strcasecmp(key, "ib_citadel")) ib_citadel = atoi(value);
210
211         }
212
213         output_headers(3);
214         svprintf("BOXTITLE", WCS_STRING, "Customize the icon bar");
215         do_template("beginbox");
216
217         wprintf("<CENTER>Select the icons you would like to see displayed "
218                 "in the &quot;icon bar&quot; menu on the left side of the "
219                 "screen.</CENTER><BR>\n"
220         );
221
222         wprintf("<FORM METHOD=\"POST\" ACTION=\"/commit_iconbar\">\n");
223         wprintf("<TABLE border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
224
225         wprintf("<TR BGCOLOR=\"#CCCCCC\"><TD>"
226                 "<INPUT TYPE=\"checkbox\" NAME=\"ib_logo\" VALUE=\"yes\" %s>"
227                 "</TD><TD>"
228                 "<IMG BORDER=\"0\" WIDTH=\"48\" HEIGHT=\"48\" "
229                 "SRC=\"/image&name=hello\" ALT=\"&nbsp;\">"
230                 "</TD><TD>"
231                 "<B>Site logo</B><BR>"
232                 "A graphic describing this site"
233                 "</TD></TR>\n",
234                 (ib_logo ? "CHECKED" : "")
235         );
236
237         wprintf("<TR><TD>"
238                 "<INPUT TYPE=\"checkbox\" NAME=\"ib_inbox\" VALUE=\"yes\" %s>"
239                 "</TD><TD>"
240                 "<IMG BORDER=\"0\" WIDTH=\"48\" HEIGHT=\"48\" "
241                 "SRC=\"/static/mail.gif\" ALT=\"&nbsp;\">"
242                 "</TD><TD>"
243                 "<B>Mail (inbox)</B><BR>"
244                 "A shortcut to your e-mail Inbox."
245                 "</TD></TR>\n",
246                 (ib_inbox ? "CHECKED" : "")
247         );
248
249 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
250         wprintf("<TR BGCOLOR=\"#CCCCCC\"><TD>"
251                 "<INPUT TYPE=\"checkbox\" NAME=\"ib_calendar\" "
252                 "VALUE=\"yes\" %s>"
253                 "</TD><TD>"
254                 "<IMG BORDER=\"0\" WIDTH=\"48\" HEIGHT=\"48\" "
255                 "SRC=\"/static/vcalendar.gif\" ALT=\"&nbsp;\">"
256                 "</TD><TD>"
257                 "<B>Calendar</B><BR>"
258                 "A shortcut to your personal calendar."
259                 "</TD></TR>\n",
260                 (ib_calendar ? "CHECKED" : "")
261         );
262
263         wprintf("<TR><TD>"
264                 "<INPUT TYPE=\"checkbox\" NAME=\"ib_tasks\" VALUE=\"yes\" %s>"
265                 "</TD><TD>"
266                 "<IMG BORDER=\"0\" WIDTH=\"48\" HEIGHT=\"48\" "
267                 "SRC=\"/static/vcalendar.gif\" ALT=\"&nbsp;\">"
268                 "</TD><TD>"
269                 "<B>Tasks</B><BR>"
270                 "A shortcut to your personal task list."
271                 "</TD></TR>\n",
272                 (ib_tasks ? "CHECKED" : "")
273         );
274 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */
275
276         wprintf("<TR BGCOLOR=\"#CCCCCC\"><TD>"
277                 "<INPUT TYPE=\"checkbox\" NAME=\"ib_rooms\" VALUE=\"yes\" %s>"
278                 "</TD><TD>"
279                 "<IMG BORDER=\"0\" WIDTH=\"48\" HEIGHT=\"48\" "
280                 "SRC=\"/static/rooms-icon.gif\" ALT=\"&nbsp;\">"
281                 "</TD><TD>"
282                 "<B>Rooms</B><BR>"
283                 "Clicking this icon displays a list of all accesible "
284                 "rooms (or folders) available."
285                 "</TD></TR>\n",
286                 (ib_rooms ? "CHECKED" : "")
287         );
288
289         wprintf("<TR><TD>"
290                 "<INPUT TYPE=\"checkbox\" NAME=\"ib_users\" VALUE=\"yes\" %s>"
291                 "</TD><TD>"
292                 "<IMG BORDER=\"0\" WIDTH=\"48\" HEIGHT=\"48\" "
293                 "SRC=\"/static/users-icon.gif\" ALT=\"&nbsp;\">"
294                 "</TD><TD>"
295                 "<B>Users</B><BR>"
296                 "Clicking this icon displays a list of all users "
297                 "currently logged in."
298                 "</TD></TR>\n",
299                 (ib_users ? "CHECKED" : "")
300         );
301
302         wprintf("<TR BGCOLOR=\"#CCCCCC\"><TD>"
303                 "<INPUT TYPE=\"checkbox\" NAME=\"ib_advanced\" "
304                 "VALUE=\"yes\" %s>"
305                 "</TD><TD>"
306                 "<IMG BORDER=\"0\" WIDTH=\"48\" HEIGHT=\"48\" "
307                 "SRC=\"/static/advanced-icon.gif\" ALT=\"&nbsp;\">"
308                 "</TD><TD>"
309                 "<B>Advanced options</B><BR>"
310                 "Access to the complete menu of Citadel functions."
311                 "</TD></TR>\n",
312                 (ib_advanced ? "CHECKED" : "")
313         );
314
315         wprintf("<TR><TD>"
316                 "<INPUT TYPE=\"checkbox\" NAME=\"ib_logoff\" "
317                 "VALUE=\"yes\" %s>"
318                 "</TD><TD>"
319                 "<IMG BORDER=\"0\" WIDTH=\"48\" HEIGHT=\"48\" "
320                 "SRC=\"/static/exit-icon.gif\" ALT=\"&nbsp;\">"
321                 "</TD><TD>"
322                 "<B>Log off</B><BR>"
323                 "Exit from the Citadel system.  If you remove this icon "
324                 "then you will have no way out!"
325                 "</TD></TR>\n",
326                 (ib_logoff ? "CHECKED" : "")
327         );
328         wprintf("<TR BGCOLOR=\"#CCCCCC\"><TD>"
329                 "<INPUT TYPE=\"checkbox\" NAME=\"ib_citadel\" "
330                 "VALUE=\"yes\" %s>"
331                 "</TD><TD>"
332                 "<IMG BORDER=\"0\" WIDTH=\"48\" HEIGHT=\"48\" "
333                 "SRC=\"/static/citadel-logo.jpg\" ALT=\"&nbsp;\">"
334                 "</TD><TD>"
335                 "<B>Citadel logo</B><BR>"
336                 "Displays the &quot;Powered by Citadel&quot; graphic"
337                 "</TD></TR>\n",
338                 (ib_citadel ? "CHECKED" : "")
339         );
340
341         wprintf("</TABLE><BR>\n"
342                 "<CENTER>"
343                 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">"
344                 "&nbsp;"
345                 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">"
346                 "</CENTER></FORM>\n"
347         );
348
349         do_template("endbox");
350         wDumpContent(2);
351 }
352
353
354 void commit_iconbar(void) {
355         char iconbar[SIZ];
356         int i;
357
358         char *boxen[] = {
359                 "ib_logo",
360                 "ib_inbox",
361                 "ib_calendar",
362                 "ib_tasks",
363                 "ib_rooms",
364                 "ib_users",
365                 "ib_advanced",
366                 "ib_logoff",
367                 "ib_citadel"
368         };
369
370         if (strcmp(bstr("sc"), "OK")) {
371                 display_main_menu();
372                 return;
373         }
374
375         strcpy(iconbar, "");
376
377         for (i=0; i<(sizeof(boxen)/sizeof(char *)); ++i) {
378                 if (i > 0) {
379                         sprintf(&iconbar[strlen(iconbar)], ",");
380                 }
381                 sprintf(&iconbar[strlen(iconbar)], "%s=", boxen[i]);
382                 if (!strcasecmp(bstr(boxen[i]), "yes")) {
383                         sprintf(&iconbar[strlen(iconbar)], "1");
384                 }
385                 else {
386                         sprintf(&iconbar[strlen(iconbar)], "0");
387                 }
388         }
389
390         set_preference("iconbar", iconbar);
391
392         output_headers(3);
393         do_template("beginbox_nt");
394         wprintf(
395                 "<IMG SRC=\"/static/advanced-icon.gif\" "
396                 "onLoad=\"javascript:top['iconbarframe'].location.reload();\">"
397                 "&nbsp;"
398                 "Your icon bar has been updated.  Please select any of its "
399                 "choices to continue.\n"
400         );
401         do_template("endbox");
402         wDumpContent(2);
403 }