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