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