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