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