* Unfinished code is now disabled.
[citadel.git] / webcit / roomops.c
1 /*
2  * $Id$
3  * Lots of different room-related operations.
4  */
5
6 #include "webcit.h"
7 #include "webserver.h"
8 #define MAX_FLOORS 128
9 char floorlist[MAX_FLOORS][SIZ]; /**< list of our floor names */
10
11 char *viewdefs[9]; /**< the different kinds of available views */
12
13 /*
14  * Initialize the viewdefs with localized strings
15  */
16 void initialize_viewdefs(void) {
17         viewdefs[0] = _("Bulletin Board");
18         viewdefs[1] = _("Mail Folder");
19         viewdefs[2] = _("Address Book");
20         viewdefs[3] = _("Calendar");
21         viewdefs[4] = _("Task List");
22         viewdefs[5] = _("Notes List");
23         viewdefs[6] = _("Wiki");
24         viewdefs[7] = _("Calendar List");
25         viewdefs[8] = _("Journal");
26 }
27
28 /*
29  * Determine which views are allowed as the default for creating a new room.
30  */
31 int is_view_allowed_as_default(int which_view)
32 {
33         switch(which_view) {
34                 case VIEW_BBS:          return(1);
35                 case VIEW_MAILBOX:      return(1);
36                 case VIEW_ADDRESSBOOK:  return(1);
37                 case VIEW_CALENDAR:     return(1);
38                 case VIEW_TASKS:        return(1);
39                 case VIEW_NOTES:        return(1);
40
41 #ifdef TECH_PREVIEW
42                 case VIEW_WIKI:         return(1);
43 #else /* TECH_PREVIEW */
44                 case VIEW_WIKI:         return(0);      /* because it isn't finished yet */
45 #endif /* TECH_PREVIEW */
46
47                 case VIEW_CALBRIEF:     return(0);
48                 case VIEW_JOURNAL:      return(0);
49                 default:                return(0);      /* should never get here */
50         }
51 }
52
53
54 /*
55  * load the list of floors
56  */
57 void load_floorlist(void)
58 {
59         int a;
60         char buf[SIZ];
61
62         for (a = 0; a < MAX_FLOORS; ++a)
63                 floorlist[a][0] = 0;
64
65         serv_puts("LFLR");
66         serv_getln(buf, sizeof buf);
67         if (buf[0] != '1') {
68                 strcpy(floorlist[0], "Main Floor");
69                 return;
70         }
71         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
72                 extract_token(floorlist[extract_int(buf, 0)], buf, 1, '|', sizeof floorlist[0]);
73         }
74 }
75
76
77 /*
78  * Free a session's march list
79  */
80 void free_march_list(struct wcsession *wcf)
81 {
82         struct march *mptr;
83
84         while (wcf->march != NULL) {
85                 mptr = wcf->march->next;
86                 free(wcf->march);
87                 wcf->march = mptr;
88         }
89
90 }
91
92
93
94 /*
95  * remove a room from the march list
96  */
97 void remove_march(char *aaa)
98 {
99         struct march *mptr, *mptr2;
100
101         if (WC->march == NULL)
102                 return;
103
104         if (!strcasecmp(WC->march->march_name, aaa)) {
105                 mptr = WC->march->next;
106                 free(WC->march);
107                 WC->march = mptr;
108                 return;
109         }
110         mptr2 = WC->march;
111         for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
112                 if (!strcasecmp(mptr->march_name, aaa)) {
113                         mptr2->next = mptr->next;
114                         free(mptr);
115                         mptr = mptr2;
116                 } else {
117                         mptr2 = mptr;
118                 }
119         }
120 }
121
122
123
124
125 /*
126  * display rooms in tree structure
127  */
128 void room_tree_list(struct roomlisting *rp)
129 {
130         char rmname[64];
131         int f;
132
133         if (rp == NULL) {
134                 return;
135         }
136
137         room_tree_list(rp->lnext);
138
139         strcpy(rmname, rp->rlname);
140         f = rp->rlflags;
141
142         wprintf("<a href=\"dotgoto&room=");
143         urlescputs(rmname);
144         wprintf("\"");
145         wprintf(">");
146         escputs1(rmname, 1, 1);
147         if ((f & QR_DIRECTORY) && (f & QR_NETWORK))
148                 wprintf("}");
149         else if (f & QR_DIRECTORY)
150                 wprintf("]");
151         else if (f & QR_NETWORK)
152                 wprintf(")");
153         else
154                 wprintf("&gt;");
155         wprintf("</a><tt> </tt>\n");
156
157         room_tree_list(rp->rnext);
158         free(rp);
159 }
160
161
162 /** 
163  * \brief Room ordering stuff (compare first by floor, then by order)
164  * \param r1 first roomlist to compare
165  * \param r2 second roomlist co compare
166  * \return are they the same???
167  */
168 int rordercmp(struct roomlisting *r1, struct roomlisting *r2)
169 {
170         if ((r1 == NULL) && (r2 == NULL))
171                 return (0);
172         if (r1 == NULL)
173                 return (-1);
174         if (r2 == NULL)
175                 return (1);
176         if (r1->rlfloor < r2->rlfloor)
177                 return (-1);
178         if (r1->rlfloor > r2->rlfloor)
179                 return (1);
180         if (r1->rlorder < r2->rlorder)
181                 return (-1);
182         if (r1->rlorder > r2->rlorder)
183                 return (1);
184         return (0);
185 }
186
187
188 /**
189  * \brief Common code for all room listings
190  * \param variety what???
191  */
192 void listrms(char *variety)
193 {
194         char buf[SIZ];
195         int num_rooms = 0;
196
197         struct roomlisting *rl = NULL;
198         struct roomlisting *rp;
199         struct roomlisting *rs;
200
201         /** Ask the server for a room list */
202         serv_puts(variety);
203         serv_getln(buf, sizeof buf);
204         if (buf[0] != '1') {
205                 wprintf("&nbsp;");
206                 return;
207         }
208
209         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
210                 ++num_rooms;
211                 rp = malloc(sizeof(struct roomlisting));
212                 extract_token(rp->rlname, buf, 0, '|', sizeof rp->rlname);
213                 rp->rlflags = extract_int(buf, 1);
214                 rp->rlfloor = extract_int(buf, 2);
215                 rp->rlorder = extract_int(buf, 3);
216                 rp->lnext = NULL;
217                 rp->rnext = NULL;
218
219                 rs = rl;
220                 if (rl == NULL) {
221                         rl = rp;
222                 } else
223                         while (rp != NULL) {
224                                 if (rordercmp(rp, rs) < 0) {
225                                         if (rs->lnext == NULL) {
226                                                 rs->lnext = rp;
227                                                 rp = NULL;
228                                         } else {
229                                                 rs = rs->lnext;
230                                         }
231                                 } else {
232                                         if (rs->rnext == NULL) {
233                                                 rs->rnext = rp;
234                                                 rp = NULL;
235                                         } else {
236                                                 rs = rs->rnext;
237                                         }
238                                 }
239                         }
240         }
241
242         room_tree_list(rl);
243
244         /**
245          * If no rooms were listed, print an nbsp to make the cell
246          * borders show up anyway.
247          */
248         if (num_rooms == 0) wprintf("&nbsp;");
249 }
250
251
252 /**
253  * \brief list all forgotten rooms
254  */
255 void zapped_list(void)
256 {
257         output_headers(1, 1, 1, 0, 0, 0);
258
259         svprintf("BOXTITLE", WCS_STRING, _("Zapped (forgotten) rooms"));
260         do_template("beginbox");
261
262         listrms("LZRM -1");
263
264         wprintf("<br /><br />\n");
265         wprintf(_("Click on any room to un-zap it and goto that room.\n"));
266         do_template("endbox");
267         wDumpContent(1);
268 }
269
270
271 /**
272  * \brief read this room's info file (set v to 1 for verbose mode)
273  */
274 void readinfo(void)
275 {
276         char buf[256];
277         char briefinfo[128];
278         char fullinfo[8192];
279         int fullinfo_len = 0;
280
281         serv_puts("RINF");
282         serv_getln(buf, sizeof buf);
283         if (buf[0] == '1') {
284
285                 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
286                         if (fullinfo_len < (sizeof fullinfo - sizeof buf)) {
287                                 strcpy(&fullinfo[fullinfo_len], buf);
288                                 fullinfo_len += strlen(buf);
289                         }
290                 }
291
292                 safestrncpy(briefinfo, fullinfo, sizeof briefinfo);
293                 strcpy(&briefinfo[50], "...");
294
295                 wprintf("<div class=\"infos\" "
296                 "onclick=\"javascript:Effect.Appear('room_infos', { duration: 0.5 });\" "
297                 ">");
298                 escputs(briefinfo);
299                 wprintf("</div><div id=\"room_infos\" style=\"display:none;\">");
300                 wprintf("<img class=\"close_infos\" "
301                         "onclick=\"javascript:Effect.Fade('room_infos', { duration: 0.5 });\" "
302                         "src=\"static/closewindow.gif\" alt=\"%s\">",
303                         _("Close window")
304                 );
305                 escputs(fullinfo);
306                 wprintf("</div>");
307         }
308         else {
309                 wprintf("&nbsp;");
310         }
311 }
312
313
314
315
316 /**
317  * \brief Display room banner icon.  
318  * The server doesn't actually
319  * need the room name, but we supply it in order to
320  * keep the browser from using a cached icon from 
321  * another room.
322  */
323 void embed_room_graphic(void) {
324         char buf[SIZ];
325
326         serv_puts("OIMG _roompic_");
327         serv_getln(buf, sizeof buf);
328         if (buf[0] == '2') {
329                 wprintf("<img height=\"64px\" src=\"image&name=_roompic_&room=");
330                 urlescputs(WC->wc_roomname);
331                 wprintf("\">");
332                 serv_puts("CLOS");
333                 serv_getln(buf, sizeof buf);
334         }
335         else if (WC->wc_view == VIEW_ADDRESSBOOK) {
336                 wprintf("<img height=48 width=48 src=\""
337                         "static/viewcontacts_48x.gif"
338                         "\">"
339                 );
340         }
341         else if ( (WC->wc_view == VIEW_CALENDAR) || (WC->wc_view == VIEW_CALBRIEF) ) {
342                 wprintf("<img height=48 width=48 src=\""
343                         "static/calarea_48x.gif"
344                         "\">"
345                 );
346         }
347         else if (WC->wc_view == VIEW_TASKS) {
348                 wprintf("<img height=48 width=48 src=\""
349                         "static/taskmanag_48x.gif"
350                         "\">"
351                 );
352         }
353         else if (WC->wc_view == VIEW_NOTES) {
354                 wprintf("<img height=48 width=48 src=\""
355                         "static/storenotes_48x.gif"
356                         "\">"
357                 );
358         }
359         else if (WC->wc_view == VIEW_MAILBOX) {
360                 wprintf("<img height=48 width=48 src=\""
361                         "static/privatemess_48x.gif"
362                         "\">"
363                 );
364         }
365         else {
366                 wprintf("<img height=48 width=48 src=\""
367                         "static/chatrooms_48x.gif"
368                         "\">"
369                 );
370         }
371
372 }
373
374
375
376 /**
377  * \brief Display the current view and offer an option to change it
378  */
379 void embed_view_o_matic(void) {
380         int i;
381
382         wprintf("<form name=\"viewomatic\" action=\"changeview\">\n");
383         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
384         wprintf("<label for=\"view_name\">");
385         wprintf(_("View as:"));
386         wprintf("</label> "
387                 "<select name=\"newview\" size=\"1\" "
388                 "id=\"view_name\" class=\"selectbox\" "
389                 "OnChange=\"location.href=viewomatic.newview.options"
390                 "[selectedIndex].value\">\n");
391
392         for (i=0; i<(sizeof viewdefs / sizeof (char *)); ++i) {
393                 /**
394                  * Only offer the views that make sense, given the default
395                  * view for the room.  For example, don't offer a Calendar
396                  * view in a non-Calendar room.
397                  */
398                 if (
399                         (i == WC->wc_view)
400                         ||      (i == WC->wc_default_view)                      /**< default */
401                         ||      ( (i == 0) && (WC->wc_default_view == 1) )      /**< mail or bulletin */
402                         ||      ( (i == 1) && (WC->wc_default_view == 0) )      /**< mail or bulletin */
403                         /** ||  ( (i == 7) && (WC->wc_default_view == 3) )      (calendar list temporarily disabled) */
404                 ) {
405
406                         wprintf("<option %s value=\"changeview?view=%d\">",
407                                 ((i == WC->wc_view) ? "selected" : ""),
408                                 i );
409                         escputs(viewdefs[i]);
410                         wprintf("</option>\n");
411                 }
412         }
413         wprintf("</select></form>\n");
414 }
415
416
417 /**
418  * \brief Display a search box
419  */
420 void embed_search_o_matic(void) {
421         wprintf("<form name=\"searchomatic\" action=\"do_search\">\n");
422         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
423         wprintf("<label for=\"search_name\">");
424         wprintf(_("Search: "));
425         wprintf("</label> <input "
426                 "type=\"text\" name=\"query\" size=\"15\" maxlength=\"128\" "
427                 "id=\"search_name\" class=\"inputbox\">\n"
428         );
429         wprintf("</form>\n");
430 }
431
432
433 /**
434  * \brief               Embed the room banner
435  *
436  * \param got           The information returned from a GOTO server command
437  * \param navbar_style  Determines which navigation buttons to display
438  *
439  */
440
441 void embed_room_banner(char *got, int navbar_style) {
442         char buf[256];
443         char buf2[1024];
444         char sanitized_roomname[256];
445         char with_files[256];
446         int file_count=0;
447         
448         /**
449          * We need to have the information returned by a GOTO server command.
450          * If it isn't supplied, we fake it by issuing our own GOTO.
451          */
452         if (got == NULL) {
453                 serv_printf("GOTO %s", WC->wc_roomname);
454                 serv_getln(buf, sizeof buf);
455                 got = buf;
456         }
457
458         /** The browser needs some information for its own use */
459         wprintf("<script type=\"text/javascript\">      \n"
460                 "       room_is_trash = %d;             \n"
461                 "</script>\n",
462                 WC->wc_is_trash
463         );
464
465         /**
466          * If the user happens to select the "make this my start page" link,
467          * we want it to remember the URL as a "/dotskip" one instead of
468          * a "skip" or "gotonext" or something like that.
469          */
470         snprintf(WC->this_page, sizeof(WC->this_page), "dotskip&room=%s",
471                 WC->wc_roomname);
472
473         /** Check for new mail. */
474         WC->new_mail = extract_int(&got[4], 9);
475         WC->wc_view = extract_int(&got[4], 11);
476
477         /* Is this a directory room and does it contain files and how many? */
478         if ((WC->room_flags & QR_DIRECTORY) && (WC->room_flags & QR_VISDIR))
479         {
480                 serv_puts("RDIR");
481                 serv_getln(buf2, sizeof buf2);
482                 if (buf2[0] == '1') while (serv_getln(buf2, sizeof buf2), strcmp(buf2, "000"))
483                         file_count++;
484                 snprintf (with_files, sizeof with_files, 
485                           "; <a href=\"display_room_directory\"> %d %s </a>", 
486                           file_count, 
487                           ((file_count>1) || (file_count == 0)  ? _("files") : _("file")));
488         }
489         else
490                 strcpy (with_files, "");
491                 
492         stresc(sanitized_roomname, 256, WC->wc_roomname, 1, 1);
493         svprintf("ROOMNAME", WCS_STRING, "%s", sanitized_roomname);
494         svprintf("NUMMSGS", WCS_STRING,
495                 _("%d new of %d messages%s"),
496                 extract_int(&got[4], 1),
497                 extract_int(&got[4], 2),
498                 with_files
499         );
500         svcallback("ROOMPIC", embed_room_graphic);
501         svcallback("ROOMINFO", readinfo);
502         svcallback("VIEWOMATIC", embed_view_o_matic);
503         svcallback("SEARCHOMATIC", embed_search_o_matic);
504         svcallback("START", offer_start_page);
505
506         do_template("roombanner");
507         if (navbar_style != navbar_none) {
508
509                 wprintf("<div id=\"navbar\"><ul>");
510
511                 if (navbar_style == navbar_default) wprintf(
512                         "<li class=\"ungoto\">"
513                         "<a href=\"ungoto\">"
514                         "<img align=\"middle\" src=\"static/ungoto2_24x.gif\" border=\"0\">"
515                         "<span class=\"navbar_link\">%s</span></A>"
516                         "</li>\n", _("Ungoto")
517                 );
518
519                 if ( (navbar_style == navbar_default) && (WC->wc_view == VIEW_BBS) ) {
520                         wprintf(
521                                 "<li class=\"newmess\">"
522                                 "<a href=\"readnew\">"
523                                 "<img align=\"middle\" src=\"static/newmess2_24x.gif\" border=\"0\">"
524                                 "<span class=\"navbar_link\">%s</span></A>"
525                                 "</li>\n", _("Read new messages")
526                         );
527                 }
528
529                 if (navbar_style == navbar_default) {
530                         switch(WC->wc_view) {
531                                 case VIEW_ADDRESSBOOK:
532                                         wprintf(
533                                                 "<li class=\"viewcontacts\">"
534                                                 "<a href=\"readfwd\">"
535                                                 "<img align=\"middle\" src=\"static/viewcontacts_24x.gif\" "
536                                                 "border=\"0\">"
537                                                 "<span class=\"navbar_link\">"
538                                                 "%s"
539                                                 "</span></a></li>\n", _("View contacts")
540                                         );
541                                         break;
542                                 case VIEW_CALENDAR:
543                                         wprintf(
544                                                 "<li class=\"staskday\">"
545                                                 "<a href=\"readfwd?calview=day\">"
546                                                 "<img align=\"middle\" src=\"static/taskday2_24x.gif\" "
547                                                 "border=\"0\">"
548                                                 "<span class=\"navbar_link\">"
549                                                 "%s"
550                                                 "</span></a></li>\n", _("Day view")
551                                         );
552                                         wprintf(
553                                                 "<li class=\"monthview\">"
554                                                 "<a href=\"readfwd?calview=month\">"
555                                                 "<img align=\"middle\" src=\"static/monthview2_24x.gif\" "
556                                                 "border=\"0\">"
557                                                 "<span class=\"navbar_link\">"
558                                                 "%s"
559                                                 "</span></a></li>\n", _("Month view")
560                                         );
561                                         break;
562                                 case VIEW_CALBRIEF:
563                                         wprintf(
564                                                 "<li class=\"monthview\">"
565                                                 "<a href=\"readfwd?calview=month\">"
566                                                 "<img align=\"middle\" src=\"static/monthview2_24x.gif\" "
567                                                 "border=\"0\">"
568                                                 "<span class=\"navbar_link\">"
569                                                 "%s"
570                                                 "</span></a></li>\n", _("Calendar list")
571                                         );
572                                         break;
573                                 case VIEW_TASKS:
574                                         wprintf(
575                                                 "<li class=\"taskmanag\">"
576                                                 "<a href=\"readfwd\">"
577                                                 "<img align=\"middle\" src=\"static/taskmanag_24x.gif\" "
578                                                 "border=\"0\">"
579                                                 "<span class=\"navbar_link\">"
580                                                 "%s"
581                                                 "</span></a></li>\n", _("View tasks")
582                                         );
583                                         break;
584                                 case VIEW_NOTES:
585                                         wprintf(
586                                                 "<li class=\"viewnotes\">"
587                                                 "<a href=\"readfwd\">"
588                                                 "<img align=\"middle\" src=\"static/viewnotes_24x.gif\" "
589                                                 "border=\"0\">"
590                                                 "<span class=\"navbar_link\">"
591                                                 "%s"
592                                                 "</span></a></li>\n", _("View notes")
593                                         );
594                                         break;
595                                 case VIEW_MAILBOX:
596                                         wprintf(
597                                                 "<li class=\"readallmess\">"
598                                                 "<a href=\"readfwd\">"
599                                                 "<img align=\"middle\" src=\"static/readallmess3_24x.gif\" "
600                                                 "border=\"0\">"
601                                                 "<span class=\"navbar_link\">"
602                                                 "%s"
603                                                 "</span></a></li>\n", _("View message list")
604                                         );
605                                         break;
606                                 case VIEW_WIKI:
607                                         wprintf(
608                                                 "<li class=\"readallmess\">"
609                                                 "<a href=\"readfwd\">"
610                                                 "<img align=\"middle\" src=\"static/readallmess3_24x.gif\" "
611                                                 "border=\"0\">"
612                                                 "<span class=\"navbar_link\">"
613                                                 "%s"
614                                                 "</span></a></li>\n", _("Wiki home")
615                                         );
616                                         break;
617                                 default:
618                                         wprintf(
619                                                 "<li class=\"readallmess\">"
620                                                 "<a href=\"readfwd\">"
621                                                 "<img align=\"middle\" src=\"static/readallmess3_24x.gif\" "
622                                                 "border=\"0\">"
623                                                 "<span class=\"navbar_link\">"
624                                                 "%s"
625                                                 "</span></a></li>\n", _("Read all messages")
626                                         );
627                                         break;
628                         }
629                 }
630
631                 if (navbar_style == navbar_default) {
632                         switch(WC->wc_view) {
633                                 case VIEW_ADDRESSBOOK:
634                                         wprintf(
635                                                 "<li class=\"addnewcontact\">"
636                                                 "<a href=\"display_enter\">"
637                                                 "<img align=\"middle\" src=\"static/addnewcontact_24x.gif\" "
638                                                 "border=\"0\"><span class=\"navbar_link\">"
639                                                 "%s"
640                                                 "</span></a></li>\n", _("Add new contact")
641                                         );
642                                         break;
643                                 case VIEW_CALENDAR:
644                                 case VIEW_CALBRIEF:
645                                         wprintf("<li class=\"addevent\"><a href=\"display_enter");
646                                         if (!IsEmptyStr(bstr("year" ))) wprintf("?year=%s", bstr("year"));
647                                         if (!IsEmptyStr(bstr("month"))) wprintf("?month=%s", bstr("month"));
648                                         if (!IsEmptyStr(bstr("day"  ))) wprintf("?day=%s", bstr("day"));
649                                         wprintf("\">"
650                                                 "<img align=\"middle\" src=\"static/addevent_24x.gif\" "
651                                                 "border=\"0\"><span class=\"navbar_link\">"
652                                                 "%s"
653                                                 "</span></a></li>\n", _("Add new event")
654                                         );
655                                         break;
656                                 case VIEW_TASKS:
657                                         wprintf(
658                                                 "<li class=\"newmess\">"
659                                                 "<a href=\"display_enter\">"
660                                                 "<img align=\"middle\" src=\"static/newmess3_24x.gif\" "
661                                                 "border=\"0\"><span class=\"navbar_link\">"
662                                                 "%s"
663                                                 "</span></a></li>\n", _("Add new task")
664                                         );
665                                         break;
666                                 case VIEW_NOTES:
667                                         wprintf(
668                                                 "<li class=\"enternewnote\">"
669                                                 "<a href=\"javascript:add_new_note();\">"
670                                                 "<img align=\"middle\" src=\"static/enternewnote_24x.gif\" "
671                                                 "border=\"0\"><span class=\"navbar_link\">"
672                                                 "%s"
673                                                 "</span></a></li>\n", _("Add new note")
674                                         );
675                                         break;
676                                 case VIEW_WIKI:
677                                         safestrncpy(buf, bstr("page"), sizeof buf);
678                                         str_wiki_index(buf);
679                                         wprintf(
680                                                 "<li class=\"newmess\">"
681                                                 "<a href=\"display_enter?wikipage=%s\">"
682                                                 "<img align=\"middle\" src=\"static/newmess3_24x.gif\" "
683                                                 "border=\"0\"><span class=\"navbar_link\">"
684                                                 "%s"
685                                                 "</span></a></li>\n", buf, _("Edit this page")
686                                         );
687                                         break;
688                                 case VIEW_MAILBOX:
689                                         wprintf(
690                                                 "<li class=\"newmess\">"
691                                                 "<a href=\"display_enter\">"
692                                                 "<img align=\"middle\" src=\"static/newmess3_24x.gif\" "
693                                                 "border=\"0\"><span class=\"navbar_link\">"
694                                                 "%s"
695                                                 "</span></a></li>\n", _("Write mail")
696                                         );
697                                         break;
698                                 default:
699                                         wprintf(
700                                                 "<li class=\"newmess\">"
701                                                 "<a href=\"display_enter\">"
702                                                 "<img align=\"middle\" src=\"static/newmess3_24x.gif\" "
703                                                 "border=\"0\"><span class=\"navbar_link\">"
704                                                 "%s"
705                                                 "</span></a></li>\n", _("Enter a message")
706                                         );
707                                         break;
708                         }
709                 }
710
711                 if (navbar_style == navbar_default) wprintf(
712                         "<li class=\"skipthisroom\">"
713                         "<a href=\"skip\" "
714                         "title=\"%s\">"
715                         "<img align=\"middle\" src=\"static/skipthisroom_24x.gif\" border=\"0\">"
716                         "<span class=\"navbar_link\">%s</span></a>"
717                         "</li>\n",
718                         _("Leave all messages marked as unread, go to next room with unread messages"),
719                         _("Skip this room")
720                 );
721
722                 if (navbar_style == navbar_default) wprintf(
723                         "<li class=\"markngo\">"
724                         "<a href=\"gotonext\" "
725                         "title=\"%s\">"
726                         "<img align=\"middle\" src=\"static/markngo_24x.gif\" border=\"0\">"
727                         "<span class=\"navbar_link\">%s</span></a>"
728                         "</li>\n",
729                         _("Mark all messages as read, go to next room with unread messages"),
730                         _("Goto next room")
731                 );
732
733                 wprintf("</ul></div>\n");
734         }
735
736 }
737
738
739 /**
740  * \brief back end routine to take the session to a new room
741  * \param gname room to go to
742  *
743  */
744 int gotoroom(char *gname)
745 {
746         char buf[SIZ];
747         static long ls = (-1L);
748         int err = 0;
749
750         /** store ungoto information */
751         strcpy(WC->ugname, WC->wc_roomname);
752         WC->uglsn = ls;
753
754         /** move to the new room */
755         serv_printf("GOTO %s", gname);
756         serv_getln(buf, sizeof buf);
757         if (buf[0] != '2') {
758                 buf[3] = 0;
759                 err = atoi(buf);
760                 serv_puts("GOTO _BASEROOM_");
761                 serv_getln(buf, sizeof buf);
762         }
763         if (buf[0] != '2') {
764                 buf[3] = 0;
765                 err = atoi(buf);
766                 return err;
767         }
768         extract_token(WC->wc_roomname, &buf[4], 0, '|', sizeof WC->wc_roomname);
769         WC->room_flags = extract_int(&buf[4], 4);
770         /* highest_msg_read = extract_int(&buf[4],6);
771            maxmsgnum = extract_int(&buf[4],5);
772          */
773         WC->is_mailbox = extract_int(&buf[4],7);
774         ls = extract_long(&buf[4], 6);
775         WC->wc_floor = extract_int(&buf[4], 10);
776         WC->wc_view = extract_int(&buf[4], 11);
777         WC->wc_default_view = extract_int(&buf[4], 12);
778         WC->wc_is_trash = extract_int(&buf[4], 13);
779         WC->room_flags2 = extract_int(&buf[4], 14);
780
781         if (WC->is_aide)
782                 WC->is_room_aide = WC->is_aide;
783         else
784                 WC->is_room_aide = (char) extract_int(&buf[4], 8);
785
786         remove_march(WC->wc_roomname);
787         if (!strcasecmp(gname, "_BASEROOM_"))
788                 remove_march(gname);
789
790         return err;
791 }
792
793
794 /**
795  * \brief Locate the room on the march list which we most want to go to.  
796  * Each room
797  * is measured given a "weight" of preference based on various factors.
798  * \param desired_floor the room number on the citadel server
799  * \return the roomname
800  */
801 char *pop_march(int desired_floor)
802 {
803         static char TheRoom[128];
804         int TheFloor = 0;
805         int TheOrder = 32767;
806         int TheWeight = 0;
807         int weight;
808         struct march *mptr = NULL;
809
810         strcpy(TheRoom, "_BASEROOM_");
811         if (WC->march == NULL)
812                 return (TheRoom);
813
814         for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
815                 weight = 0;
816                 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
817                         weight = weight + 10000;
818                 if (mptr->march_floor == desired_floor)
819                         weight = weight + 5000;
820
821                 weight = weight + ((128 - (mptr->march_floor)) * 128);
822                 weight = weight + (128 - (mptr->march_order));
823
824                 if (weight > TheWeight) {
825                         TheWeight = weight;
826                         strcpy(TheRoom, mptr->march_name);
827                         TheFloor = mptr->march_floor;
828                         TheOrder = mptr->march_order;
829                 }
830         }
831         return (TheRoom);
832 }
833
834
835
836 /*
837  * Goto next room having unread messages.
838  *
839  * We want to skip over rooms that the user has already been to, and take the
840  * user back to the lobby when done.  The room we end up in is placed in
841  * newroom - which is set to 0 (the lobby) initially.
842  * We start the search in the current room rather than the beginning to prevent
843  * two or more concurrent users from dragging each other back to the same room.
844  */
845 void gotonext(void)
846 {
847         char buf[256];
848         struct march *mptr = NULL;
849         struct march *mptr2 = NULL;
850         char room_name[128];
851         char next_room[128];
852         int ELoop = 0;
853
854         /*
855          * First check to see if the march-mode list is already allocated.
856          * If it is, pop the first room off the list and go there.
857          */
858
859         if (WC->march == NULL) {
860                 serv_puts("LKRN");
861                 serv_getln(buf, sizeof buf);
862                 if (buf[0] == '1')
863                         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
864                                 if (IsEmptyStr(buf)) {
865                                         if (ELoop > 10000)
866                                                 return;
867                                         if (ELoop % 100 == 0)
868                                                 sleeeeeeeeeep(1);
869                                         ELoop ++;
870                                         continue;                                       
871                                 }
872                                 extract_token(room_name, buf, 0, '|', sizeof room_name);
873                                 if (strcasecmp(room_name, WC->wc_roomname)) {
874                                         mptr = (struct march *) malloc(sizeof(struct march));
875                                         mptr->next = NULL;
876                                         safestrncpy(mptr->march_name, room_name, sizeof mptr->march_name);
877                                         mptr->march_floor = extract_int(buf, 2);
878                                         mptr->march_order = extract_int(buf, 3);
879                                         if (WC->march == NULL) 
880                                                 WC->march = mptr;
881                                         else 
882                                                 mptr2->next = mptr;
883                                         mptr2 = mptr;
884                                 }
885                                 buf[0] = '\0';
886                         }
887                 /*
888                  * add _BASEROOM_ to the end of the march list, so the user will end up
889                  * in the system base room (usually the Lobby>) at the end of the loop
890                  */
891                 mptr = (struct march *) malloc(sizeof(struct march));
892                 mptr->next = NULL;
893                 mptr->march_order = 0;
894                 mptr->march_floor = 0;
895                 strcpy(mptr->march_name, "_BASEROOM_");
896                 if (WC->march == NULL) {
897                         WC->march = mptr;
898                 } else {
899                         mptr2 = WC->march;
900                         while (mptr2->next != NULL)
901                                 mptr2 = mptr2->next;
902                         mptr2->next = mptr;
903                 }
904                 /*
905                  * ...and remove the room we're currently in, so a <G>oto doesn't make us
906                  * walk around in circles
907                  */
908                 remove_march(WC->wc_roomname);
909         }
910         if (WC->march != NULL) {
911                 strcpy(next_room, pop_march(-1));
912         } else {
913                 strcpy(next_room, "_BASEROOM_");
914         }
915
916
917         smart_goto(next_room);
918 }
919
920
921 /*
922  * goto next room
923  */
924 void smart_goto(char *next_room) {
925         gotoroom(next_room);
926         readloop("readnew");
927 }
928
929
930
931 /*
932  * mark all messages in current room as having been read
933  */
934 void slrp_highest(void)
935 {
936         char buf[256];
937
938         serv_puts("SLRP HIGHEST");
939         serv_getln(buf, sizeof buf);
940 }
941
942
943 /*
944  * un-goto the previous room
945  */
946 void ungoto(void)
947 {
948         char buf[SIZ];
949
950         if (!strcmp(WC->ugname, "")) {
951                 smart_goto(WC->wc_roomname);
952                 return;
953         }
954         serv_printf("GOTO %s", WC->ugname);
955         serv_getln(buf, sizeof buf);
956         if (buf[0] != '2') {
957                 smart_goto(WC->wc_roomname);
958                 return;
959         }
960         if (WC->uglsn >= 0L) {
961                 serv_printf("SLRP %ld", WC->uglsn);
962                 serv_getln(buf, sizeof buf);
963         }
964         strcpy(buf, WC->ugname);
965         strcpy(WC->ugname, "");
966         smart_goto(buf);
967 }
968
969 typedef struct __room_states {
970         char password[SIZ];
971         char dirname[SIZ];
972         char name[SIZ];
973         int flags;
974         int floor;
975         int order;
976         int view;
977         int flags2;
978 } room_states;
979
980
981
982
983 /*
984  * Set/clear/read the "self-service list subscribe" flag for a room
985  * 
986  * set newval to 0 to clear, 1 to set, any other value to leave unchanged.
987  * returns the new value.
988  */
989
990 int self_service(int newval) {
991         int current_value = 0;
992         char buf[SIZ];
993         
994         char name[SIZ];
995         char password[SIZ];
996         char dirname[SIZ];
997         int flags, floor, order, view, flags2;
998
999         serv_puts("GETR");
1000         serv_getln(buf, sizeof buf);
1001         if (buf[0] != '2') return(0);
1002
1003         extract_token(name, &buf[4], 0, '|', sizeof name);
1004         extract_token(password, &buf[4], 1, '|', sizeof password);
1005         extract_token(dirname, &buf[4], 2, '|', sizeof dirname);
1006         flags = extract_int(&buf[4], 3);
1007         floor = extract_int(&buf[4], 4);
1008         order = extract_int(&buf[4], 5);
1009         view = extract_int(&buf[4], 6);
1010         flags2 = extract_int(&buf[4], 7);
1011
1012         if (flags2 & QR2_SELFLIST) {
1013                 current_value = 1;
1014         }
1015         else {
1016                 current_value = 0;
1017         }
1018
1019         if (newval == 1) {
1020                 flags2 = flags2 | QR2_SELFLIST;
1021         }
1022         else if (newval == 0) {
1023                 flags2 = flags2 & ~QR2_SELFLIST;
1024         }
1025         else {
1026                 return(current_value);
1027         }
1028
1029         if (newval != current_value) {
1030                 serv_printf("SETR %s|%s|%s|%d|0|%d|%d|%d|%d",
1031                         name, password, dirname, flags,
1032                         floor, order, view, flags2);
1033                 serv_getln(buf, sizeof buf);
1034         }
1035
1036         return(newval);
1037
1038 }
1039
1040 int is_selflist(room_states *RoomFlags)
1041 {
1042         return ((RoomFlags->flags2 & QR2_SELFLIST) != 0);
1043 }
1044
1045 int is_publiclist(room_states *RoomFlags)
1046 {
1047         return ((RoomFlags->flags2 & QR2_SMTP_PUBLIC) != 0);
1048 }
1049
1050 int is_moderatedlist(room_states *RoomFlags)
1051 {
1052         return ((RoomFlags->flags2 & QR2_MODERATED) != 0);
1053 }
1054
1055 /*
1056  * Set/clear/read the "self-service list subscribe" flag for a room
1057  * 
1058  * set newval to 0 to clear, 1 to set, any other value to leave unchanged.
1059  * returns the new value.
1060  */
1061
1062 int get_roomflags(room_states *RoomOps) 
1063 {
1064         char buf[SIZ];
1065         
1066         serv_puts("GETR");
1067         serv_getln(buf, sizeof buf);
1068         if (buf[0] != '2') return(0);
1069
1070         extract_token(RoomOps->name, &buf[4], 0, '|', sizeof RoomOps->name);
1071         extract_token(RoomOps->password, &buf[4], 1, '|', sizeof RoomOps->password);
1072         extract_token(RoomOps->dirname, &buf[4], 2, '|', sizeof RoomOps->dirname);
1073         RoomOps->flags = extract_int(&buf[4], 3);
1074         RoomOps->floor = extract_int(&buf[4], 4);
1075         RoomOps->order = extract_int(&buf[4], 5);
1076         RoomOps->view = extract_int(&buf[4], 6);
1077         RoomOps->flags2 = extract_int(&buf[4], 7);
1078         return (1);
1079 }
1080
1081 int set_roomflags(room_states *RoomOps)
1082 {
1083         char buf[SIZ];
1084
1085         serv_printf("SETR %s|%s|%s|%d|0|%d|%d|%d|%d",
1086                     RoomOps->name, 
1087                     RoomOps->password, 
1088                     RoomOps->dirname, 
1089                     RoomOps->flags,
1090                     RoomOps->floor, 
1091                     RoomOps->order, 
1092                     RoomOps->view, 
1093                     RoomOps->flags2);
1094         serv_getln(buf, sizeof buf);
1095         return (1);
1096 }
1097
1098
1099
1100
1101
1102
1103 /*
1104  * display the form for editing a room
1105  */
1106 void display_editroom(void)
1107 {
1108         char buf[SIZ];
1109         char cmd[1024];
1110         char node[256];
1111         char remote_room[128];
1112         char recp[1024];
1113         char er_name[128];
1114         char er_password[10];
1115         char er_dirname[15];
1116         char er_roomaide[26];
1117         unsigned er_flags;
1118         unsigned er_flags2;
1119         int er_floor;
1120         int i, j;
1121         char *tab;
1122         char *shared_with;
1123         char *not_shared_with;
1124         int roompolicy = 0;
1125         int roomvalue = 0;
1126         int floorpolicy = 0;
1127         int floorvalue = 0;
1128         char pop3_host[128];
1129         char pop3_user[32];
1130         int bg = 0;
1131
1132         tab = bstr("tab");
1133         if (IsEmptyStr(tab)) tab = "admin";
1134
1135         load_floorlist();
1136         output_headers(1, 1, 1, 0, 0, 0);
1137
1138         wprintf("<div class=\"fix_scrollbar_bug\">");
1139
1140         /** print the tabbed dialog */
1141         wprintf("<ul class=\"tabbed_dialog\">\n");
1142
1143         wprintf("<li class=\"tablabel ");
1144         if (!strcmp(tab, "admin")) {
1145                 wprintf(" tab_cell_label\">");
1146                 wprintf(_("Administration"));
1147         }
1148         else {
1149                 wprintf("< tab_cell_edit\"><a href=\"display_editroom&tab=admin\">");
1150                 wprintf(_("Administration"));
1151                 wprintf("</a>");
1152         }
1153         wprintf("</li>\n");
1154
1155         if ( (WC->axlevel >= 6) || (WC->is_room_aide) ) {
1156
1157                 wprintf("<li class=\"tablabel ");
1158                 if (!strcmp(tab, "config")) {
1159                         wprintf(" tab_cell_label\">");
1160                         wprintf(_("Configuration"));
1161                 }
1162                 else {
1163                         wprintf(" tab_cell_edit\"><a href=\"display_editroom&tab=config\">");
1164                         wprintf(_("Configuration"));
1165                         wprintf("</a>");
1166                 }
1167                 wprintf("</li>\n");
1168
1169                 wprintf("<li class=\"tablabel ");
1170                 if (!strcmp(tab, "expire")) {
1171                         wprintf(" tab_cell_label\">");
1172                         wprintf(_("Message expire policy"));
1173                 }
1174                 else {
1175                         wprintf(" tab_cell_edit\"><a href=\"display_editroom&tab=expire\">");
1176                         wprintf(_("Message expire policy"));
1177                         wprintf("</a>");
1178                 }
1179                 wprintf("</li>\n");
1180         
1181                 wprintf("<li class=\"tablabel ");
1182                 if (!strcmp(tab, "access")) {
1183                         wprintf(" tab_cell_label\">");
1184                         wprintf(_("Access controls"));
1185                 }
1186                 else {
1187                         wprintf(" tab_cell_edit\"><a href=\"display_editroom&tab=access\">");
1188                         wprintf(_("Access controls"));
1189                         wprintf("</a>");
1190                 }
1191                 wprintf("</li>\n");
1192
1193                 wprintf("<li class=\"tablabel ");
1194                 if (!strcmp(tab, "sharing")) {
1195                         wprintf(" tab_cell_label\">");
1196                         wprintf(_("Sharing"));
1197                 }
1198                 else {
1199                         wprintf(" tab_cell_edit\"><a href=\"display_editroom&tab=sharing\">");
1200                         wprintf(_("Sharing"));
1201                         wprintf("</a>");
1202                 }
1203                 wprintf("</li>\n");
1204
1205                 wprintf("<li class=\"tablabel ");
1206                 if (!strcmp(tab, "listserv")) {
1207                         wprintf(" tab_cell_label\">");
1208                         wprintf(_("Mailing list service"));
1209                 }
1210                 else {
1211                         wprintf("< tab_cell_edit\"><a href=\"display_editroom&tab=listserv\">");
1212                         wprintf(_("Mailing list service"));
1213                         wprintf("</a>");
1214                 }
1215                 wprintf("</li>\n");
1216
1217         }
1218
1219         wprintf("<li class=\"tablabel ");
1220         if (!strcmp(tab, "feeds")) {
1221                 wprintf(" tab_cell_label\">");
1222                 wprintf(_("Remote retrieval"));
1223         }
1224         else {
1225                 wprintf("< tab_cell_edit\"><a href=\"display_editroom&tab=feeds\">");
1226                 wprintf(_("Remote retrieval"));
1227                 wprintf("</a>");
1228         }
1229         wprintf("</li>\n");
1230
1231         wprintf("</ul>\n");
1232         /* end tabbed dialog */ 
1233
1234         /* begin content of whatever tab is open now */
1235
1236         if (!strcmp(tab, "admin")) {
1237                 wprintf("<div class=\"tabcontent\">");
1238                 wprintf("<ul>"
1239                         "<li><a href=\"delete_room\" "
1240                         "onClick=\"return confirm('");
1241                 wprintf(_("Are you sure you want to delete this room?"));
1242                 wprintf("');\">\n");
1243                 wprintf(_("Delete this room"));
1244                 wprintf("</a>\n"
1245                         "<li><a href=\"display_editroompic\">\n");
1246                 wprintf(_("Set or change the icon for this room's banner"));
1247                 wprintf("</a>\n"
1248                         "<li><a href=\"display_editinfo\">\n");
1249                 wprintf(_("Edit this room's Info file"));
1250                 wprintf("</a>\n"
1251                         "</ul>");
1252                 wprintf("</div>");
1253         }
1254
1255         if (!strcmp(tab, "config")) {
1256                 wprintf("<div class=\"tabcontent\">");
1257                 serv_puts("GETR");
1258                 serv_getln(buf, sizeof buf);
1259
1260                 if (!strncmp(buf, "550", 3)) {
1261                         wprintf("<br><br><div align=center>%s</div><br><br>\n",
1262                                 _("Higher access is required to access this function.")
1263                         );
1264                 }
1265                 else if (buf[0] != '2') {
1266                         wprintf("<br><br><div align=center>%s</div><br><br>\n", &buf[4]);
1267                 }
1268                 else {
1269                         extract_token(er_name, &buf[4], 0, '|', sizeof er_name);
1270                         extract_token(er_password, &buf[4], 1, '|', sizeof er_password);
1271                         extract_token(er_dirname, &buf[4], 2, '|', sizeof er_dirname);
1272                         er_flags = extract_int(&buf[4], 3);
1273                         er_floor = extract_int(&buf[4], 4);
1274                         er_flags2 = extract_int(&buf[4], 7);
1275         
1276                         wprintf("<form method=\"POST\" action=\"editroom\">\n");
1277                         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
1278                 
1279                         wprintf("<ul><li>");
1280                         wprintf(_("Name of room: "));
1281                         wprintf("<input type=\"text\" NAME=\"er_name\" VALUE=\"%s\" MAXLENGTH=\"%d\">\n",
1282                                 er_name,
1283                                 (sizeof(er_name)-1)
1284                         );
1285                 
1286                         wprintf("<li>");
1287                         wprintf(_("Resides on floor: "));
1288                         wprintf("<select NAME=\"er_floor\" SIZE=\"1\"");
1289                         if (er_flags & QR_MAILBOX)
1290                                 wprintf("disabled >\n");
1291                         for (i = 0; i < 128; ++i)
1292                                 if (!IsEmptyStr(floorlist[i])) {
1293                                         wprintf("<OPTION ");
1294                                         if (i == er_floor )
1295                                                 wprintf("SELECTED ");
1296                                         wprintf("VALUE=\"%d\">", i);
1297                                         escputs(floorlist[i]);
1298                                         wprintf("</OPTION>\n");
1299                                 }
1300                         wprintf("</select>\n");
1301
1302                         wprintf("<li>");
1303                         wprintf(_("Type of room:"));
1304                         wprintf("<ul>\n");
1305         
1306                         wprintf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"public\" ");
1307                         if ((er_flags & (QR_PRIVATE + QR_MAILBOX)) == 0)
1308                                 wprintf("CHECKED ");
1309                         wprintf("OnChange=\""
1310                                 "       if (this.form.type[0].checked == true) {        "
1311                                 "               this.form.er_floor.disabled = false;    "
1312                                 "       }                                               "
1313                                 "\"> ");
1314                         wprintf(_("Public (automatically appears to everyone)"));
1315                         wprintf("\n");
1316         
1317                         wprintf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"hidden\" ");
1318                         if ((er_flags & QR_PRIVATE) &&
1319                         (er_flags & QR_GUESSNAME))
1320                                 wprintf("CHECKED ");
1321                         wprintf(" OnChange=\""
1322                                 "       if (this.form.type[1].checked == true) {        "
1323                                 "               this.form.er_floor.disabled = false;    "
1324                                 "       }                                               "
1325                                 "\"> ");
1326                         wprintf(_("Private - hidden (accessible to anyone who knows its name)"));
1327                 
1328                         wprintf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
1329                         if ((er_flags & QR_PRIVATE) &&
1330                         (er_flags & QR_PASSWORDED))
1331                                 wprintf("CHECKED ");
1332                         wprintf(" OnChange=\""
1333                                 "       if (this.form.type[2].checked == true) {        "
1334                                 "               this.form.er_floor.disabled = false;    "
1335                                 "       }                                               "
1336                                 "\"> ");
1337                         wprintf(_("Private - require password: "));
1338                         wprintf("\n<input type=\"text\" NAME=\"er_password\" VALUE=\"%s\" MAXLENGTH=\"9\">\n",
1339                                 er_password);
1340                 
1341                         wprintf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
1342                         if ((er_flags & QR_PRIVATE)
1343                         && ((er_flags & QR_GUESSNAME) == 0)
1344                         && ((er_flags & QR_PASSWORDED) == 0))
1345                                 wprintf("CHECKED ");
1346                         wprintf(" OnChange=\""
1347                                 "       if (this.form.type[3].checked == true) {        "
1348                                 "               this.form.er_floor.disabled = false;    "
1349                                 "       }                                               "
1350                                 "\"> ");
1351                         wprintf(_("Private - invitation only"));
1352                 
1353                         wprintf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"personal\" ");
1354                         if (er_flags & QR_MAILBOX)
1355                                 wprintf("CHECKED ");
1356                         wprintf (" OnChange=\""
1357                                 "       if (this.form.type[4].checked == true) {        "
1358                                 "               this.form.er_floor.disabled = true;     "
1359                                 "       }                                               "
1360                                 "\"> ");
1361                         wprintf(_("Personal (mailbox for you only)"));
1362                         
1363                         wprintf("\n<li><input type=\"checkbox\" NAME=\"bump\" VALUE=\"yes\" ");
1364                         wprintf("> ");
1365                         wprintf(_("If private, cause current users to forget room"));
1366                 
1367                         wprintf("\n</ul>\n");
1368                 
1369                         wprintf("<li><input type=\"checkbox\" NAME=\"prefonly\" VALUE=\"yes\" ");
1370                         if (er_flags & QR_PREFONLY)
1371                                 wprintf("CHECKED ");
1372                         wprintf("> ");
1373                         wprintf(_("Preferred users only"));
1374                 
1375                         wprintf("\n<li><input type=\"checkbox\" NAME=\"readonly\" VALUE=\"yes\" ");
1376                         if (er_flags & QR_READONLY)
1377                                 wprintf("CHECKED ");
1378                         wprintf("> ");
1379                         wprintf(_("Read-only room"));
1380                 
1381                         wprintf("\n<li><input type=\"checkbox\" NAME=\"collabdel\" VALUE=\"yes\" ");
1382                         if (er_flags2 & QR2_COLLABDEL)
1383                                 wprintf("CHECKED ");
1384                         wprintf("> ");
1385                         wprintf(_("All users allowed to post may also delete messages"));
1386                 
1387                         /** directory stuff */
1388                         wprintf("\n<li><input type=\"checkbox\" NAME=\"directory\" VALUE=\"yes\" ");
1389                         if (er_flags & QR_DIRECTORY)
1390                                 wprintf("CHECKED ");
1391                         wprintf("> ");
1392                         wprintf(_("File directory room"));
1393         
1394                         wprintf("\n<ul><li>");
1395                         wprintf(_("Directory name: "));
1396                         wprintf("<input type=\"text\" NAME=\"er_dirname\" VALUE=\"%s\" MAXLENGTH=\"14\">\n",
1397                                 er_dirname);
1398         
1399                         wprintf("<li><input type=\"checkbox\" NAME=\"ulallowed\" VALUE=\"yes\" ");
1400                         if (er_flags & QR_UPLOAD)
1401                         wprintf("CHECKED ");
1402                         wprintf("> ");
1403                         wprintf(_("Uploading allowed"));
1404                 
1405                         wprintf("\n<li><input type=\"checkbox\" NAME=\"dlallowed\" VALUE=\"yes\" ");
1406                         if (er_flags & QR_DOWNLOAD)
1407                                 wprintf("CHECKED ");
1408                         wprintf("> ");
1409                         wprintf(_("Downloading allowed"));
1410                 
1411                         wprintf("\n<li><input type=\"checkbox\" NAME=\"visdir\" VALUE=\"yes\" ");
1412                         if (er_flags & QR_VISDIR)
1413                                 wprintf("CHECKED ");
1414                         wprintf("> ");
1415                         wprintf(_("Visible directory"));
1416                         wprintf("</ul>\n");
1417                 
1418                         /** end of directory stuff */
1419         
1420                         wprintf("<li><input type=\"checkbox\" NAME=\"network\" VALUE=\"yes\" ");
1421                         if (er_flags & QR_NETWORK)
1422                                 wprintf("CHECKED ");
1423                         wprintf("> ");
1424                         wprintf(_("Network shared room"));
1425         
1426                         wprintf("\n<li><input type=\"checkbox\" NAME=\"permanent\" VALUE=\"yes\" ");
1427                         if (er_flags & QR_PERMANENT)
1428                                 wprintf("CHECKED ");
1429                         wprintf("> ");
1430                         wprintf(_("Permanent (does not auto-purge)"));
1431         
1432                         wprintf("\n<li><input type=\"checkbox\" NAME=\"subjectreq\" VALUE=\"yes\" ");
1433                         if (er_flags2 & QR2_SUBJECTREQ)
1434                                 wprintf("CHECKED ");
1435                         wprintf("> ");
1436                         wprintf(_("Subject Required (Force users to specify a message subject)"));
1437         
1438                         /** start of anon options */
1439                 
1440                         wprintf("\n<li>");
1441                         wprintf(_("Anonymous messages"));
1442                         wprintf("<ul>\n");
1443                 
1444                         wprintf("<li><input type=\"radio\" NAME=\"anon\" VALUE=\"no\" ");
1445                         if (((er_flags & QR_ANONONLY) == 0)
1446                         && ((er_flags & QR_ANONOPT) == 0))
1447                                 wprintf("CHECKED ");
1448                         wprintf("> ");
1449                         wprintf(_("No anonymous messages"));
1450         
1451                         wprintf("\n<li><input type=\"radio\" NAME=\"anon\" VALUE=\"anononly\" ");
1452                         if (er_flags & QR_ANONONLY)
1453                                 wprintf("CHECKED ");
1454                         wprintf("> ");
1455                         wprintf(_("All messages are anonymous"));
1456                 
1457                         wprintf("\n<li><input type=\"radio\" NAME=\"anon\" VALUE=\"anon2\" ");
1458                         if (er_flags & QR_ANONOPT)
1459                                 wprintf("CHECKED ");
1460                         wprintf("> ");
1461                         wprintf(_("Prompt user when entering messages"));
1462                         wprintf("</ul>\n");
1463                 
1464                 /* end of anon options */
1465                 
1466                         wprintf("<li>");
1467                         wprintf(_("Room aide: "));
1468                         serv_puts("GETA");
1469                         serv_getln(buf, sizeof buf);
1470                         if (buf[0] != '2') {
1471                                 wprintf("<em>%s</em>\n", &buf[4]);
1472                         } else {
1473                                 extract_token(er_roomaide, &buf[4], 0, '|', sizeof er_roomaide);
1474                                 wprintf("<input type=\"text\" NAME=\"er_roomaide\" VALUE=\"%s\" MAXLENGTH=\"25\">\n", er_roomaide);
1475                         }
1476                 
1477                         wprintf("</ul><CENTER>\n");
1478                         wprintf("<input type=\"hidden\" NAME=\"tab\" VALUE=\"config\">\n"
1479                                 "<input type=\"submit\" NAME=\"ok_button\" VALUE=\"%s\">"
1480                                 "&nbsp;"
1481                                 "<input type=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">"
1482                                 "</CENTER>\n",
1483                                 _("Save changes"),
1484                                 _("Cancel")
1485                         );
1486                 }
1487                 wprintf("</div>");
1488         }
1489
1490
1491         /* Sharing the room with other Citadel nodes... */
1492         if (!strcmp(tab, "sharing")) {
1493                 wprintf("<div class=\"tabcontent\">");
1494
1495                 shared_with = strdup("");
1496                 not_shared_with = strdup("");
1497
1498                 /** Learn the current configuration */
1499                 serv_puts("CONF getsys|application/x-citadel-ignet-config");
1500                 serv_getln(buf, sizeof buf);
1501                 if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1502                         extract_token(node, buf, 0, '|', sizeof node);
1503                         not_shared_with = realloc(not_shared_with,
1504                                         strlen(not_shared_with) + 32);
1505                         strcat(not_shared_with, node);
1506                         strcat(not_shared_with, "\n");
1507                 }
1508
1509                 serv_puts("GNET");
1510                 serv_getln(buf, sizeof buf);
1511                 if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1512                         extract_token(cmd, buf, 0, '|', sizeof cmd);
1513                         extract_token(node, buf, 1, '|', sizeof node);
1514                         extract_token(remote_room, buf, 2, '|', sizeof remote_room);
1515                         if (!strcasecmp(cmd, "ignet_push_share")) {
1516                                 shared_with = realloc(shared_with,
1517                                                 strlen(shared_with) + 32);
1518                                 strcat(shared_with, node);
1519                                 if (!IsEmptyStr(remote_room)) {
1520                                         strcat(shared_with, "|");
1521                                         strcat(shared_with, remote_room);
1522                                 }
1523                                 strcat(shared_with, "\n");
1524                         }
1525                 }
1526
1527                 for (i=0; i<num_tokens(shared_with, '\n'); ++i) {
1528                         extract_token(buf, shared_with, i, '\n', sizeof buf);
1529                         extract_token(node, buf, 0, '|', sizeof node);
1530                         for (j=0; j<num_tokens(not_shared_with, '\n'); ++j) {
1531                                 extract_token(cmd, not_shared_with, j, '\n', sizeof cmd);
1532                                 if (!strcasecmp(node, cmd)) {
1533                                         remove_token(not_shared_with, j, '\n');
1534                                 }
1535                         }
1536                 }
1537
1538                 /* Display the stuff */
1539                 wprintf("<CENTER><br />"
1540                         "<table border=1 cellpadding=5><tr>"
1541                         "<td><B><I>");
1542                 wprintf(_("Shared with"));
1543                 wprintf("</I></B></td>"
1544                         "<td><B><I>");
1545                 wprintf(_("Not shared with"));
1546                 wprintf("</I></B></td></tr>\n"
1547                         "<tr><td VALIGN=TOP>\n");
1548
1549                 wprintf("<table border=0 cellpadding=5><tr class=\"tab_cell\"><td>");
1550                 wprintf(_("Remote node name"));
1551                 wprintf("</td><td>");
1552                 wprintf(_("Remote room name"));
1553                 wprintf("</td><td>");
1554                 wprintf(_("Actions"));
1555                 wprintf("</td></tr>\n");
1556
1557                 for (i=0; i<num_tokens(shared_with, '\n'); ++i) {
1558                         extract_token(buf, shared_with, i, '\n', sizeof buf);
1559                         extract_token(node, buf, 0, '|', sizeof node);
1560                         extract_token(remote_room, buf, 1, '|', sizeof remote_room);
1561                         if (!IsEmptyStr(node)) {
1562                                 wprintf("<form method=\"POST\" action=\"netedit\">");
1563                                 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
1564                                 wprintf("<tr><td>%s</td>\n", node);
1565
1566                                 wprintf("<td>");
1567                                 if (!IsEmptyStr(remote_room)) {
1568                                         escputs(remote_room);
1569                                 }
1570                                 wprintf("</td>");
1571
1572                                 wprintf("<td>");
1573                 
1574                                 wprintf("<input type=\"hidden\" NAME=\"line\" "
1575                                         "VALUE=\"ignet_push_share|");
1576                                 urlescputs(node);
1577                                 if (!IsEmptyStr(remote_room)) {
1578                                         wprintf("|");
1579                                         urlescputs(remote_room);
1580                                 }
1581                                 wprintf("\">");
1582                                 wprintf("<input type=\"hidden\" NAME=\"tab\" VALUE=\"sharing\">\n");
1583                                 wprintf("<input type=\"hidden\" NAME=\"cmd\" VALUE=\"remove\">\n");
1584                                 wprintf("<input type=\"submit\" "
1585                                         "NAME=\"unshare_button\" VALUE=\"%s\">", _("Unshare"));
1586                                 wprintf("</td></tr></form>\n");
1587                         }
1588                 }
1589
1590                 wprintf("</table>\n");
1591                 wprintf("</td><td VALIGN=TOP>\n");
1592                 wprintf("<table border=0 cellpadding=5><tr class=\"tab_cell\"><td>");
1593                 wprintf(_("Remote node name"));
1594                 wprintf("</td><td>");
1595                 wprintf(_("Remote room name"));
1596                 wprintf("</td><td>");
1597                 wprintf(_("Actions"));
1598                 wprintf("</td></tr>\n");
1599
1600                 for (i=0; i<num_tokens(not_shared_with, '\n'); ++i) {
1601                         extract_token(node, not_shared_with, i, '\n', sizeof node);
1602                         if (!IsEmptyStr(node)) {
1603                                 wprintf("<form method=\"POST\" action=\"netedit\">");
1604                                 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
1605                                 wprintf("<tr><td>");
1606                                 escputs(node);
1607                                 wprintf("</td><td>"
1608                                         "<input type=\"INPUT\" "
1609                                         "NAME=\"suffix\" "
1610                                         "MAXLENGTH=128>"
1611                                         "</td><td>");
1612                                 wprintf("<input type=\"hidden\" "
1613                                         "NAME=\"line\" "
1614                                         "VALUE=\"ignet_push_share|");
1615                                 urlescputs(node);
1616                                 wprintf("|\">");
1617                                 wprintf("<input type=\"hidden\" NAME=\"tab\" "
1618                                         "VALUE=\"sharing\">\n");
1619                                 wprintf("<input type=\"hidden\" NAME=\"cmd\" "
1620                                         "VALUE=\"add\">\n");
1621                                 wprintf("<input type=\"submit\" "
1622                                         "NAME=\"add_button\" VALUE=\"%s\">", _("Share"));
1623                                 wprintf("</td></tr></form>\n");
1624                         }
1625                 }
1626
1627                 wprintf("</table>\n");
1628                 wprintf("</td></tr>"
1629                         "</table></CENTER><br />\n"
1630                         "<I><B>%s</B><ul><li>", _("Notes:"));
1631                 wprintf(_("When sharing a room, "
1632                         "it must be shared from both ends.  Adding a node to "
1633                         "the 'shared' list sends messages out, but in order to"
1634                         " receive messages, the other nodes must be configured"
1635                         " to send messages out to your system as well. "
1636                         "<li>If the remote room name is blank, it is assumed "
1637                         "that the room name is identical on the remote node."
1638                         "<li>If the remote room name is different, the remote "
1639                         "node must also configure the name of the room here."
1640                         "</ul></I><br />\n"
1641                 ));
1642
1643                 wprintf("</div>");
1644         }
1645
1646         /* Mailing list management */
1647         if (!strcmp(tab, "listserv")) {
1648                 room_states RoomFlags;
1649                 wprintf("<div class=\"tabcontent\">");
1650
1651                 wprintf("<br /><center>"
1652                         "<table BORDER=0 WIDTH=100%% CELLPADDING=5>"
1653                         "<tr><td VALIGN=TOP>");
1654
1655                 wprintf(_("<i>The contents of this room are being "
1656                         "mailed <b>as individual messages</b> "
1657                         "to the following list recipients:"
1658                         "</i><br /><br />\n"));
1659
1660                 serv_puts("GNET");
1661                 serv_getln(buf, sizeof buf);
1662                 if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1663                         extract_token(cmd, buf, 0, '|', sizeof cmd);
1664                         if (!strcasecmp(cmd, "listrecp")) {
1665                                 extract_token(recp, buf, 1, '|', sizeof recp);
1666                         
1667                                 escputs(recp);
1668                                 wprintf(" <a href=\"netedit&cmd=remove&tab=listserv&line=listrecp|");
1669                                 urlescputs(recp);
1670                                 wprintf("\">");
1671                                 wprintf(_("(remove)"));
1672                                 wprintf("</A><br />");
1673                         }
1674                 }
1675                 wprintf("<br /><form method=\"POST\" action=\"netedit\">\n"
1676                         "<input type=\"hidden\" NAME=\"tab\" VALUE=\"listserv\">\n"
1677                         "<input type=\"hidden\" NAME=\"prefix\" VALUE=\"listrecp|\">\n");
1678                 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
1679                 wprintf("<input type=\"text\" id=\"add_as_listrecp\" NAME=\"line\">\n");
1680                 wprintf("<input type=\"submit\" NAME=\"add_button\" VALUE=\"%s\">", _("Add"));
1681                 wprintf("</form>\n");
1682
1683                 wprintf("</td><td VALIGN=TOP>\n");
1684                 
1685                 wprintf(_("<i>The contents of this room are being "
1686                         "mailed <b>in digest form</b> "
1687                         "to the following list recipients:"
1688                         "</i><br /><br />\n"));
1689
1690                 serv_puts("GNET");
1691                 serv_getln(buf, sizeof buf);
1692                 if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1693                         extract_token(cmd, buf, 0, '|', sizeof cmd);
1694                         if (!strcasecmp(cmd, "digestrecp")) {
1695                                 extract_token(recp, buf, 1, '|', sizeof recp);
1696                         
1697                                 escputs(recp);
1698                                 wprintf(" <a href=\"netedit&cmd=remove&tab=listserv&line="
1699                                         "digestrecp|");
1700                                 urlescputs(recp);
1701                                 wprintf("\">");
1702                                 wprintf(_("(remove)"));
1703                                 wprintf("</A><br />");
1704                         }
1705                 }
1706                 wprintf("<br /><form method=\"POST\" action=\"netedit\">\n"
1707                         "<input type=\"hidden\" NAME=\"tab\" VALUE=\"listserv\">\n"
1708                         "<input type=\"hidden\" NAME=\"prefix\" VALUE=\"digestrecp|\">\n");
1709                 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
1710                 wprintf("<input type=\"text\" id=\"add_as_digestrecp\" NAME=\"line\">\n");
1711                 wprintf("<input type=\"submit\" NAME=\"add_button\" VALUE=\"%s\">", _("Add"));
1712                 wprintf("</form>\n");
1713                 
1714                 wprintf("</td></tr></table>\n");
1715
1716                 /** Pop open an address book -- begin **/
1717                 wprintf("<div align=right>"
1718                         "<a href=\"javascript:PopOpenAddressBook('add_as_listrecp|%s|add_as_digestrecp|%s');\" "
1719                         "title=\"%s\">"
1720                         "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
1721                         "&nbsp;%s</a>"
1722                         "</div>",
1723                         _("List"),
1724                         _("Digest"),
1725                         _("Add recipients from Contacts or other address books"),
1726                         _("Add recipients from Contacts or other address books")
1727                 );
1728                 /* Pop open an address book -- end **/
1729
1730                 wprintf("<br />\n<form method=\"GET\" action=\"toggle_self_service\">\n");
1731
1732                 get_roomflags (&RoomFlags);
1733                 
1734                 /* Self Service subscription? */
1735                 wprintf("<table><tr><td>\n");
1736                 wprintf(_("Allow self-service subscribe/unsubscribe requests."));
1737                 wprintf("</td><td><input type=\"checkbox\" name=\"QR2_SelfList\" value=\"yes\" %s></td></tr>\n"
1738                         " <tr><td colspan=\"2\">\n",
1739                         (is_selflist(&RoomFlags))?"checked":"");
1740                 wprintf(_("The URL for subscribe/unsubscribe is: "));
1741                 wprintf("<TT>%s://%s/listsub</TT></td></tr>\n",
1742                         (is_https ? "https" : "http"),
1743                         WC->http_host);
1744                 /* Public posting? */
1745                 wprintf("<tr><td>");
1746                 wprintf(_("Allow non-subscribers to mail to this room."));
1747                 wprintf("</td><td><input type=\"checkbox\" name=\"QR2_SubsOnly\" value=\"yes\" %s></td></tr>\n",
1748                         (is_publiclist(&RoomFlags))?"checked":"");
1749                 
1750                 /* Moderated List? */
1751                 wprintf("<tr><td>");
1752                 wprintf(_("Room post publication needs Aide permission."));
1753                 wprintf("</td><td><input type=\"checkbox\" name=\"QR2_Moderated\" value=\"yes\" %s></td></tr>\n",
1754                         (is_moderatedlist(&RoomFlags))?"checked":"");
1755
1756
1757                 wprintf("<tr><td colspan=\"2\" align=\"center\">"
1758                         "<input type=\"submit\" NAME=\"add_button\" VALUE=\"%s\"></td></tr>", _("Save changes"));
1759                 wprintf("</table></form>");
1760                         
1761
1762                 wprintf("</CENTER>\n");
1763                 wprintf("</div>");
1764         }
1765
1766
1767         /* Configuration of The Dreaded Auto-Purger */
1768         if (!strcmp(tab, "expire")) {
1769                 wprintf("<div class=\"tabcontent\">");
1770
1771                 serv_puts("GPEX room");
1772                 serv_getln(buf, sizeof buf);
1773                 if (!strncmp(buf, "550", 3)) {
1774                         wprintf("<br><br><div align=center>%s</div><br><br>\n",
1775                                 _("Higher access is required to access this function.")
1776                         );
1777                 }
1778                 else if (buf[0] != '2') {
1779                         wprintf("<br><br><div align=center>%s</div><br><br>\n", &buf[4]);
1780                 }
1781                 else {
1782                         roompolicy = extract_int(&buf[4], 0);
1783                         roomvalue = extract_int(&buf[4], 1);
1784                 
1785                         serv_puts("GPEX floor");
1786                         serv_getln(buf, sizeof buf);
1787                         if (buf[0] == '2') {
1788                                 floorpolicy = extract_int(&buf[4], 0);
1789                                 floorvalue = extract_int(&buf[4], 1);
1790                         }
1791                         
1792                         wprintf("<br /><form method=\"POST\" action=\"set_room_policy\">\n");
1793                         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
1794                         wprintf("<table border=0 cellspacing=5>\n");
1795                         wprintf("<tr><td>");
1796                         wprintf(_("Message expire policy for this room"));
1797                         wprintf("<br />(");
1798                         escputs(WC->wc_roomname);
1799                         wprintf(")</td><td>");
1800                         wprintf("<input type=\"radio\" NAME=\"roompolicy\" VALUE=\"0\" %s>",
1801                                 ((roompolicy == 0) ? "CHECKED" : "") );
1802                         wprintf(_("Use the default policy for this floor"));
1803                         wprintf("<br />\n");
1804                         wprintf("<input type=\"radio\" NAME=\"roompolicy\" VALUE=\"1\" %s>",
1805                                 ((roompolicy == 1) ? "CHECKED" : "") );
1806                         wprintf(_("Never automatically expire messages"));
1807                         wprintf("<br />\n");
1808                         wprintf("<input type=\"radio\" NAME=\"roompolicy\" VALUE=\"2\" %s>",
1809                                 ((roompolicy == 2) ? "CHECKED" : "") );
1810                         wprintf(_("Expire by message count"));
1811                         wprintf("<br />\n");
1812                         wprintf("<input type=\"radio\" NAME=\"roompolicy\" VALUE=\"3\" %s>",
1813                                 ((roompolicy == 3) ? "CHECKED" : "") );
1814                         wprintf(_("Expire by message age"));
1815                         wprintf("<br />");
1816                         wprintf(_("Number of messages or days: "));
1817                         wprintf("<input type=\"text\" NAME=\"roomvalue\" MAXLENGTH=\"5\" VALUE=\"%d\">", roomvalue);
1818                         wprintf("</td></tr>\n");
1819         
1820                         if (WC->axlevel >= 6) {
1821                                 wprintf("<tr><td COLSPAN=2><hr /></td></tr>\n");
1822                                 wprintf("<tr><td>");
1823                                 wprintf(_("Message expire policy for this floor"));
1824                                 wprintf("<br />(");
1825                                 escputs(floorlist[WC->wc_floor]);
1826                                 wprintf(")</td><td>");
1827                                 wprintf("<input type=\"radio\" NAME=\"floorpolicy\" VALUE=\"0\" %s>",
1828                                         ((floorpolicy == 0) ? "CHECKED" : "") );
1829                                 wprintf(_("Use the system default"));
1830                                 wprintf("<br />\n");
1831                                 wprintf("<input type=\"radio\" NAME=\"floorpolicy\" VALUE=\"1\" %s>",
1832                                         ((floorpolicy == 1) ? "CHECKED" : "") );
1833                                 wprintf(_("Never automatically expire messages"));
1834                                 wprintf("<br />\n");
1835                                 wprintf("<input type=\"radio\" NAME=\"floorpolicy\" VALUE=\"2\" %s>",
1836                                         ((floorpolicy == 2) ? "CHECKED" : "") );
1837                                 wprintf(_("Expire by message count"));
1838                                 wprintf("<br />\n");
1839                                 wprintf("<input type=\"radio\" NAME=\"floorpolicy\" VALUE=\"3\" %s>",
1840                                         ((floorpolicy == 3) ? "CHECKED" : "") );
1841                                 wprintf(_("Expire by message age"));
1842                                 wprintf("<br />");
1843                                 wprintf(_("Number of messages or days: "));
1844                                 wprintf("<input type=\"text\" NAME=\"floorvalue\" MAXLENGTH=\"5\" VALUE=\"%d\">",
1845                                         floorvalue);
1846                         }
1847         
1848                         wprintf("<CENTER>\n");
1849                         wprintf("<tr><td COLSPAN=2><hr /><CENTER>\n");
1850                         wprintf("<input type=\"submit\" NAME=\"ok_button\" VALUE=\"%s\">", _("Save changes"));
1851                         wprintf("&nbsp;");
1852                         wprintf("<input type=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
1853                         wprintf("</CENTER></td><tr>\n");
1854         
1855                         wprintf("</table>\n"
1856                                 "<input type=\"hidden\" NAME=\"tab\" VALUE=\"expire\">\n"
1857                                 "</form>\n"
1858                         );
1859                 }
1860
1861                 wprintf("</div>");
1862         }
1863
1864         /* Access controls */
1865         if (!strcmp(tab, "access")) {
1866                 wprintf("<div class=\"tabcontent\">");
1867                 display_whok();
1868                 wprintf("</div>");
1869         }
1870
1871         /* Fetch messages from remote locations */
1872         if (!strcmp(tab, "feeds")) {
1873                 wprintf("<div class=\"tabcontent\">");
1874
1875                 wprintf("<i>");
1876                 wprintf(_("Retrieve messages from these remote POP3 accounts and store them in this room:"));
1877                 wprintf("</i><br />\n");
1878
1879                 wprintf("<table class=\"altern\" border=0 cellpadding=5>"
1880                         "<tr class=\"even\"><th>");
1881                 wprintf(_("Remote host"));
1882                 wprintf("</th><th>");
1883                 wprintf(_("User name"));
1884                 wprintf("</th><th>");
1885                 wprintf(_("Password"));
1886                 wprintf("</th><th>");
1887                 wprintf(_("Keep messages on server?"));
1888                 wprintf("</th><th> </th></tr>");
1889
1890                 serv_puts("GNET");
1891                 serv_getln(buf, sizeof buf);
1892                 bg = 1;
1893                 if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1894                         extract_token(cmd, buf, 0, '|', sizeof cmd);
1895                         if (!strcasecmp(cmd, "pop3client")) {
1896                                 safestrncpy(recp, &buf[11], sizeof recp);
1897
1898                                 bg = 1 - bg;
1899                                 wprintf("<tr class=\"%s\">",
1900                                         (bg ? "even" : "odd")
1901                                 );
1902
1903                                 wprintf("<td>");
1904                                 extract_token(pop3_host, buf, 1, '|', sizeof pop3_host);
1905                                 escputs(pop3_host);
1906                                 wprintf("</td>");
1907
1908                                 wprintf("<td>");
1909                                 extract_token(pop3_user, buf, 2, '|', sizeof pop3_user);
1910                                 escputs(pop3_user);
1911                                 wprintf("</td>");
1912
1913                                 wprintf("<td>*****</td>");              /* Don't show the password */
1914
1915                                 wprintf("<td>%s</td>", extract_int(buf, 4) ? _("Yes") : _("No"));
1916
1917                                 wprintf("<td class=\"button_link\">");
1918                                 wprintf(" <a href=\"netedit&cmd=remove&tab=feeds&line=pop3client|");
1919                                 urlescputs(recp);
1920                                 wprintf("\">");
1921                                 wprintf(_("(remove)"));
1922                                 wprintf("</a></td>");
1923                         
1924                                 wprintf("</tr>");
1925                         }
1926                 }
1927
1928                 wprintf("<form method=\"POST\" action=\"netedit\">\n"
1929                         "<tr>"
1930                         "<input type=\"hidden\" name=\"tab\" value=\"feeds\">"
1931                         "<input type=\"hidden\" name=\"prefix\" value=\"pop3client|\">\n");
1932                 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
1933                 wprintf("<td>");
1934                 wprintf("<input type=\"text\" id=\"add_as_pop3host\" NAME=\"line_pop3host\">\n");
1935                 wprintf("</td>");
1936                 wprintf("<td>");
1937                 wprintf("<input type=\"text\" id=\"add_as_pop3user\" NAME=\"line_pop3user\">\n");
1938                 wprintf("</td>");
1939                 wprintf("<td>");
1940                 wprintf("<input type=\"password\" id=\"add_as_pop3pass\" NAME=\"line_pop3pass\">\n");
1941                 wprintf("</td>");
1942                 wprintf("<td>");
1943                 wprintf("<input type=\"checkbox\" id=\"add_as_pop3keep\" NAME=\"line_pop3keep\" VALUE=\"1\">");
1944                 wprintf("</td>");
1945                 wprintf("<td>");
1946                 wprintf("<input type=\"submit\" NAME=\"add_button\" VALUE=\"%s\">", _("Add"));
1947                 wprintf("</td></tr>");
1948                 wprintf("</form></table>\n");
1949
1950                 wprintf("<hr>\n");
1951
1952                 wprintf("<i>");
1953                 wprintf(_("Fetch the following RSS feeds and store them in this room:"));
1954                 wprintf("</i><br />\n");
1955
1956                 wprintf("<table class=\"altern\" border=0 cellpadding=5>"
1957                         "<tr class=\"even\"><th>");
1958                 wprintf("<img src=\"static/rss_16x.png\" width=\"16\" height=\"16\" alt=\" \"> ");
1959                 wprintf(_("Feed URL"));
1960                 wprintf("</th><th>");
1961                 wprintf("</th></tr>");
1962
1963                 serv_puts("GNET");
1964                 serv_getln(buf, sizeof buf);
1965                 bg = 1;
1966                 if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1967                         extract_token(cmd, buf, 0, '|', sizeof cmd);
1968                         if (!strcasecmp(cmd, "rssclient")) {
1969                                 safestrncpy(recp, &buf[10], sizeof recp);
1970
1971                                 bg = 1 - bg;
1972                                 wprintf("<tr class=\"%s\">",
1973                                         (bg ? "even" : "odd")
1974                                 );
1975
1976                                 wprintf("<td>");
1977                                 extract_token(pop3_host, buf, 1, '|', sizeof pop3_host);
1978                                 escputs(pop3_host);
1979                                 wprintf("</td>");
1980
1981                                 wprintf("<td class=\"button_link\">");
1982                                 wprintf(" <a href=\"netedit&cmd=remove&tab=feeds&line=rssclient|");
1983                                 urlescputs(recp);
1984                                 wprintf("\">");
1985                                 wprintf(_("(remove)"));
1986                                 wprintf("</a></td>");
1987                         
1988                                 wprintf("</tr>");
1989                         }
1990                 }
1991
1992                 wprintf("<form method=\"POST\" action=\"netedit\">\n"
1993                         "<tr>"
1994                         "<input type=\"hidden\" name=\"tab\" value=\"feeds\">"
1995                         "<input type=\"hidden\" name=\"prefix\" value=\"rssclient|\">\n");
1996                 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
1997                 wprintf("<td>");
1998                 wprintf("<input type=\"text\" id=\"add_as_pop3host\" size=\"72\" "
1999                         "maxlength=\"256\" name=\"line_pop3host\">\n");
2000                 wprintf("</td>");
2001                 wprintf("<td>");
2002                 wprintf("<input type=\"submit\" name=\"add_button\" value=\"%s\">", _("Add"));
2003                 wprintf("</td></tr>");
2004                 wprintf("</form></table>\n");
2005
2006                 wprintf("</div>");
2007         }
2008
2009
2010         /* end content of whatever tab is open now */
2011         wprintf("</div>\n");
2012
2013         address_book_popup();
2014         wDumpContent(1);
2015 }
2016
2017
2018 /* 
2019  * Toggle self-service list subscription
2020  */
2021 void toggle_self_service(void) {
2022         room_states RoomFlags;
2023
2024         get_roomflags (&RoomFlags);
2025
2026         /* Yank out the bits we want to change */
2027         RoomFlags.flags2 = RoomFlags.flags2 &
2028                 !(QR2_SELFLIST|QR2_SMTP_PUBLIC|QR2_MODERATED);
2029
2030         if (!strcasecmp(bstr("QR2_SelfList"), "yes")) 
2031                 RoomFlags.flags2 = RoomFlags.flags2 | QR2_SELFLIST;
2032         if (!strcasecmp(bstr("QR2_SMTP_PUBLIC"), "yes")) 
2033                 RoomFlags.flags2 = RoomFlags.flags2 | QR2_SMTP_PUBLIC;
2034         if (!strcasecmp(bstr("QR2_Moderated"), "yes")) 
2035                 RoomFlags.flags2 = RoomFlags.flags2 | QR2_MODERATED;
2036
2037         set_roomflags (&RoomFlags);
2038         
2039         display_editroom();
2040 }
2041
2042
2043
2044 /*
2045  * save new parameters for a room
2046  */
2047 void editroom(void)
2048 {
2049         char buf[SIZ];
2050         char er_name[128];
2051         char er_password[10];
2052         char er_dirname[15];
2053         char er_roomaide[26];
2054         int er_floor;
2055         unsigned er_flags;
2056         int er_listingorder;
2057         int er_defaultview;
2058         unsigned er_flags2;
2059         int bump;
2060
2061
2062         if (IsEmptyStr(bstr("ok_button"))) {
2063                 strcpy(WC->ImportantMessage,
2064                         _("Cancelled.  Changes were not saved."));
2065                 display_editroom();
2066                 return;
2067         }
2068         serv_puts("GETR");
2069         serv_getln(buf, sizeof buf);
2070
2071         if (buf[0] != '2') {
2072                 strcpy(WC->ImportantMessage, &buf[4]);
2073                 display_editroom();
2074                 return;
2075         }
2076         extract_token(er_name, &buf[4], 0, '|', sizeof er_name);
2077         extract_token(er_password, &buf[4], 1, '|', sizeof er_password);
2078         extract_token(er_dirname, &buf[4], 2, '|', sizeof er_dirname);
2079         er_flags = extract_int(&buf[4], 3);
2080         er_listingorder = extract_int(&buf[4], 5);
2081         er_defaultview = extract_int(&buf[4], 6);
2082         er_flags2 = extract_int(&buf[4], 7);
2083
2084         strcpy(er_roomaide, bstr("er_roomaide"));
2085         if (IsEmptyStr(er_roomaide)) {
2086                 serv_puts("GETA");
2087                 serv_getln(buf, sizeof buf);
2088                 if (buf[0] != '2') {
2089                         strcpy(er_roomaide, "");
2090                 } else {
2091                         extract_token(er_roomaide, &buf[4], 0, '|', sizeof er_roomaide);
2092                 }
2093         }
2094         strcpy(buf, bstr("er_name"));
2095         buf[128] = 0;
2096         if (!IsEmptyStr(buf)) {
2097                 strcpy(er_name, buf);
2098         }
2099
2100         strcpy(buf, bstr("er_password"));
2101         buf[10] = 0;
2102         if (!IsEmptyStr(buf))
2103                 strcpy(er_password, buf);
2104
2105         strcpy(buf, bstr("er_dirname"));
2106         buf[15] = 0;
2107         if (!IsEmptyStr(buf))
2108                 strcpy(er_dirname, buf);
2109
2110         strcpy(buf, bstr("type"));
2111         er_flags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
2112
2113         if (!strcmp(buf, "invonly")) {
2114                 er_flags |= (QR_PRIVATE);
2115         }
2116         if (!strcmp(buf, "hidden")) {
2117                 er_flags |= (QR_PRIVATE | QR_GUESSNAME);
2118         }
2119         if (!strcmp(buf, "passworded")) {
2120                 er_flags |= (QR_PRIVATE | QR_PASSWORDED);
2121         }
2122         if (!strcmp(buf, "personal")) {
2123                 er_flags |= QR_MAILBOX;
2124         } else {
2125                 er_flags &= ~QR_MAILBOX;
2126         }
2127         
2128         if (!strcmp(bstr("prefonly"), "yes")) {
2129                 er_flags |= QR_PREFONLY;
2130         } else {
2131                 er_flags &= ~QR_PREFONLY;
2132         }
2133
2134         if (!strcmp(bstr("readonly"), "yes")) {
2135                 er_flags |= QR_READONLY;
2136         } else {
2137                 er_flags &= ~QR_READONLY;
2138         }
2139
2140         
2141         if (!strcmp(bstr("collabdel"), "yes")) {
2142                 er_flags2 |= QR2_COLLABDEL;
2143         } else {
2144                 er_flags2 &= ~QR2_COLLABDEL;
2145         }
2146
2147         if (!strcmp(bstr("permanent"), "yes")) {
2148                 er_flags |= QR_PERMANENT;
2149         } else {
2150                 er_flags &= ~QR_PERMANENT;
2151         }
2152
2153         if (!strcmp(bstr("subjectreq"), "yes")) {
2154                 er_flags2 |= QR2_SUBJECTREQ;
2155         } else {
2156                 er_flags2 &= ~QR2_SUBJECTREQ;
2157         }
2158
2159         if (!strcmp(bstr("network"), "yes")) {
2160                 er_flags |= QR_NETWORK;
2161         } else {
2162                 er_flags &= ~QR_NETWORK;
2163         }
2164
2165         if (!strcmp(bstr("directory"), "yes")) {
2166                 er_flags |= QR_DIRECTORY;
2167         } else {
2168                 er_flags &= ~QR_DIRECTORY;
2169         }
2170
2171         if (!strcmp(bstr("ulallowed"), "yes")) {
2172                 er_flags |= QR_UPLOAD;
2173         } else {
2174                 er_flags &= ~QR_UPLOAD;
2175         }
2176
2177         if (!strcmp(bstr("dlallowed"), "yes")) {
2178                 er_flags |= QR_DOWNLOAD;
2179         } else {
2180                 er_flags &= ~QR_DOWNLOAD;
2181         }
2182
2183         if (!strcmp(bstr("visdir"), "yes")) {
2184                 er_flags |= QR_VISDIR;
2185         } else {
2186                 er_flags &= ~QR_VISDIR;
2187         }
2188
2189         strcpy(buf, bstr("anon"));
2190
2191         er_flags &= ~(QR_ANONONLY | QR_ANONOPT);
2192         if (!strcmp(buf, "anononly"))
2193                 er_flags |= QR_ANONONLY;
2194         if (!strcmp(buf, "anon2"))
2195                 er_flags |= QR_ANONOPT;
2196
2197         bump = 0;
2198         if (!strcmp(bstr("bump"), "yes"))
2199                 bump = 1;
2200
2201         er_floor = atoi(bstr("er_floor"));
2202
2203         sprintf(buf, "SETR %s|%s|%s|%u|%d|%d|%d|%d|%u",
2204                 er_name, er_password, er_dirname, er_flags, bump, er_floor,
2205                 er_listingorder, er_defaultview, er_flags2);
2206         serv_puts(buf);
2207         serv_getln(buf, sizeof buf);
2208         if (buf[0] != '2') {
2209                 strcpy(WC->ImportantMessage, &buf[4]);
2210                 display_editroom();
2211                 return;
2212         }
2213         gotoroom(er_name);
2214
2215         if (!IsEmptyStr(er_roomaide)) {
2216                 sprintf(buf, "SETA %s", er_roomaide);
2217                 serv_puts(buf);
2218                 serv_getln(buf, sizeof buf);
2219                 if (buf[0] != '2') {
2220                         strcpy(WC->ImportantMessage, &buf[4]);
2221                         display_main_menu();
2222                         return;
2223                 }
2224         }
2225         gotoroom(er_name);
2226         strcpy(WC->ImportantMessage, _("Your changes have been saved."));
2227         display_editroom();
2228         return;
2229 }
2230
2231
2232 /*
2233  * Display form for Invite, Kick, and show Who Knows a room
2234  */
2235 void do_invt_kick(void) {
2236         char buf[SIZ], room[SIZ], username[SIZ];
2237
2238         serv_puts("GETR");
2239         serv_getln(buf, sizeof buf);
2240
2241         if (buf[0] != '2') {
2242                 escputs(&buf[4]);
2243                 return;
2244         }
2245         extract_token(room, &buf[4], 0, '|', sizeof room);
2246
2247         strcpy(username, bstr("username"));
2248
2249         if (!IsEmptyStr(bstr("kick_button"))) {
2250                 sprintf(buf, "KICK %s", username);
2251                 serv_puts(buf);
2252                 serv_getln(buf, sizeof buf);
2253
2254                 if (buf[0] != '2') {
2255                         strcpy(WC->ImportantMessage, &buf[4]);
2256                 } else {
2257                         sprintf(WC->ImportantMessage,
2258                                 _("<B><I>User %s kicked out of room %s.</I></B>\n"), 
2259                                 username, room);
2260                 }
2261         }
2262
2263         if (!IsEmptyStr(bstr("invite_button"))) {
2264                 sprintf(buf, "INVT %s", username);
2265                 serv_puts(buf);
2266                 serv_getln(buf, sizeof buf);
2267
2268                 if (buf[0] != '2') {
2269                         strcpy(WC->ImportantMessage, &buf[4]);
2270                 } else {
2271                         sprintf(WC->ImportantMessage,
2272                                 _("<B><I>User %s invited to room %s.</I></B>\n"), 
2273                                 username, room);
2274                 }
2275         }
2276
2277         display_editroom();
2278 }
2279
2280
2281
2282 /*
2283  * Display form for Invite, Kick, and show Who Knows a room
2284  */
2285 void display_whok(void)
2286 {
2287         char buf[SIZ], room[SIZ], username[SIZ];
2288
2289         serv_puts("GETR");
2290         serv_getln(buf, sizeof buf);
2291
2292         if (buf[0] != '2') {
2293                 escputs(&buf[4]);
2294                 return;
2295         }
2296         extract_token(room, &buf[4], 0, '|', sizeof room);
2297
2298         
2299         wprintf("<table border=0 CELLSPACING=10><tr VALIGN=TOP><td>");
2300         wprintf(_("The users listed below have access to this room.  "
2301                 "To remove a user from the access list, select the user "
2302                 "name from the list and click 'Kick'."));
2303         wprintf("<br /><br />");
2304         
2305         wprintf("<CENTER><form method=\"POST\" action=\"do_invt_kick\">\n");
2306         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
2307         wprintf("<input type=\"hidden\" NAME=\"tab\" VALUE=\"access\">\n");
2308         wprintf("<select NAME=\"username\" SIZE=\"10\" style=\"width:100%%\">\n");
2309         serv_puts("WHOK");
2310         serv_getln(buf, sizeof buf);
2311         if (buf[0] == '1') {
2312                 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2313                         extract_token(username, buf, 0, '|', sizeof username);
2314                         wprintf("<OPTION>");
2315                         escputs(username);
2316                         wprintf("\n");
2317                 }
2318         }
2319         wprintf("</select><br />\n");
2320
2321         wprintf("<input type=\"submit\" name=\"kick_button\" value=\"%s\">", _("Kick"));
2322         wprintf("</form></CENTER>\n");
2323
2324         wprintf("</td><td>");
2325         wprintf(_("To grant another user access to this room, enter the "
2326                 "user name in the box below and click 'Invite'."));
2327         wprintf("<br /><br />");
2328
2329         wprintf("<CENTER><form method=\"POST\" action=\"do_invt_kick\">\n");
2330         wprintf("<input type=\"hidden\" NAME=\"tab\" VALUE=\"access\">\n");
2331         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
2332         wprintf(_("Invite:"));
2333         wprintf(" ");
2334         wprintf("<input type=\"text\" name=\"username\" id=\"username_id\" style=\"width:100%%\"><br />\n"
2335                 "<input type=\"hidden\" name=\"invite_button\" value=\"Invite\">"
2336                 "<input type=\"submit\" value=\"%s\">"
2337                 "</form></CENTER>\n", _("Invite"));
2338                 /* Pop open an address book -- begin **/
2339                 wprintf(
2340                         "<a href=\"javascript:PopOpenAddressBook('username_id|%s');\" "
2341                         "title=\"%s\">"
2342                         "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
2343                         "&nbsp;%s</a>",
2344                         _("User"), 
2345                         _("Users"), _("Users")
2346                 );
2347                 /* Pop open an address book -- end **/
2348
2349         wprintf("</td></tr></table>\n");
2350         address_book_popup();
2351         wDumpContent(1);
2352 }
2353
2354
2355
2356 /*
2357  * display the form for entering a new room
2358  */
2359 void display_entroom(void)
2360 {
2361         int i;
2362         char buf[SIZ];
2363
2364         serv_puts("CRE8 0");
2365         serv_getln(buf, sizeof buf);
2366
2367         if (buf[0] != '2') {
2368                 strcpy(WC->ImportantMessage, &buf[4]);
2369                 display_main_menu();
2370                 return;
2371         }
2372
2373         output_headers(1, 1, 1, 0, 0, 0);
2374
2375         svprintf("BOXTITLE", WCS_STRING, _("Create a new room"));
2376         do_template("beginbox");
2377
2378         wprintf("<form name=\"create_room_form\" method=\"POST\" action=\"entroom\">\n");
2379         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
2380
2381         wprintf("<table class=\"altern\"> ");
2382
2383         wprintf("<tr class=\"even\"><td>");
2384         wprintf(_("Name of room: "));
2385         wprintf("</td><td>");
2386         wprintf("<input type=\"text\" NAME=\"er_name\" MAXLENGTH=\"127\">\n");
2387         wprintf("</td></tr>");
2388
2389         wprintf("<tr class=\"odd\"><td>");
2390         wprintf(_("Resides on floor: "));
2391         wprintf("</td><td>");
2392         load_floorlist(); 
2393         wprintf("<select name=\"er_floor\" size=\"1\">\n");
2394         for (i = 0; i < 128; ++i)
2395                 if (!IsEmptyStr(floorlist[i])) {
2396                         wprintf("<option ");
2397                         wprintf("value=\"%d\">", i);
2398                         escputs(floorlist[i]);
2399                         wprintf("</option>\n");
2400                 }
2401         wprintf("</select>\n");
2402         wprintf("</td></tr>");
2403
2404                 /*
2405                  * Our clever little snippet of JavaScript automatically selects
2406                  * a public room if the view is set to Bulletin Board or wiki, and
2407                  * it selects a mailbox room otherwise.  The user can override this,
2408                  * of course.  We also disable the floor selector for mailboxes.
2409                  */
2410         wprintf("<tr class=\"even\"><td>");
2411         wprintf(_("Default view for room: "));
2412         wprintf("</td><td>");
2413         wprintf("<select name=\"er_view\" size=\"1\" OnChange=\""
2414                 "       if ( (this.form.er_view.value == 0)             "
2415                 "          || (this.form.er_view.value == 6) ) {        "
2416                 "               this.form.type[0].checked=true;         "
2417                 "               this.form.er_floor.disabled = false;    "
2418                 "       }                                               "
2419                 "       else {                                          "
2420                 "               this.form.type[4].checked=true;         "
2421                 "               this.form.er_floor.disabled = true;     "
2422                 "       }                                               "
2423                 "\">\n");
2424         for (i=0; i<(sizeof viewdefs / sizeof (char *)); ++i) {
2425                 if (is_view_allowed_as_default(i)) {
2426                         wprintf("<option %s value=\"%d\">",
2427                                 ((i == 0) ? "selected" : ""), i );
2428                         escputs(viewdefs[i]);
2429                         wprintf("</option>\n");
2430                 }
2431         }
2432         wprintf("</select>\n");
2433         wprintf("</td></tr>");
2434
2435         wprintf("<tr class=\"even\"><td>");
2436         wprintf(_("Type of room:"));
2437         wprintf("</td><td>");
2438         wprintf("<ul class=\"adminlist\">\n");
2439
2440         wprintf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"public\" ");
2441         wprintf("CHECKED OnChange=\""
2442                 "       if (this.form.type[0].checked == true) {        "
2443                 "               this.form.er_floor.disabled = false;    "
2444                 "       }                                               "
2445                 "\"> ");
2446         wprintf(_("Public (automatically appears to everyone)"));
2447         wprintf("</li>");
2448
2449         wprintf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"hidden\" OnChange=\""
2450                 "       if (this.form.type[1].checked == true) {        "
2451                 "               this.form.er_floor.disabled = false;    "
2452                 "       }                                               "
2453                 "\"> ");
2454         wprintf(_("Private - hidden (accessible to anyone who knows its name)"));
2455         wprintf("</li>");
2456
2457         wprintf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"passworded\" OnChange=\""
2458                 "       if (this.form.type[2].checked == true) {        "
2459                 "               this.form.er_floor.disabled = false;    "
2460                 "       }                                               "
2461                 "\"> ");
2462         wprintf(_("Private - require password: "));
2463         wprintf("<input type=\"text\" NAME=\"er_password\" MAXLENGTH=\"9\">\n");
2464         wprintf("</li>");
2465
2466         wprintf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"invonly\" OnChange=\""
2467                 "       if (this.form.type[3].checked == true) {        "
2468                 "               this.form.er_floor.disabled = false;    "
2469                 "       }                                               "
2470                 "\"> ");
2471         wprintf(_("Private - invitation only"));
2472         wprintf("</li>");
2473
2474         wprintf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"personal\" "
2475                 "OnChange=\""
2476                 "       if (this.form.type[4].checked == true) {        "
2477                 "               this.form.er_floor.disabled = true;     "
2478                 "       }                                               "
2479                 "\"> ");
2480         wprintf(_("Personal (mailbox for you only)"));
2481         wprintf("</li>");
2482
2483         wprintf("\n</ul>\n");
2484         wprintf("</td></tr></table>\n");
2485
2486         wprintf("<div class=\"buttons\">\n");
2487         wprintf("<input type=\"submit\" name=\"ok_button\" value=\"%s\">", _("Create new room"));
2488         wprintf("&nbsp;");
2489         wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">", _("Cancel"));
2490         wprintf("</div>\n");
2491         wprintf("</form>\n<hr />");
2492         serv_printf("MESG roomaccess");
2493         serv_getln(buf, sizeof buf);
2494         if (buf[0] == '1') {
2495                 fmout("LEFT");
2496         }
2497
2498         do_template("endbox");
2499
2500         wDumpContent(1);
2501 }
2502
2503
2504
2505
2506 /*
2507  * support function for entroom() -- sets the default view 
2508  */
2509 void er_set_default_view(int newview) {
2510
2511         char buf[SIZ];
2512
2513         char rm_name[SIZ];
2514         char rm_pass[SIZ];
2515         char rm_dir[SIZ];
2516         int rm_bits1;
2517         int rm_floor;
2518         int rm_listorder;
2519         int rm_bits2;
2520
2521         serv_puts("GETR");
2522         serv_getln(buf, sizeof buf);
2523         if (buf[0] != '2') return;
2524
2525         extract_token(rm_name, &buf[4], 0, '|', sizeof rm_name);
2526         extract_token(rm_pass, &buf[4], 1, '|', sizeof rm_pass);
2527         extract_token(rm_dir, &buf[4], 2, '|', sizeof rm_dir);
2528         rm_bits1 = extract_int(&buf[4], 3);
2529         rm_floor = extract_int(&buf[4], 4);
2530         rm_listorder = extract_int(&buf[4], 5);
2531         rm_bits2 = extract_int(&buf[4], 7);
2532
2533         serv_printf("SETR %s|%s|%s|%d|0|%d|%d|%d|%d",
2534                 rm_name, rm_pass, rm_dir, rm_bits1, rm_floor,
2535                 rm_listorder, newview, rm_bits2
2536         );
2537         serv_getln(buf, sizeof buf);
2538 }
2539
2540
2541
2542 /*
2543  * Create a new room
2544  */
2545 void entroom(void)
2546 {
2547         char buf[SIZ];
2548         char er_name[SIZ];
2549         char er_type[SIZ];
2550         char er_password[SIZ];
2551         int er_floor;
2552         int er_num_type;
2553         int er_view;
2554
2555         if (IsEmptyStr(bstr("ok_button"))) {
2556                 strcpy(WC->ImportantMessage,
2557                         _("Cancelled.  No new room was created."));
2558                 display_main_menu();
2559                 return;
2560         }
2561         strcpy(er_name, bstr("er_name"));
2562         strcpy(er_type, bstr("type"));
2563         strcpy(er_password, bstr("er_password"));
2564         er_floor = atoi(bstr("er_floor"));
2565         er_view = atoi(bstr("er_view"));
2566
2567         er_num_type = 0;
2568         if (!strcmp(er_type, "hidden"))
2569                 er_num_type = 1;
2570         if (!strcmp(er_type, "passworded"))
2571                 er_num_type = 2;
2572         if (!strcmp(er_type, "invonly"))
2573                 er_num_type = 3;
2574         if (!strcmp(er_type, "personal"))
2575                 er_num_type = 4;
2576
2577         sprintf(buf, "CRE8 1|%s|%d|%s|%d|%d|%d", 
2578                 er_name, er_num_type, er_password, er_floor, 0, er_view);
2579         serv_puts(buf);
2580         serv_getln(buf, sizeof buf);
2581         if (buf[0] != '2') {
2582                 strcpy(WC->ImportantMessage, &buf[4]);
2583                 display_main_menu();
2584                 return;
2585         }
2586         /** TODO: Room created, now udate the left hand icon bar for this user */
2587         burn_folder_cache(0);   /* burn the old folder cache */
2588         
2589         
2590         gotoroom(er_name);
2591         do_change_view(er_view);                /* Now go there */
2592 }
2593
2594
2595 /**
2596  * \brief display the screen to enter a private room
2597  */
2598 void display_private(char *rname, int req_pass)
2599 {
2600         output_headers(1, 1, 1, 0, 0, 0);
2601
2602         svprintf("BOXTITLE", WCS_STRING, _("Go to a hidden room"));
2603         do_template("beginbox");
2604
2605         wprintf("<p>");
2606         wprintf(_("If you know the name of a hidden (guess-name) or "
2607                 "passworded room, you can enter that room by typing "
2608                 "its name below.  Once you gain access to a private "
2609                 "room, it will appear in your regular room listings "
2610                 "so you don't have to keep returning here."));
2611         wprintf("</p>");
2612
2613         wprintf("<form method=\"post\" action=\"goto_private\">\n");
2614         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
2615
2616         wprintf("<table class=\"altern\"> "
2617                 "<tr class=\"even\"><td>");
2618         wprintf(_("Enter room name:"));
2619         wprintf("</td><td>"
2620                 "<input type=\"text\" name=\"gr_name\" "
2621                 "value=\"%s\" maxlength=\"128\">\n", rname);
2622
2623         if (req_pass) {
2624                 wprintf("</td></tr><tr class=\"odd\"><td>");
2625                 wprintf(_("Enter room password:"));
2626                 wprintf("</td><td>");
2627                 wprintf("<input type=\"password\" name=\"gr_pass\" maxlength=\"9\">\n");
2628         }
2629         wprintf("</td></tr></table>\n");
2630
2631         wprintf("<div class=\"buttons\">\n");
2632         wprintf("<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
2633                 "&nbsp;"
2634                 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">",
2635                 _("Go there"),
2636                 _("Cancel")
2637         );
2638         wprintf("</div></form>\n");
2639
2640         do_template("endbox");
2641
2642         wDumpContent(1);
2643 }
2644
2645 /**
2646  * \brief goto a private room
2647  */
2648 void goto_private(void)
2649 {
2650         char hold_rm[SIZ];
2651         char buf[SIZ];
2652
2653         if (IsEmptyStr(bstr("ok_button"))) {
2654                 display_main_menu();
2655                 return;
2656         }
2657         strcpy(hold_rm, WC->wc_roomname);
2658         strcpy(buf, "GOTO ");
2659         strcat(buf, bstr("gr_name"));
2660         strcat(buf, "|");
2661         strcat(buf, bstr("gr_pass"));
2662         serv_puts(buf);
2663         serv_getln(buf, sizeof buf);
2664
2665         if (buf[0] == '2') {
2666                 smart_goto(bstr("gr_name"));
2667                 return;
2668         }
2669         if (!strncmp(buf, "540", 3)) {
2670                 display_private(bstr("gr_name"), 1);
2671                 return;
2672         }
2673         output_headers(1, 1, 1, 0, 0, 0);
2674         wprintf("%s\n", &buf[4]);
2675         wDumpContent(1);
2676         return;
2677 }
2678
2679
2680 /**
2681  * \brief display the screen to zap a room
2682  */
2683 void display_zap(void)
2684 {
2685         output_headers(1, 1, 2, 0, 0, 0);
2686
2687         wprintf("<div id=\"banner\">\n");
2688         wprintf("<h1>");
2689         wprintf(_("Zap (forget/unsubscribe) the current room"));
2690         wprintf("</h1>\n");
2691         wprintf("</div>\n");
2692
2693         wprintf("<div id=\"content\" class=\"service\">\n");
2694
2695         wprintf(_("If you select this option, <em>%s</em> will "
2696                 "disappear from your room list.  Is this what you wish "
2697                 "to do?<br />\n"), WC->wc_roomname);
2698
2699         wprintf("<form method=\"POST\" action=\"zap\">\n");
2700         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
2701         wprintf("<input type=\"submit\" NAME=\"ok_button\" VALUE=\"%s\">", _("Zap this room"));
2702         wprintf("&nbsp;");
2703         wprintf("<input type=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
2704         wprintf("</form>\n");
2705         wDumpContent(1);
2706 }
2707
2708
2709 /**
2710  * \brief zap a room
2711  */
2712 void zap(void)
2713 {
2714         char buf[SIZ];
2715         char final_destination[SIZ];
2716
2717         /**
2718          * If the forget-room routine fails for any reason, we fall back
2719          * to the current room; otherwise, we go to the Lobby
2720          */
2721         strcpy(final_destination, WC->wc_roomname);
2722
2723         if (!IsEmptyStr(bstr("ok_button"))) {
2724                 serv_printf("GOTO %s", WC->wc_roomname);
2725                 serv_getln(buf, sizeof buf);
2726                 if (buf[0] == '2') {
2727                         serv_puts("FORG");
2728                         serv_getln(buf, sizeof buf);
2729                         if (buf[0] == '2') {
2730                                 strcpy(final_destination, "_BASEROOM_");
2731                         }
2732                 }
2733         }
2734         smart_goto(final_destination);
2735 }
2736
2737
2738
2739 /**
2740  * \brief Delete the current room
2741  */
2742 void delete_room(void)
2743 {
2744         char buf[SIZ];
2745
2746         
2747         serv_puts("KILL 1");
2748         serv_getln(buf, sizeof buf);
2749         burn_folder_cache(0);   /* Burn the cahce of known rooms to update the icon bar */
2750         if (buf[0] != '2') {
2751                 strcpy(WC->ImportantMessage, &buf[4]);
2752                 display_main_menu();
2753                 return;
2754         } else {
2755                 smart_goto("_BASEROOM_");
2756         }
2757 }
2758
2759
2760
2761 /**
2762  * \brief Perform changes to a room's network configuration
2763  */
2764 void netedit(void) {
2765         FILE *fp;
2766         char buf[SIZ];
2767         char line[SIZ];
2768         char cmpa0[SIZ];
2769         char cmpa1[SIZ];
2770         char cmpb0[SIZ];
2771         char cmpb1[SIZ];
2772         int i, num_addrs;
2773
2774         if (!IsEmptyStr(bstr("line_pop3host"))) {
2775                 strcpy(line, bstr("prefix"));
2776                 strcat(line, bstr("line_pop3host"));
2777                 strcat(line, "|");
2778                 strcat(line, bstr("line_pop3user"));
2779                 strcat(line, "|");
2780                 strcat(line, bstr("line_pop3pass"));
2781                 strcat(line, "|");
2782                 strcat(line, atoi(bstr("line_pop3keep")) ? "1" : "0" );
2783                 strcat(line, bstr("suffix"));
2784         }
2785         else if (!IsEmptyStr(bstr("line"))) {
2786                 strcpy(line, bstr("prefix"));
2787                 strcat(line, bstr("line"));
2788                 strcat(line, bstr("suffix"));
2789         }
2790         else {
2791                 display_editroom();
2792                 return;
2793         }
2794
2795
2796         fp = tmpfile();
2797         if (fp == NULL) {
2798                 display_editroom();
2799                 return;
2800         }
2801
2802         serv_puts("GNET");
2803         serv_getln(buf, sizeof buf);
2804         if (buf[0] != '1') {
2805                 fclose(fp);
2806                 display_editroom();
2807                 return;
2808         }
2809
2810         /** This loop works for add *or* remove.  Spiffy, eh? */
2811         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2812                 extract_token(cmpa0, buf, 0, '|', sizeof cmpa0);
2813                 extract_token(cmpa1, buf, 1, '|', sizeof cmpa1);
2814                 extract_token(cmpb0, line, 0, '|', sizeof cmpb0);
2815                 extract_token(cmpb1, line, 1, '|', sizeof cmpb1);
2816                 if ( (strcasecmp(cmpa0, cmpb0)) 
2817                    || (strcasecmp(cmpa1, cmpb1)) ) {
2818                         fprintf(fp, "%s\n", buf);
2819                 }
2820         }
2821
2822         rewind(fp);
2823         serv_puts("SNET");
2824         serv_getln(buf, sizeof buf);
2825         if (buf[0] != '4') {
2826                 fclose(fp);
2827                 display_editroom();
2828                 return;
2829         }
2830
2831         while (fgets(buf, sizeof buf, fp) != NULL) {
2832                 buf[strlen(buf)-1] = 0;
2833                 serv_puts(buf);
2834         }
2835
2836         if (!IsEmptyStr(bstr("add_button"))) {
2837                 num_addrs = num_tokens(bstr("line"), ',');
2838                 if (num_addrs < 2) {
2839                         /* just adding one node or address */
2840                         serv_puts(line);
2841                 }
2842                 else {
2843                         /* adding multiple addresses separated by commas */
2844                         for (i=0; i<num_addrs; ++i) {
2845                                 strcpy(line, bstr("prefix"));
2846                                 extract_token(buf, bstr("line"), i, ',', sizeof buf);
2847                                 striplt(buf);
2848                                 strcat(line, buf);
2849                                 strcat(line, bstr("suffix"));
2850                                 serv_puts(line);
2851                         }
2852                 }
2853         }
2854
2855         serv_puts("000");
2856         fclose(fp);
2857         display_editroom();
2858 }
2859
2860
2861
2862 /**
2863  * \brief Convert a room name to a folder-ish-looking name.
2864  * \param folder the folderish name
2865  * \param room the room name
2866  * \param floor the floor name
2867  * \param is_mailbox is it a mailbox?
2868  */
2869 void room_to_folder(char *folder, char *room, int floor, int is_mailbox)
2870 {
2871         int i, len;
2872
2873         /**
2874          * For mailboxes, just do it straight...
2875          */
2876         if (is_mailbox) {
2877                 sprintf(folder, "My folders|%s", room);
2878         }
2879
2880         /**
2881          * Otherwise, prefix the floor name as a "public folders" moniker
2882          */
2883         else {
2884                 if (floor > MAX_FLOORS) {
2885                         wc_backtrace ();
2886                         sprintf(folder, "%%%%%%|%s", room);
2887                 }
2888                 else {
2889                         sprintf(folder, "%s|%s", floorlist[floor], room);
2890                 }
2891         }
2892
2893         /**
2894          * Replace "\" characters with "|" for pseudo-folder-delimiting
2895          */
2896         len = strlen (folder);
2897         for (i=0; i<len; ++i) {
2898                 if (folder[i] == '\\') folder[i] = '|';
2899         }
2900 }
2901
2902
2903
2904
2905 /**
2906  * \brief Back end for change_view()
2907  * \param newview set newview???
2908  */
2909 void do_change_view(int newview) {
2910         char buf[SIZ];
2911
2912         serv_printf("VIEW %d", newview);
2913         serv_getln(buf, sizeof buf);
2914         WC->wc_view = newview;
2915         smart_goto(WC->wc_roomname);
2916 }
2917
2918
2919
2920 /**
2921  * \brief Change the view for this room
2922  */
2923 void change_view(void) {
2924         int view;
2925
2926         view = atol(bstr("view"));
2927         do_change_view(view);
2928 }
2929
2930
2931 /**
2932  * \brief One big expanded tree list view --- like a folder list
2933  * \param fold the folder to view
2934  * \param max_folders how many folders???
2935  * \param num_floors hom many floors???
2936  */
2937 void do_folder_view(struct folder *fold, int max_folders, int num_floors) {
2938         char buf[SIZ];
2939         int levels;
2940         int i;
2941         int has_subfolders = 0;
2942         int *parents;
2943
2944         parents = malloc(max_folders * sizeof(int));
2945
2946         /** BEGIN TREE MENU */
2947         wprintf("<div id=\"roomlist_div\">Loading folder list...</div>\n");
2948
2949         /** include NanoTree */
2950         wprintf("<script type=\"text/javascript\" src=\"static/nanotree.js\"></script>\n");
2951
2952         /** initialize NanoTree */
2953         wprintf("<script type=\"text/javascript\">                      \n"
2954                 "       showRootNode = false;                           \n"
2955                 "       sortNodes = false;                              \n"
2956                 "       dragable = false;                               \n"
2957                 "                                                       \n"
2958                 "       function standardClick(treeNode) {              \n"
2959                 "       }                                               \n"
2960                 "                                                       \n"
2961                 "       var closedGif = 'static/folder_closed.gif';     \n"
2962                 "       var openGif = 'static/folder_open.gif';         \n"
2963                 "                                                       \n"
2964                 "       rootNode = new TreeNode(1, 'root node - hide'); \n"
2965         );
2966
2967         levels = 0;
2968         for (i=0; i<max_folders; ++i) {
2969
2970                 has_subfolders = 0;
2971                 if ((i+1) < max_folders) {
2972                         int len;
2973                         len = strlen(fold[i].name);
2974                         if ( (!strncasecmp(fold[i].name, fold[i+1].name, len))
2975                            && (fold[i+1].name[len] == '|') ) {
2976                                 has_subfolders = 1;
2977                         }
2978                 }
2979
2980                 levels = num_tokens(fold[i].name, '|');
2981                 parents[levels] = i;
2982
2983                 wprintf("var node%d = new TreeNode(%d, '", i, i);
2984
2985                 if (fold[i].selectable) {
2986                         wprintf("<a href=\"dotgoto?room=");
2987                         urlescputs(fold[i].room);
2988                         wprintf("\">");
2989                 }
2990
2991                 if (levels == 1) {
2992                         wprintf("<span class=\"roomlist_floor\">");
2993                 }
2994                 else if (fold[i].hasnewmsgs) {
2995                         wprintf("<span class=\"roomlist_new\">");
2996                 }
2997                 else {
2998                         wprintf("<span class=\"roomlist_old\">");
2999                 }
3000                 extract_token(buf, fold[i].name, levels-1, '|', sizeof buf);
3001                 escputs(buf);
3002                 wprintf("</span>");
3003
3004                 wprintf("</a>', ");
3005                 if (has_subfolders) {
3006                         wprintf("new Array(closedGif, openGif)");
3007                 }
3008                 else if (fold[i].view == VIEW_ADDRESSBOOK) {
3009                         wprintf("'static/viewcontacts_16x.gif'");
3010                 }
3011                 else if (fold[i].view == VIEW_CALENDAR) {
3012                         wprintf("'static/calarea_16x.gif'");
3013                 }
3014                 else if (fold[i].view == VIEW_CALBRIEF) {
3015                         wprintf("'static/calarea_16x.gif'");
3016                 }
3017                 else if (fold[i].view == VIEW_TASKS) {
3018                         wprintf("'static/taskmanag_16x.gif'");
3019                 }
3020                 else if (fold[i].view == VIEW_NOTES) {
3021                         wprintf("'static/storenotes_16x.gif'");
3022                 }
3023                 else if (fold[i].view == VIEW_MAILBOX) {
3024                         wprintf("'static/privatemess_16x.gif'");
3025                 }
3026                 else {
3027                         wprintf("'static/chatrooms_16x.gif'");
3028                 }
3029                 wprintf(", '");
3030                 urlescputs(fold[i].name);
3031                 wprintf("');\n");
3032
3033                 if (levels < 2) {
3034                         wprintf("rootNode.addChild(node%d);\n", i);
3035                 }
3036                 else {
3037                         wprintf("node%d.addChild(node%d);\n", parents[levels-1], i);
3038                 }
3039         }
3040
3041         wprintf("container = document.getElementById('roomlist_div');   \n"
3042                 "showTree('');  \n"
3043                 "</script>\n"
3044         );
3045
3046         free(parents);
3047         /** END TREE MENU */
3048 }
3049
3050 /**
3051  * \brief Boxes and rooms and lists ... oh my!
3052  * \param fold the folder to view
3053  * \param max_folders how many folders???
3054  * \param num_floors hom many floors???
3055  */
3056 void do_rooms_view(struct folder *fold, int max_folders, int num_floors) {
3057         char buf[256];
3058         char floor_name[256];
3059         char old_floor_name[256];
3060         char boxtitle[256];
3061         int levels, oldlevels;
3062         int i, t;
3063         int num_boxes = 0;
3064         static int columns = 3;
3065         int boxes_per_column = 0;
3066         int current_column = 0;
3067         int nf;
3068
3069         strcpy(floor_name, "");
3070         strcpy(old_floor_name, "");
3071
3072         nf = num_floors;
3073         while (nf % columns != 0) ++nf;
3074         boxes_per_column = (nf / columns);
3075         if (boxes_per_column < 1) boxes_per_column = 1;
3076
3077         /** Outer table (for columnization) */
3078         wprintf("<table BORDER=0 WIDTH=96%% CELLPADDING=5>"
3079                 "<tr><td valign=top>");
3080
3081         levels = 0;
3082         oldlevels = 0;
3083         for (i=0; i<max_folders; ++i) {
3084
3085                 levels = num_tokens(fold[i].name, '|');
3086                 extract_token(floor_name, fold[i].name, 0,
3087                         '|', sizeof floor_name);
3088
3089                 if ( (strcasecmp(floor_name, old_floor_name))
3090                    && (!IsEmptyStr(old_floor_name)) ) {
3091                         /* End inner box */
3092                         do_template("endbox");
3093                         wprintf("<br>");
3094
3095                         ++num_boxes;
3096                         if ((num_boxes % boxes_per_column) == 0) {
3097                                 ++current_column;
3098                                 if (current_column < columns) {
3099                                         wprintf("</td><td valign=top>\n");
3100                                 }
3101                         }
3102                 }
3103                 strcpy(old_floor_name, floor_name);
3104
3105                 if (levels == 1) {
3106                         /** Begin inner box */
3107                         stresc(boxtitle, 256, floor_name, 1, 0);
3108                         svprintf("BOXTITLE", WCS_STRING, boxtitle);
3109                         do_template("beginbox");
3110                 }
3111
3112                 oldlevels = levels;
3113
3114                 if (levels > 1) {
3115                         wprintf("&nbsp;");
3116                         if (levels>2) for (t=0; t<(levels-2); ++t) wprintf("&nbsp;&nbsp;&nbsp;");
3117                         if (fold[i].selectable) {
3118                                 wprintf("<a href=\"dotgoto?room=");
3119                                 urlescputs(fold[i].room);
3120                                 wprintf("\">");
3121                         }
3122                         else {
3123                                 wprintf("<i>");
3124                         }
3125                         if (fold[i].hasnewmsgs) {
3126                                 wprintf("<span class=\"roomlist_new\">");
3127                         }
3128                         else {
3129                                 wprintf("<span class=\"roomlist_old\">");
3130                         }
3131                         extract_token(buf, fold[i].name, levels-1, '|', sizeof buf);
3132                         escputs(buf);
3133                         wprintf("</span>");
3134                         if (fold[i].selectable) {
3135                                 wprintf("</A>");
3136                         }
3137                         else {
3138                                 wprintf("</i>");
3139                         }
3140                         if (!strcasecmp(fold[i].name, "My Folders|Mail")) {
3141                                 wprintf(" (INBOX)");
3142                         }
3143                         wprintf("<br />\n");
3144                 }
3145         }
3146         /** End the final inner box */
3147         do_template("endbox");
3148
3149         wprintf("</td></tr></table>\n");
3150 }
3151
3152 /**
3153  * \brief print a floor div???
3154  * \param which_floordiv name of the floordiv???
3155  */
3156 void set_floordiv_expanded(char *which_floordiv) {
3157         begin_ajax_response();
3158         safestrncpy(WC->floordiv_expanded, which_floordiv, sizeof WC->floordiv_expanded);
3159         end_ajax_response();
3160 }
3161
3162 /**
3163  * \brief view the iconbar
3164  * \param fold the folder to view
3165  * \param max_folders how many folders???
3166  * \param num_floors hom many floors???
3167  */
3168 void do_iconbar_view(struct folder *fold, int max_folders, int num_floors) {
3169         char buf[256];
3170         char floor_name[256];
3171         char old_floor_name[256];
3172         char floordivtitle[256];
3173         char floordiv_id[32];
3174         int levels, oldlevels;
3175         int i, t;
3176         int num_drop_targets = 0;
3177         char *icon = NULL;
3178
3179         strcpy(floor_name, "");
3180         strcpy(old_floor_name, "");
3181
3182         levels = 0;
3183         oldlevels = 0;
3184         for (i=0; i<max_folders; ++i) {
3185
3186                 levels = num_tokens(fold[i].name, '|');
3187                 extract_token(floor_name, fold[i].name, 0,
3188                         '|', sizeof floor_name);
3189
3190                 if ( (strcasecmp(floor_name, old_floor_name))
3191                    && (!IsEmptyStr(old_floor_name)) ) {
3192                         /** End inner box */
3193                         wprintf("<br>\n");
3194                         wprintf("</div>\n");    /** floordiv */
3195                 }
3196                 strcpy(old_floor_name, floor_name);
3197
3198                 if (levels == 1) {
3199                         /** Begin floor */
3200                         stresc(floordivtitle, 256, floor_name, 0, 0);
3201                         sprintf(floordiv_id, "floordiv%d", i);
3202                         wprintf("<span class=\"ib_roomlist_floor\" "
3203                                 "onClick=\"expand_floor('%s')\">"
3204                                 "%s</span><br>\n", floordiv_id, floordivtitle);
3205                         wprintf("<div id=\"%s\" style=\"display:%s\">",
3206                                 floordiv_id,
3207                                 (!strcasecmp(floordiv_id, WC->floordiv_expanded) ? "block" : "none")
3208                         );
3209                 }
3210
3211                 oldlevels = levels;
3212
3213                 if (levels > 1) {
3214                         wprintf("<div id=\"roomdiv%d\">", i);
3215                         wprintf("&nbsp;");
3216                         if (levels>2) for (t=0; t<(levels-2); ++t) wprintf("&nbsp;");
3217
3218                         /** choose the icon */
3219                         if (fold[i].view == VIEW_ADDRESSBOOK) {
3220                                 icon = "viewcontacts_16x.gif" ;
3221                         }
3222                         else if (fold[i].view == VIEW_CALENDAR) {
3223                                 icon = "calarea_16x.gif" ;
3224                         }
3225                         else if (fold[i].view == VIEW_CALBRIEF) {
3226                                 icon = "calarea_16x.gif" ;
3227                         }
3228                         else if (fold[i].view == VIEW_TASKS) {
3229                                 icon = "taskmanag_16x.gif" ;
3230                         }
3231                         else if (fold[i].view == VIEW_NOTES) {
3232                                 icon = "storenotes_16x.gif" ;
3233                         }
3234                         else if (fold[i].view == VIEW_MAILBOX) {
3235                                 icon = "privatemess_16x.gif" ;
3236                         }
3237                         else {
3238                                 icon = "chatrooms_16x.gif" ;
3239                         }
3240
3241                         if (fold[i].selectable) {
3242                                 wprintf("<a href=\"dotgoto?room=");
3243                                 urlescputs(fold[i].room);
3244                                 wprintf("\">");
3245                                 wprintf("<img align=\"middle\" border=0 src=\"static/%s\" alt=\"\"> ", icon);
3246                         }
3247                         else {
3248                                 wprintf("<i>");
3249                         }
3250                         if (fold[i].hasnewmsgs) {
3251                                 wprintf("<span class=\"ib_roomlist_new\">");
3252                         }
3253                         else {
3254                                 wprintf("<span class=\"ib_roomlist_old\">");
3255                         }
3256                         extract_token(buf, fold[i].name, levels-1, '|', sizeof buf);
3257                         escputs(buf);
3258                         if (!strcasecmp(fold[i].name, "My Folders|Mail")) {
3259                                 wprintf(" (INBOX)");
3260                         }
3261                         wprintf("</span>");
3262                         if (fold[i].selectable) {
3263                                 wprintf("</A>");
3264                         }
3265                         else {
3266                                 wprintf("</i>");
3267                         }
3268                         wprintf("<br />");
3269                         wprintf("</div>\n");    /** roomdiv */
3270                 }
3271         }
3272         wprintf("</div>\n");    /** floordiv */
3273
3274
3275         /** BEGIN: The old invisible pixel trick, to get our JavaScript to initialize */
3276         wprintf("<img src=\"static/blank.gif\" onLoad=\"\n");
3277
3278         num_drop_targets = 0;
3279
3280         for (i=0; i<max_folders; ++i) {
3281                 levels = num_tokens(fold[i].name, '|');
3282                 if (levels > 1) {
3283                         wprintf("drop_targets_elements[%d]=$('roomdiv%d');\n", num_drop_targets, i);
3284                         wprintf("drop_targets_roomnames[%d]='", num_drop_targets);
3285                         jsescputs(fold[i].room);
3286                         wprintf("';\n");
3287                         ++num_drop_targets;
3288                 }
3289         }
3290
3291         wprintf("num_drop_targets = %d;\n", num_drop_targets);
3292         if ((WC->floordiv_expanded[0] != '\0')&&
3293             (WC->floordiv_expanded[1] != '\0')){
3294                 wprintf("which_div_expanded = '%s';\n", WC->floordiv_expanded);
3295         }
3296
3297         wprintf("\">\n");
3298         /** END: The old invisible pixel trick, to get our JavaScript to initialize */
3299 }
3300
3301
3302
3303 /**
3304  * \brief Burn the cached folder list.  
3305  * \param age How old the cahce needs to be before we burn it.
3306  */
3307
3308 void burn_folder_cache(time_t age)
3309 {
3310         /** If our cached folder list is very old, burn it. */
3311         if (WC->cache_fold != NULL) {
3312                 if ((time(NULL) - WC->cache_timestamp) > age) {
3313                         free(WC->cache_fold);
3314                         WC->cache_fold = NULL;
3315                 }
3316         }
3317 }
3318
3319
3320
3321
3322 /**
3323  * \brief Show the room list.  
3324  * (only should get called by
3325  * knrooms() because that's where output_headers() is called from)
3326  * \param viewpref the view preferences???
3327  */
3328
3329 void list_all_rooms_by_floor(char *viewpref) {
3330         char buf[SIZ];
3331         int swap = 0;
3332         struct folder *fold = NULL;
3333         struct folder ftmp;
3334         int max_folders = 0;
3335         int alloc_folders = 0;
3336         int *floor_mapping;
3337         int IDMax;
3338         int i, j;
3339         int ra_flags = 0;
3340         int flags = 0;
3341         int num_floors = 1;     /** add an extra one for private folders */
3342         char buf2[SIZ];
3343         char buf3[SIZ];
3344         
3345         /** If our cached folder list is very old, burn it. */
3346         burn_folder_cache(300);
3347         
3348         /** Can we do the iconbar roomlist from cache? */
3349         if ((WC->cache_fold != NULL) && (!strcasecmp(viewpref, "iconbar"))) {
3350                 do_iconbar_view(WC->cache_fold, WC->cache_max_folders, WC->cache_num_floors);
3351                 return;
3352         }
3353
3354         /** Grab the floor table so we know how to build the list... */
3355         load_floorlist();
3356
3357         /** Start with the mailboxes */
3358         max_folders = 1;
3359         alloc_folders = 1;
3360         fold = malloc(sizeof(struct folder));
3361         memset(fold, 0, sizeof(struct folder));
3362         strcpy(fold[0].name, "My folders");
3363         fold[0].is_mailbox = 1;
3364
3365         /** Then add floors */
3366         serv_puts("LFLR");
3367         serv_getln(buf, sizeof buf);
3368         if (buf[0]=='1') while(serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3369                 if (max_folders >= alloc_folders) {
3370                         alloc_folders = max_folders + 100;
3371                         fold = realloc(fold,
3372                                 alloc_folders * sizeof(struct folder));
3373                 }
3374                 memset(&fold[max_folders], 0, sizeof(struct folder));
3375                 extract_token(fold[max_folders].name, buf, 1, '|', sizeof fold[max_folders].name);
3376                 extract_token(buf3, buf, 0, '|', SIZ);
3377                 fold[max_folders].floor = atol (buf3);
3378                 ++max_folders;
3379                 ++num_floors;
3380         }
3381         IDMax = 0;
3382         for (i=0; i<num_floors; i++)
3383                 if (IDMax < fold[i].floor)
3384                         IDMax = fold[i].floor;
3385         floor_mapping = malloc (sizeof (int) * (IDMax + 1));
3386         memset (floor_mapping, 0, sizeof (int) * (IDMax + 1));
3387         for (i=0; i<num_floors; i++)
3388                 floor_mapping[fold[i].floor]=i;
3389         
3390         /** refresh the messages index for this room */
3391 //      serv_puts("GOTO ");
3392 //      while (serv_getln(buf, sizeof buf), strcmp(buf, "000"));
3393         /** Now add rooms */
3394         serv_puts("LKRA");
3395         serv_getln(buf, sizeof buf);
3396         if (buf[0]=='1') while(serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3397                 if (max_folders >= alloc_folders) {
3398                         alloc_folders = max_folders + 100;
3399                         fold = realloc(fold,
3400                                 alloc_folders * sizeof(struct folder));
3401                 }
3402                 memset(&fold[max_folders], 0, sizeof(struct folder));
3403                 extract_token(fold[max_folders].room, buf, 0, '|', sizeof fold[max_folders].room);
3404                 ra_flags = extract_int(buf, 5);
3405                 flags = extract_int(buf, 1);
3406                 fold[max_folders].floor = extract_int(buf, 2);
3407                 fold[max_folders].hasnewmsgs =
3408                         ((ra_flags & UA_HASNEWMSGS) ? 1 : 0 );
3409                 if (flags & QR_MAILBOX) {
3410                         fold[max_folders].is_mailbox = 1;
3411                 }
3412                 fold[max_folders].view = extract_int(buf, 6);
3413                 room_to_folder(fold[max_folders].name,
3414                                 fold[max_folders].room,
3415                                 fold[max_folders].floor,
3416                                 fold[max_folders].is_mailbox);
3417                 fold[max_folders].selectable = 1;
3418                 /* Increase the room count for the associtaed floor */
3419                 if (fold[max_folders].is_mailbox) {
3420                         fold[0].num_rooms++;
3421                 }
3422                 else {
3423                         i = floor_mapping[fold[max_folders].floor];
3424                         fold[i].num_rooms++;
3425                 }
3426                 ++max_folders;
3427         }
3428         
3429         /*
3430          * Remove any floors that don't have rooms
3431          */
3432         get_preference("emptyfloors", buf2, sizeof buf2);
3433         if (buf2[0]==0 || (strcasecmp(buf2, "no") == 0))
3434         {
3435                 for (i=0; i<num_floors; i++)
3436                 {
3437                         if (fold[i].num_rooms == 0) {
3438                                 for (j=i; j<max_folders; j++) {
3439                                         memcpy(&fold[j], &fold[j+1], sizeof(struct folder));
3440                                 }
3441                                 max_folders--;
3442                                 num_floors--;
3443                                 i--;
3444                         }
3445                 }
3446         }
3447         
3448         /** Bubble-sort the folder list */
3449         for (i=0; i<max_folders; ++i) {
3450                 for (j=0; j<(max_folders-1)-i; ++j) {
3451                         if (fold[j].is_mailbox == fold[j+1].is_mailbox) {
3452                                 swap = strcasecmp(fold[j].name, fold[j+1].name);
3453                         }
3454                         else {
3455                                 if ( (fold[j+1].is_mailbox)
3456                                    && (!fold[j].is_mailbox)) {
3457                                         swap = 1;
3458                                 }
3459                                 else {
3460                                         swap = 0;
3461                                 }
3462                         }
3463                         if (swap > 0) {
3464                                 memcpy(&ftmp, &fold[j], sizeof(struct folder));
3465                                 memcpy(&fold[j], &fold[j+1],
3466                                                         sizeof(struct folder));
3467                                 memcpy(&fold[j+1], &ftmp,
3468                                                         sizeof(struct folder));
3469                         }
3470                 }
3471         }
3472
3473
3474         if (!strcasecmp(viewpref, "folders")) {
3475                 do_folder_view(fold, max_folders, num_floors);
3476         }
3477         else if (!strcasecmp(viewpref, "hackish_view")) {
3478                 for (i=0; i<max_folders; ++i) {
3479                         escputs(fold[i].name);
3480                         wprintf("<br />\n");
3481                 }
3482         }
3483         else if (!strcasecmp(viewpref, "iconbar")) {
3484                 do_iconbar_view(fold, max_folders, num_floors);
3485         }
3486         else {
3487                 do_rooms_view(fold, max_folders, num_floors);
3488         }
3489
3490         /* Don't free the folder list ... cache it for future use! */
3491         if (WC->cache_fold != NULL) {
3492                 free(WC->cache_fold);
3493         }
3494         WC->cache_fold = fold;
3495         WC->cache_max_folders = max_folders;
3496         WC->cache_num_floors = num_floors;
3497         WC->cache_timestamp = time(NULL);
3498         free(floor_mapping);
3499 }
3500
3501
3502 /**
3503  * \brief Do either a known rooms list or a folders list, depending on the
3504  * user's preference
3505  */
3506 void knrooms(void)
3507 {
3508         char listviewpref[SIZ];
3509
3510         output_headers(1, 1, 2, 0, 0, 0);
3511
3512         /** Determine whether the user is trying to change views */
3513         if (bstr("view") != NULL) {
3514                 if (!IsEmptyStr(bstr("view"))) {
3515                         set_preference("roomlistview", bstr("view"), 1);
3516                 }
3517         }
3518
3519         get_preference("roomlistview", listviewpref, sizeof listviewpref);
3520
3521         if ( (strcasecmp(listviewpref, "folders"))
3522            && (strcasecmp(listviewpref, "table")) ) {
3523                 strcpy(listviewpref, "rooms");
3524         }
3525
3526         /** title bar */
3527         wprintf("<div id=\"banner\">\n");
3528         wprintf("<div class=\"room_banner\">");
3529         wprintf("<h1>");
3530         if (!strcasecmp(listviewpref, "rooms")) {
3531                 wprintf(_("Room list"));
3532         }
3533         if (!strcasecmp(listviewpref, "folders")) {
3534                 wprintf(_("Folder list"));
3535         }
3536         if (!strcasecmp(listviewpref, "table")) {
3537                 wprintf(_("Room list"));
3538         }
3539         wprintf("</h1></div>\n");
3540
3541         /** offer the ability to switch views */
3542         wprintf("<ul class=\"room_actions\">\n");
3543         wprintf("<li class=\"start_page\">");
3544         offer_start_page();
3545         wprintf("</li>");
3546         wprintf("<li><form name=\"roomlistomatic\">\n"
3547                 "<select name=\"newview\" size=\"1\" "
3548                 "OnChange=\"location.href=roomlistomatic.newview.options"
3549                 "[selectedIndex].value\">\n");
3550
3551         wprintf("<option %s value=\"knrooms&view=rooms\">"
3552                 "View as room list"
3553                 "</option>\n",
3554                 ( !strcasecmp(listviewpref, "rooms") ? "SELECTED" : "" )
3555         );
3556
3557         wprintf("<option %s value=\"knrooms&view=folders\">"
3558                 "View as folder list"
3559                 "</option>\n",
3560                 ( !strcasecmp(listviewpref, "folders") ? "SELECTED" : "" )
3561         );
3562
3563         wprintf("</select>");
3564         wprintf("</form></li>");
3565         wprintf("</ul></div>\n");
3566
3567         wprintf("<div id=\"content\" class=\"service\">\n");
3568
3569         /** Display the room list in the user's preferred format */
3570         list_all_rooms_by_floor(listviewpref);
3571         wDumpContent(1);
3572 }
3573
3574
3575
3576 /**
3577  * \brief Set the message expire policy for this room and/or floor
3578  */
3579 void set_room_policy(void) {
3580         char buf[SIZ];
3581
3582         if (IsEmptyStr(bstr("ok_button"))) {
3583                 strcpy(WC->ImportantMessage,
3584                         _("Cancelled.  Changes were not saved."));
3585                 display_editroom();
3586                 return;
3587         }
3588
3589         serv_printf("SPEX room|%d|%d", atoi(bstr("roompolicy")), atoi(bstr("roomvalue")));
3590         serv_getln(buf, sizeof buf);
3591         strcpy(WC->ImportantMessage, &buf[4]);
3592
3593         if (WC->axlevel >= 6) {
3594                 strcat(WC->ImportantMessage, "<br />\n");
3595                 serv_printf("SPEX floor|%d|%d", atoi(bstr("floorpolicy")), atoi(bstr("floorvalue")));
3596                 serv_getln(buf, sizeof buf);
3597                 strcat(WC->ImportantMessage, &buf[4]);
3598         }
3599
3600         display_editroom();
3601 }
3602
3603 /*@}*/