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