]> code.citadel.org Git - citadel.git/blob - webcit/roomops.c
8840d127f3d7d40ed9932734173eeeab23b4654e
[citadel.git] / webcit / roomops.c
1 /*
2  * $Id$
3  *
4  * Lots of different room-related operations.
5  */
6
7 #include <ctype.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <stdio.h>
11 #include <fcntl.h>
12 #include <signal.h>
13 #include <sys/types.h>
14 #include <sys/wait.h>
15 #include <sys/socket.h>
16 #include <sys/time.h>
17 #include <limits.h>
18 #include <netinet/in.h>
19 #include <netdb.h>
20 #include <string.h>
21 #include <pwd.h>
22 #include <errno.h>
23 #include <stdarg.h>
24 #include <pthread.h>
25 #include <signal.h>
26 #include "webcit.h"
27
28 struct folder {
29         int floor;
30         char room[SIZ];
31         char name[SIZ];
32         int hasnewmsgs;
33         int is_mailbox;
34         int selectable;
35 };
36
37 char *viewdefs[] = {
38         "Bulletin Board",
39         "Mail Folder",
40         "Address Book",
41         "Calendar",
42         "Task List",
43         "Notes List"
44 };
45
46 char floorlist[128][SIZ];
47
48 /*
49  * load the list of floors
50  */
51 void load_floorlist(void)
52 {
53         int a;
54         char buf[SIZ];
55
56         for (a = 0; a < 128; ++a)
57                 floorlist[a][0] = 0;
58
59         serv_puts("LFLR");
60         serv_gets(buf);
61         if (buf[0] != '1') {
62                 strcpy(floorlist[0], "Main Floor");
63                 return;
64         }
65         while (serv_gets(buf), strcmp(buf, "000")) {
66                 extract(floorlist[extract_int(buf, 0)], buf, 1);
67         }
68 }
69
70
71 /*
72  * remove a room from the march list
73  */
74 void remove_march(char *aaa)
75 {
76         struct march *mptr, *mptr2;
77
78         if (WC->march == NULL)
79                 return;
80
81         if (!strcasecmp(WC->march->march_name, aaa)) {
82                 mptr = WC->march->next;
83                 free(WC->march);
84                 WC->march = mptr;
85                 return;
86         }
87         mptr2 = WC->march;
88         for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
89                 if (!strcasecmp(mptr->march_name, aaa)) {
90                         mptr2->next = mptr->next;
91                         free(mptr);
92                         mptr = mptr2;
93                 } else {
94                         mptr2 = mptr;
95                 }
96         }
97 }
98
99
100
101
102
103 void room_tree_list(struct roomlisting *rp)
104 {
105         char rmname[64];
106         int f;
107
108         if (rp == NULL) {
109                 return;
110         }
111
112         room_tree_list(rp->lnext);
113
114         strcpy(rmname, rp->rlname);
115         f = rp->rlflags;
116
117         wprintf("<A HREF=\"/dotgoto&room=");
118         urlescputs(rmname);
119         wprintf("\"");
120         wprintf(">");
121         escputs1(rmname, 1, 1);
122         if ((f & QR_DIRECTORY) && (f & QR_NETWORK))
123                 wprintf("}");
124         else if (f & QR_DIRECTORY)
125                 wprintf("]");
126         else if (f & QR_NETWORK)
127                 wprintf(")");
128         else
129                 wprintf("&gt;");
130         wprintf("</A><TT> </TT>\n");
131
132         room_tree_list(rp->rnext);
133         free(rp);
134 }
135
136
137 /* 
138  * Room ordering stuff (compare first by floor, then by order)
139  */
140 int rordercmp(struct roomlisting *r1, struct roomlisting *r2)
141 {
142         if ((r1 == NULL) && (r2 == NULL))
143                 return (0);
144         if (r1 == NULL)
145                 return (-1);
146         if (r2 == NULL)
147                 return (1);
148         if (r1->rlfloor < r2->rlfloor)
149                 return (-1);
150         if (r1->rlfloor > r2->rlfloor)
151                 return (1);
152         if (r1->rlorder < r2->rlorder)
153                 return (-1);
154         if (r1->rlorder > r2->rlorder)
155                 return (1);
156         return (0);
157 }
158
159
160 /*
161  * Common code for all room listings
162  */
163 void listrms(char *variety)
164 {
165         char buf[SIZ];
166         int num_rooms = 0;
167
168         struct roomlisting *rl = NULL;
169         struct roomlisting *rp;
170         struct roomlisting *rs;
171
172
173         /* Ask the server for a room list */
174         serv_puts(variety);
175         serv_gets(buf);
176         if (buf[0] != '1') {
177                 wprintf("&nbsp;");
178                 return;
179         }
180         while (serv_gets(buf), strcmp(buf, "000")) {
181                 ++num_rooms;
182                 rp = malloc(sizeof(struct roomlisting));
183                 extract(rp->rlname, buf, 0);
184                 rp->rlflags = extract_int(buf, 1);
185                 rp->rlfloor = extract_int(buf, 2);
186                 rp->rlorder = extract_int(buf, 3);
187                 rp->lnext = NULL;
188                 rp->rnext = NULL;
189
190                 rs = rl;
191                 if (rl == NULL) {
192                         rl = rp;
193                 } else
194                         while (rp != NULL) {
195                                 if (rordercmp(rp, rs) < 0) {
196                                         if (rs->lnext == NULL) {
197                                                 rs->lnext = rp;
198                                                 rp = NULL;
199                                         } else {
200                                                 rs = rs->lnext;
201                                         }
202                                 } else {
203                                         if (rs->rnext == NULL) {
204                                                 rs->rnext = rp;
205                                                 rp = NULL;
206                                         } else {
207                                                 rs = rs->rnext;
208                                         }
209                                 }
210                         }
211         }
212
213         room_tree_list(rl);
214
215         /* If no rooms were listed, print an nbsp to make the cell
216          * borders show up anyway.
217          */
218         if (num_rooms == 0) wprintf("&nbsp;");
219 }
220
221
222 /*
223  * list all forgotten rooms
224  */
225 void zapped_list(void)
226 {
227         output_headers(1, 1, 0, 0, 0, 0, 0);
228
229         svprintf("BOXTITLE", WCS_STRING, "Zapped (forgotten) rooms");
230         do_template("beginbox");
231
232         listrms("LZRM -1");
233
234         wprintf("<br /><br />\n");
235         wprintf("Click on any room to un-zap it and goto that room.\n");
236         do_template("endbox");
237         wDumpContent(1);
238 }
239
240
241 /*
242  * read this room's info file (set v to 1 for verbose mode)
243  */
244 void readinfo(void)
245 {
246         char buf[SIZ];
247
248         serv_puts("RINF");
249         serv_gets(buf);
250         if (buf[0] == '1') {
251                 fmout(NULL, "CENTER");
252         }
253 }
254
255
256
257
258 /* Display room graphic.  The server doesn't actually
259  * need the room name, but we supply it in order to
260  * keep the browser from using a cached graphic from 
261  * another room.
262  */
263 void embed_room_graphic(void) {
264         char buf[SIZ];
265
266         serv_puts("OIMG _roompic_");
267         serv_gets(buf);
268         if (buf[0] == '2') {
269                 wprintf("<TD BGCOLOR=\"#444455\">");
270                 wprintf("<IMG HEIGHT=64 SRC=\"/image&name=_roompic_&room=");
271                 urlescputs(WC->wc_roomname);
272                 wprintf("\"></TD>");
273                 serv_puts("CLOS");
274                 serv_gets(buf);
275         }
276
277 }
278
279
280 /* Let the user know if new mail has arrived 
281  */
282 void embed_newmail_button(void) {
283         if ( (WC->new_mail > WC->remember_new_mail) && (WC->new_mail>0) ) {
284                 wprintf(
285                         "<A HREF=\"/dotgoto?room=_MAIL_\">"
286                         "<IMG SRC=\"/static/mail.gif\" border=0 "
287                         "ALT=\"You have new mail\">"
288                         "<br /><SPAN CLASS=\"youhavemail\">"
289                         "%d new mail</SPAN></A>", WC->new_mail);
290                 WC->remember_new_mail = WC->new_mail;
291         }
292 }
293
294
295
296 /*
297  * Display the current view and offer an option to change it
298  */
299 void embed_view_o_matic(void) {
300         int i;
301
302         wprintf("<FORM NAME=\"viewomatic\">\n"
303                 "<span class=\"room_banner_new_messages\">View as: "
304                 "<SELECT NAME=\"newview\" SIZE=\"1\" "
305                 "STYLE=\"font-family: Bitstream Vera Sans,Arial,Helvetica,sans-serif;"
306                 " font-size: 7pt; background: #444455; color: #ddddcc;\" "
307                 "OnChange=\"location.href=viewomatic.newview.options"
308                 "[selectedIndex].value\">\n");
309
310         for (i=0; i<(sizeof viewdefs / sizeof (char *)); ++i) {
311                 /*
312                  * Only offer the views that make sense, given the default
313                  * view for the room.  For example, don't offer a Calendar
314                  * view in a non-Calendar room.
315                  */
316                 if (
317                         (i == WC->wc_view)
318                    ||   (i == WC->wc_default_view)
319                    ||   ( (i == 0) && (WC->wc_default_view == 1) )
320                    ||   ( (i == 1) && (WC->wc_default_view == 0) )
321                 ) {
322
323                         wprintf("<OPTION %s VALUE=\"/changeview?view=%d\">",
324                                 ((i == WC->wc_view) ? "SELECTED" : ""),
325                                 i );
326                         escputs(viewdefs[i]);
327                         wprintf("</OPTION>\n");
328                 }
329         }
330         wprintf("</select></span></form>\n");
331 }
332
333
334
335 void embed_room_banner(char *got, int navbar_style) {
336         char fakegot[SIZ];
337
338         /* We need to have the information returned by a GOTO server command.
339          * If it isn't supplied, we fake it by issuing our own GOTO.
340          */
341         if (got == NULL) {
342                 serv_printf("GOTO %s", WC->wc_roomname);
343                 serv_gets(fakegot);
344                 got = fakegot;
345         }
346
347         /* If the user happens to select the "make this my start page" link,
348          * we want it to remember the URL as a "/dotskip" one instead of
349          * a "skip" or "gotonext" or something like that.
350          */
351         snprintf(WC->this_page, sizeof(WC->this_page), "/dotskip&room=%s",
352                 WC->wc_roomname);
353
354         /* Check for new mail. */
355         WC->new_mail = extract_int(&got[4], 9);
356         WC->wc_view = extract_int(&got[4], 11);
357
358         svprintf("ROOMNAME", WCS_STRING, "%s", WC->wc_roomname);
359         svprintf("NEWMSGS", WCS_STRING, "%d", extract_int(&got[4], 1));
360         svprintf("TOTALMSGS", WCS_STRING, "%d", extract_int(&got[4], 2));
361         svcallback("ROOMPIC", embed_room_graphic);
362         svcallback("ROOMINFO", readinfo);
363         svcallback("YOUHAVEMAIL", embed_newmail_button);
364         svcallback("VIEWOMATIC", embed_view_o_matic);
365         svcallback("START", offer_start_page);
366
367         do_template("roombanner");
368         if (navbar_style != navbar_none) {
369
370                 wprintf("<div style=\"position:absolute; bottom:0px; left:0px\">\n"
371                         "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%%\"><tr>\n");
372
373
374                 if (navbar_style == navbar_default) wprintf(
375                         "<td>"
376                         "<a href=\"/ungoto\">"
377                         "<img align=\"middle\" src=\"/static/back.gif\" border=\"0\">"
378                         "<span class=\"navbar_link\">Ungoto</span></A>"
379                         "</td>\n"
380                 );
381
382                 if ( (navbar_style == navbar_default) && (WC->wc_view == VIEW_BBS) ) {
383                         wprintf(
384                                 "<td>"
385                                 "<A HREF=\"/readnew\">"
386                                 "<img align=\"middle\" src=\"/static/readmsgs.gif\" border=\"0\">"
387                                 "<span class=\"navbar_link\">Read new messages</span></A>"
388                                 "</td>\n"
389                         );
390                 }
391
392                 if (navbar_style == navbar_default) {
393                         switch(WC->wc_view) {
394                                 case VIEW_ADDRESSBOOK:
395                                         wprintf(
396                                                 "<td>"
397                                                 "<A HREF=\"/readfwd\">"
398                                                 "<img align=\"middle\" src=\"/static/readmsgs.gif\" "
399                                                 "border=\"0\">"
400                                                 "<span class=\"navbar_link\">"
401                                                 "View contacts"
402                                                 "</span></a></td>\n"
403                                         );
404                                         break;
405                                 case VIEW_CALENDAR:
406                                         wprintf(
407                                                 "<td>"
408                                                 "<A HREF=\"/readfwd?calview=day\">"
409                                                 "<img align=\"middle\" src=\"/static/day_view.gif\" "
410                                                 "border=\"0\">"
411                                                 "<span class=\"navbar_link\">"
412                                                 "Day view"
413                                                 "</span></a></td>\n"
414                                         );
415                                         wprintf(
416                                                 "<td>"
417                                                 "<A HREF=\"/readfwd?calview=month\">"
418                                                 "<img align=\"middle\" src=\"/static/month_view.gif\" "
419                                                 "border=\"0\">"
420                                                 "<span class=\"navbar_link\">"
421                                                 "Month view"
422                                                 "</span></a></td>\n"
423                                         );
424                                         break;
425                                 case VIEW_TASKS:
426                                         wprintf(
427                                                 "<td>"
428                                                 "<A HREF=\"/readfwd\">"
429                                                 "<img align=\"middle\" src=\"/static/readmsgs.gif\" "
430                                                 "border=\"0\">"
431                                                 "<span class=\"navbar_link\">"
432                                                 "View tasks"
433                                                 "</span></a></td>\n"
434                                         );
435                                         break;
436                                 case VIEW_NOTES:
437                                         wprintf(
438                                                 "<td>"
439                                                 "<A HREF=\"/readfwd\">"
440                                                 "<img align=\"middle\" src=\"/static/readmsgs.gif\" "
441                                                 "border=\"0\">"
442                                                 "<span class=\"navbar_link\">"
443                                                 "View notes"
444                                                 "</span></a></td>\n"
445                                         );
446                                         break;
447                                 case VIEW_MAILBOX:
448                                         wprintf(
449                                                 "<td>"
450                                                 "<A HREF=\"/readfwd\">"
451                                                 "<img align=\"middle\" src=\"/static/readmsgs.gif\" "
452                                                 "border=\"0\">"
453                                                 "<span class=\"navbar_link\">"
454                                                 "View message list"
455                                                 "</span></a></td>\n"
456                                         );
457                                         break;
458                                 default:
459                                         wprintf(
460                                                 "<td>"
461                                                 "<A HREF=\"/readfwd\">"
462                                                 "<img align=\"middle\" src=\"/static/readmsgs.gif\" "
463                                                 "border=\"0\">"
464                                                 "<span class=\"navbar_link\">"
465                                                 "Read all messages"
466                                                 "</span></a></td>\n"
467                                         );
468                                         break;
469                         }
470                 }
471
472                 if (navbar_style == navbar_default) {
473                         wprintf(
474                                 "<td>"
475                                 "<A HREF=\"/display_enter\">"
476                                 "<img align=\"middle\" src=\"/static/enter.gif\" border=\"0\">"
477                                 "<span class=\"navbar_link\">"
478                         );
479                         switch(WC->wc_view) {
480                                 case VIEW_ADDRESSBOOK:
481                                         wprintf("Add new contact");
482                                         break;
483                                 case VIEW_CALENDAR:
484                                         wprintf("Add new event");
485                                         break;
486                                 case VIEW_TASKS:
487                                         wprintf("Add new task");
488                                         break;
489                                 case VIEW_NOTES:
490                                         wprintf("Add new note");
491                                         break;
492                                 default:
493                                         wprintf("Enter a message");
494                                         break;
495                         }
496                         wprintf("</span></a></td>\n");
497                 }
498
499                 if (navbar_style == navbar_default) wprintf(
500                         "<td>"
501                         "<A HREF=\"/skip\" "
502                         "TITLE=\"Leave all messages marked as unread, go to next room with unread messages\">"
503                         "<span class=\"navbar_link\">Skip this room</span>"
504                         "<img align=\"middle\" src=\"/static/forward.gif\" border=\"0\"></A>"
505                         "</td>\n"
506                 );
507
508                 if (navbar_style == navbar_default) wprintf(
509                         "<td>"
510                         "<A HREF=\"/gotonext\" "
511                         "TITLE=\"Mark all messages as read, go to next room with unread messages\">"
512                         "<span class=\"navbar_link\">Goto next room</span>"
513                         "<img align=\"middle\" src=\"/static/forward.gif\" border=\"0\"></A>"
514                         "</td>\n"
515                 );
516
517                 wprintf("</tr></table></div>\n");
518         }
519
520 }
521
522
523
524
525
526 /*
527  * back end routine to take the session to a new room
528  *
529  */
530 void gotoroom(char *gname)
531 {
532         char buf[SIZ];
533         static long ls = (-1L);
534
535         /* store ungoto information */
536         strcpy(WC->ugname, WC->wc_roomname);
537         WC->uglsn = ls;
538
539         /* move to the new room */
540         serv_printf("GOTO %s", gname);
541         serv_gets(buf);
542         if (buf[0] != '2') {
543                 serv_puts("GOTO _BASEROOM_");
544                 serv_gets(buf);
545         }
546         if (buf[0] != '2') {
547                 return;
548         }
549         extract(WC->wc_roomname, &buf[4], 0);
550         WC->room_flags = extract_int(&buf[4], 4);
551         /* highest_msg_read = extract_int(&buf[4],6);
552            maxmsgnum = extract_int(&buf[4],5);
553            is_mail = (char) extract_int(&buf[4],7); */
554         ls = extract_long(&buf[4], 6);
555         WC->wc_floor = extract_int(&buf[4], 10);
556         WC->wc_view = extract_int(&buf[4], 11);
557         WC->wc_default_view = extract_int(&buf[4], 12);
558
559         if (WC->is_aide)
560                 WC->is_room_aide = WC->is_aide;
561         else
562                 WC->is_room_aide = (char) extract_int(&buf[4], 8);
563
564         remove_march(WC->wc_roomname);
565         if (!strcasecmp(gname, "_BASEROOM_"))
566                 remove_march(gname);
567 }
568
569
570 /*
571  * Locate the room on the march list which we most want to go to.  Each room
572  * is measured given a "weight" of preference based on various factors.
573  */
574 char *pop_march(int desired_floor)
575 {
576         static char TheRoom[128];
577         int TheFloor = 0;
578         int TheOrder = 32767;
579         int TheWeight = 0;
580         int weight;
581         struct march *mptr = NULL;
582
583         strcpy(TheRoom, "_BASEROOM_");
584         if (WC->march == NULL)
585                 return (TheRoom);
586
587         for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
588                 weight = 0;
589                 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
590                         weight = weight + 10000;
591                 if (mptr->march_floor == desired_floor)
592                         weight = weight + 5000;
593
594                 weight = weight + ((128 - (mptr->march_floor)) * 128);
595                 weight = weight + (128 - (mptr->march_order));
596
597                 if (weight > TheWeight) {
598                         TheWeight = weight;
599                         strcpy(TheRoom, mptr->march_name);
600                         TheFloor = mptr->march_floor;
601                         TheOrder = mptr->march_order;
602                 }
603         }
604         return (TheRoom);
605 }
606
607
608
609 /* Goto next room having unread messages.
610  * We want to skip over rooms that the user has already been to, and take the
611  * user back to the lobby when done.  The room we end up in is placed in
612  * newroom - which is set to 0 (the lobby) initially.
613  * We start the search in the current room rather than the beginning to prevent
614  * two or more concurrent users from dragging each other back to the same room.
615  */
616 void gotonext(void)
617 {
618         char buf[SIZ];
619         struct march *mptr, *mptr2;
620         char next_room[128];
621
622         /* First check to see if the march-mode list is already allocated.
623          * If it is, pop the first room off the list and go there.
624          */
625
626         if (WC->march == NULL) {
627                 serv_puts("LKRN");
628                 serv_gets(buf);
629                 if (buf[0] == '1')
630                         while (serv_gets(buf), strcmp(buf, "000")) {
631                                 mptr = (struct march *) malloc(sizeof(struct march));
632                                 mptr->next = NULL;
633                                 extract(mptr->march_name, buf, 0);
634                                 mptr->march_floor = extract_int(buf, 2);
635                                 mptr->march_order = extract_int(buf, 3);
636                                 if (WC->march == NULL) {
637                                         WC->march = mptr;
638                                 } else {
639                                         mptr2 = WC->march;
640                                         while (mptr2->next != NULL)
641                                                 mptr2 = mptr2->next;
642                                         mptr2->next = mptr;
643                                 }
644                         }
645 /* add _BASEROOM_ to the end of the march list, so the user will end up
646  * in the system base room (usually the Lobby>) at the end of the loop
647  */
648                 mptr = (struct march *) malloc(sizeof(struct march));
649                 mptr->next = NULL;
650                 strcpy(mptr->march_name, "_BASEROOM_");
651                 if (WC->march == NULL) {
652                         WC->march = mptr;
653                 } else {
654                         mptr2 = WC->march;
655                         while (mptr2->next != NULL)
656                                 mptr2 = mptr2->next;
657                         mptr2->next = mptr;
658                 }
659 /*
660  * ...and remove the room we're currently in, so a <G>oto doesn't make us
661  * walk around in circles
662  */
663                 remove_march(WC->wc_roomname);
664         }
665         if (WC->march != NULL) {
666                 strcpy(next_room, pop_march(-1));
667         } else {
668                 strcpy(next_room, "_BASEROOM_");
669         }
670
671
672         smart_goto(next_room);
673 }
674
675
676 void smart_goto(char *next_room) {
677         gotoroom(next_room);
678         readloop("readnew");
679 }
680
681
682
683 /*
684  * mark all messages in current room as having been read
685  */
686 void slrp_highest(void)
687 {
688         char buf[SIZ];
689
690         /* set pointer */
691         serv_puts("SLRP HIGHEST");
692         serv_gets(buf);
693         if (buf[0] != '2') {
694                 wprintf("<EM>%s</EM><br />\n", &buf[4]);
695                 return;
696         }
697 }
698
699
700 /*
701  * un-goto the previous room
702  */
703 void ungoto(void)
704 {
705         char buf[SIZ];
706
707         if (!strcmp(WC->ugname, "")) {
708                 smart_goto(WC->wc_roomname);
709                 return;
710         }
711         serv_printf("GOTO %s", WC->ugname);
712         serv_gets(buf);
713         if (buf[0] != '2') {
714                 smart_goto(WC->wc_roomname);
715                 return;
716         }
717         if (WC->uglsn >= 0L) {
718                 serv_printf("SLRP %ld", WC->uglsn);
719                 serv_gets(buf);
720         }
721         strcpy(buf, WC->ugname);
722         strcpy(WC->ugname, "");
723         smart_goto(buf);
724 }
725
726
727
728
729
730 /*
731  * Set/clear/read the "self-service list subscribe" flag for a room
732  * 
733  * Set 'newval' to 0 to clear, 1 to set, any other value to leave unchanged.
734  * Always returns the new value.
735  */
736
737 int self_service(int newval) {
738         int current_value = 0;
739         char buf[SIZ];
740         
741         char name[SIZ];
742         char password[SIZ];
743         char dirname[SIZ];
744         int flags, floor, order, view, flags2;
745
746         serv_puts("GETR");
747         serv_gets(buf);
748         if (buf[0] != '2') return(0);
749
750         extract(name, &buf[4], 0);
751         extract(password, &buf[4], 1);
752         extract(dirname, &buf[4], 2);
753         flags = extract_int(&buf[4], 3);
754         floor = extract_int(&buf[4], 4);
755         order = extract_int(&buf[4], 5);
756         view = extract_int(&buf[4], 6);
757         flags2 = extract_int(&buf[4], 7);
758
759         if (flags2 & QR2_SELFLIST) {
760                 current_value = 1;
761         }
762         else {
763                 current_value = 0;
764         }
765
766         if (newval == 1) {
767                 flags2 = flags2 | QR2_SELFLIST;
768         }
769         else if (newval == 0) {
770                 flags2 = flags2 & ~QR2_SELFLIST;
771         }
772         else {
773                 return(current_value);
774         }
775
776         if (newval != current_value) {
777                 serv_printf("SETR %s|%s|%s|%d|0|%d|%d|%d|%d",
778                         name, password, dirname, flags,
779                         floor, order, view, flags2);
780                 serv_gets(buf);
781         }
782
783         return(newval);
784
785 }
786
787
788
789
790
791
792 /*
793  * display the form for editing a room
794  */
795 void display_editroom(void)
796 {
797         char buf[SIZ];
798         char cmd[SIZ];
799         char node[SIZ];
800         char remote_room[SIZ];
801         char recp[SIZ];
802         char er_name[20];
803         char er_password[10];
804         char er_dirname[15];
805         char er_roomaide[26];
806         unsigned er_flags;
807         int er_floor;
808         int i, j;
809         char *tab;
810         char *shared_with;
811         char *not_shared_with;
812         int roompolicy = 0;
813         int roomvalue = 0;
814         int floorpolicy = 0;
815         int floorvalue = 0;
816
817         tab = bstr("tab");
818         if (strlen(tab) == 0) tab = "admin";
819
820         load_floorlist();
821         serv_puts("GETR");
822         serv_gets(buf);
823
824         if (buf[0] != '2') {
825                 strcpy(WC->ImportantMessage, &buf[4]);
826                 display_main_menu();
827                 return;
828         }
829         extract(er_name, &buf[4], 0);
830         extract(er_password, &buf[4], 1);
831         extract(er_dirname, &buf[4], 2);
832         er_flags = extract_int(&buf[4], 3);
833         er_floor = extract_int(&buf[4], 4);
834
835         output_headers(1, 1, 1, 0, 0, 0, 0);
836
837         /* print the tabbed dialog */
838         wprintf("<br />"
839                 "<div id=\"fix_scrollbar_bug\">"
840                 "<TABLE border=0 cellspacing=0 cellpadding=0 width=100%%>"
841                 "<TR ALIGN=CENTER>"
842                 "<TD>&nbsp;</TD>\n");
843
844         if (!strcmp(tab, "admin")) {
845                 wprintf("<TD BGCOLOR=\"#FFFFFF\"><SPAN CLASS=\"tablabel\">");
846         }
847         else {
848                 wprintf("<TD BGCOLOR=\"#CCCCCC\"><A HREF=\"/display_editroom&tab=admin\">");
849         }
850         wprintf("Administration");
851         if (!strcmp(tab, "admin")) {
852                 wprintf("</SPAN></TD>\n");
853         }
854         else {
855                 wprintf("</A></TD>\n");
856         }
857
858         wprintf("<TD>&nbsp;</TD>\n");
859
860         if (!strcmp(tab, "config")) {
861                 wprintf("<TD BGCOLOR=\"#FFFFFF\"><SPAN CLASS=\"tablabel\">");
862         }
863         else {
864                 wprintf("<TD BGCOLOR=\"#CCCCCC\"><A HREF=\"/display_editroom&tab=config\">");
865         }
866         wprintf("Configuration");
867         if (!strcmp(tab, "config")) {
868                 wprintf("</SPAN></TD>\n");
869         }
870         else {
871                 wprintf("</A></TD>\n");
872         }
873
874         wprintf("<TD>&nbsp;</TD>\n");
875
876         if (!strcmp(tab, "expire")) {
877                 wprintf("<TD BGCOLOR=\"#FFFFFF\"><SPAN CLASS=\"tablabel\">");
878         }
879         else {
880                 wprintf("<TD BGCOLOR=\"#CCCCCC\"><A HREF=\"/display_editroom&tab=expire\">");
881         }
882         wprintf("Message expire policy");
883         if (!strcmp(tab, "expire")) {
884                 wprintf("</SPAN></TD>\n");
885         }
886         else {
887                 wprintf("</A></TD>\n");
888         }
889
890         wprintf("<TD>&nbsp;</TD>\n");
891
892         if (!strcmp(tab, "access")) {
893                 wprintf("<TD BGCOLOR=\"#FFFFFF\"><SPAN CLASS=\"tablabel\">");
894         }
895         else {
896                 wprintf("<TD BGCOLOR=\"#CCCCCC\"><A HREF=\"/display_editroom&tab=access\">");
897         }
898         wprintf("Access controls");
899         if (!strcmp(tab, "access")) {
900                 wprintf("</SPAN></TD>\n");
901         }
902         else {
903                 wprintf("</A></TD>\n");
904         }
905
906         wprintf("<TD>&nbsp;</TD>\n");
907
908         if (!strcmp(tab, "sharing")) {
909                 wprintf("<TD BGCOLOR=\"#FFFFFF\"><SPAN CLASS=\"tablabel\">");
910         }
911         else {
912                 wprintf("<TD BGCOLOR=\"#CCCCCC\"><A HREF=\"/display_editroom&tab=sharing\">");
913         }
914         wprintf("Sharing");
915         if (!strcmp(tab, "sharing")) {
916                 wprintf("</SPAN></TD>\n");
917         }
918         else {
919                 wprintf("</A></TD>\n");
920         }
921
922         wprintf("<TD>&nbsp;</TD>\n");
923
924         if (!strcmp(tab, "listserv")) {
925                 wprintf("<TD BGCOLOR=\"#FFFFFF\"><SPAN CLASS=\"tablabel\">");
926         }
927         else {
928                 wprintf("<TD BGCOLOR=\"#CCCCCC\"><A HREF=\"/display_editroom&tab=listserv\">");
929         }
930         wprintf("Mailing list service");
931         if (!strcmp(tab, "listserv")) {
932                 wprintf("</SPAN></TD>\n");
933         }
934         else {
935                 wprintf("</A></TD>\n");
936         }
937
938         wprintf("<TD>&nbsp;</TD>\n");
939
940         wprintf("</TR></TABLE></div>\n");
941         /* end tabbed dialog */ 
942
943         /* begin content of whatever tab is open now */
944         wprintf("<div id=\"fix_scrollbar_bug\">"
945                 "<TABLE border=0 width=100%% bgcolor=\"#FFFFFF\">\n"
946                 "<TR><TD>\n");
947
948         if (!strcmp(tab, "admin")) {
949                 wprintf("<UL>"
950                         "<LI><A HREF=\"/confirm_delete_room\">\n"
951                         "Delete this room</A>\n"
952                         "<LI><A HREF=\"/display_editroompic\">\n"
953                         "Set or change the graphic for this room's banner</A>\n"
954                         "<LI><A HREF=\"/display_editinfo\">\n"
955                         "Edit this room's Info file</A>\n"
956                         "</UL>");
957         }
958
959         if (!strcmp(tab, "config")) {
960                 wprintf("<FORM METHOD=\"POST\" ACTION=\"/editroom\">\n");
961         
962                 wprintf("<UL><LI>Name of room: ");
963                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", er_name);
964         
965                 wprintf("<LI>Resides on floor: ");
966                 wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
967                 for (i = 0; i < 128; ++i)
968                         if (strlen(floorlist[i]) > 0) {
969                                 wprintf("<OPTION ");
970                                 if (i == er_floor)
971                                         wprintf("SELECTED ");
972                                 wprintf("VALUE=\"%d\">", i);
973                                 escputs(floorlist[i]);
974                                 wprintf("</OPTION>\n");
975                         }
976                 wprintf("</SELECT>\n");
977         
978                 wprintf("<LI>Type of room:<UL>\n");
979
980                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
981                 if ((er_flags & QR_PRIVATE) == 0)
982                 wprintf("CHECKED ");
983                 wprintf("> Public room\n");
984
985                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"hidden\" ");
986                 if ((er_flags & QR_PRIVATE) &&
987                     (er_flags & QR_GUESSNAME))
988                         wprintf("CHECKED ");
989                 wprintf("> Private - guess name\n");
990         
991                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
992                 if ((er_flags & QR_PRIVATE) &&
993                     (er_flags & QR_PASSWORDED))
994                         wprintf("CHECKED ");
995                 wprintf("> Private - require password:\n");
996                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" VALUE=\"%s\" MAXLENGTH=\"9\">\n", er_password);
997         
998                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
999                 if ((er_flags & QR_PRIVATE)
1000                     && ((er_flags & QR_GUESSNAME) == 0)
1001                     && ((er_flags & QR_PASSWORDED) == 0))
1002                         wprintf("CHECKED ");
1003                 wprintf("> Private - invitation only\n");
1004         
1005                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"bump\" VALUE=\"yes\" ");
1006                 wprintf("> If private, cause current users to forget room\n");
1007         
1008                 wprintf("</UL>\n");
1009         
1010                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"prefonly\" VALUE=\"yes\" ");
1011                 if (er_flags & QR_PREFONLY)
1012                         wprintf("CHECKED ");
1013                 wprintf("> Preferred users only\n");
1014         
1015                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"readonly\" VALUE=\"yes\" ");
1016                 if (er_flags & QR_READONLY)
1017                         wprintf("CHECKED ");
1018                 wprintf("> Read-only room\n");
1019         
1020         /* directory stuff */
1021                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"directory\" VALUE=\"yes\" ");
1022                 if (er_flags & QR_DIRECTORY)
1023                         wprintf("CHECKED ");
1024                 wprintf("> File directory room\n");
1025
1026                 wprintf("<UL><LI>Directory name: ");
1027                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_dirname\" VALUE=\"%s\" MAXLENGTH=\"14\">\n", er_dirname);
1028
1029                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"ulallowed\" VALUE=\"yes\" ");
1030                 if (er_flags & QR_UPLOAD)
1031                         wprintf("CHECKED ");
1032                 wprintf("> Uploading allowed\n");
1033         
1034                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"dlallowed\" VALUE=\"yes\" ");
1035                 if (er_flags & QR_DOWNLOAD)
1036                         wprintf("CHECKED ");
1037                 wprintf("> Downloading allowed\n");
1038         
1039                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"visdir\" VALUE=\"yes\" ");
1040                 if (er_flags & QR_VISDIR)
1041                         wprintf("CHECKED ");
1042                 wprintf("> Visible directory</UL>\n");
1043         
1044         /* end of directory stuff */
1045         
1046                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"network\" VALUE=\"yes\" ");
1047                 if (er_flags & QR_NETWORK)
1048                         wprintf("CHECKED ");
1049                 wprintf("> Network shared room\n");
1050
1051                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"permanent\" VALUE=\"yes\" ");
1052                 if (er_flags & QR_PERMANENT)
1053                         wprintf("CHECKED ");
1054                 wprintf("> Permanent (does not auto-purge)\n");
1055
1056         /* start of anon options */
1057         
1058                 wprintf("<LI>Anonymous messages<UL>\n");
1059         
1060                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"no\" ");
1061                 if (((er_flags & QR_ANONONLY) == 0)
1062                     && ((er_flags & QR_ANONOPT) == 0))
1063                         wprintf("CHECKED ");
1064                 wprintf("> No anonymous messages\n");
1065         
1066                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anononly\" ");
1067                 if (er_flags & QR_ANONONLY)
1068                         wprintf("CHECKED ");
1069                 wprintf("> All messages are anonymous\n");
1070         
1071                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anon2\" ");
1072                 if (er_flags & QR_ANONOPT)
1073                         wprintf("CHECKED ");
1074                 wprintf("> Prompt user when entering messages</UL>\n");
1075         
1076         /* end of anon options */
1077         
1078                 wprintf("<LI>Room aide: \n");
1079                 serv_puts("GETA");
1080                 serv_gets(buf);
1081                 if (buf[0] != '2') {
1082                         wprintf("<EM>%s</EM>\n", &buf[4]);
1083                 } else {
1084                         extract(er_roomaide, &buf[4], 0);
1085                         wprintf("<INPUT TYPE=\"text\" NAME=\"er_roomaide\" VALUE=\"%s\" MAXLENGTH=\"25\">\n", er_roomaide);
1086                 }
1087         
1088                 wprintf("</UL><CENTER>\n");
1089                 wprintf("<INPUT TYPE=\"hidden\" NAME=\"tab\" VALUE=\"config\">\n"
1090                         "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">"
1091                         "&nbsp;"
1092                         "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">"
1093                         "</CENTER>\n"
1094                 );
1095         }
1096
1097
1098         /* Sharing the room with other Citadel nodes... */
1099         if (!strcmp(tab, "sharing")) {
1100
1101                 shared_with = strdup("");
1102                 not_shared_with = strdup("");
1103
1104                 /* Learn the current configuration */
1105                 serv_puts("CONF getsys|application/x-citadel-ignet-config");
1106                 serv_gets(buf);
1107                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
1108                         extract(node, buf, 0);
1109                         not_shared_with = realloc(not_shared_with,
1110                                         strlen(not_shared_with) + 32);
1111                         strcat(not_shared_with, node);
1112                         strcat(not_shared_with, "\n");
1113                 }
1114
1115                 serv_puts("GNET");
1116                 serv_gets(buf);
1117                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
1118                         extract(cmd, buf, 0);
1119                         extract(node, buf, 1);
1120                         extract(remote_room, buf, 2);
1121                         if (!strcasecmp(cmd, "ignet_push_share")) {
1122                                 shared_with = realloc(shared_with,
1123                                                 strlen(shared_with) + 32);
1124                                 strcat(shared_with, node);
1125                                 if (strlen(remote_room) > 0) {
1126                                         strcat(shared_with, "|");
1127                                         strcat(shared_with, remote_room);
1128                                 }
1129                                 strcat(shared_with, "\n");
1130                         }
1131                 }
1132
1133                 for (i=0; i<num_tokens(shared_with, '\n'); ++i) {
1134                         extract_token(buf, shared_with, i, '\n');
1135                         extract_token(node, buf, 0, '|');
1136                         for (j=0; j<num_tokens(not_shared_with, '\n'); ++j) {
1137                                 extract_token(cmd, not_shared_with, j, '\n');
1138                                 if (!strcasecmp(node, cmd)) {
1139                                         remove_token(not_shared_with, j, '\n');
1140                                 }
1141                         }
1142                 }
1143
1144                 /* Display the stuff */
1145                 wprintf("<CENTER><br />"
1146                         "<TABLE border=1 cellpadding=5><TR>"
1147                         "<TD><B><I>Shared with</I></B></TD>"
1148                         "<TD><B><I>Not shared with</I></B></TD></TR>\n"
1149                         "<TR><TD VALIGN=TOP>\n");
1150
1151                 wprintf("<TABLE border=0 cellpadding=5><TR BGCOLOR=\"#CCCCCC\">"
1152                         "<TD>Remote node name</TD>"
1153                         "<TD>Remote room name</TD>"
1154                         "<TD>Actions</TD>"
1155                         "</TR>\n"
1156                 );
1157
1158                 for (i=0; i<num_tokens(shared_with, '\n'); ++i) {
1159                         extract_token(buf, shared_with, i, '\n');
1160                         extract_token(node, buf, 0, '|');
1161                         extract_token(remote_room, buf, 1, '|');
1162                         if (strlen(node) > 0) {
1163                                 wprintf("<FORM METHOD=\"POST\" "
1164                                         "ACTION=\"/netedit\">"
1165                                         "<TR><TD>%s</TD>\n", node);
1166
1167                                 wprintf("<TD>");
1168                                 if (strlen(remote_room) > 0) {
1169                                         escputs(remote_room);
1170                                 }
1171                                 wprintf("</TD>");
1172
1173                                 wprintf("<TD>");
1174                 
1175                                 wprintf("<INPUT TYPE=\"hidden\" NAME=\"line\" "
1176                                         "VALUE=\"ignet_push_share|");
1177                                 urlescputs(node);
1178                                 if (strlen(remote_room) > 0) {
1179                                         wprintf("|");
1180                                         urlescputs(remote_room);
1181                                 }
1182                                 wprintf("\">");
1183                                 wprintf("<INPUT TYPE=\"hidden\" NAME=\"tab\" "
1184                                         "VALUE=\"sharing\">\n");
1185                                 wprintf("<INPUT TYPE=\"hidden\" NAME=\"cmd\" "
1186                                         "VALUE=\"remove\">\n");
1187                                 wprintf("<INPUT TYPE=\"submit\" "
1188                                         "NAME=\"sc\" VALUE=\"Unshare\">");
1189                                 wprintf("</TD></TR></FORM>\n");
1190                         }
1191                 }
1192
1193                 wprintf("</TABLE>\n");
1194                 wprintf("</TD><TD VALIGN=TOP>\n");
1195                 wprintf("<TABLE border=0 cellpadding=5><TR BGCOLOR=\"#CCCCCC\">"
1196                         "<TD>Remote node name</TD>"
1197                         "<TD>Remote room name</TD>"
1198                         "<TD>Actions</TD>"
1199                         "</TR>\n"
1200                 );
1201
1202                 for (i=0; i<num_tokens(not_shared_with, '\n'); ++i) {
1203                         extract_token(node, not_shared_with, i, '\n');
1204                         if (strlen(node) > 0) {
1205                                 wprintf("<FORM METHOD=\"POST\" "
1206                                         "ACTION=\"/netedit\">"
1207                                         "<TR><TD>");
1208                                 escputs(node);
1209                                 wprintf("</TD><TD>"
1210                                         "<INPUT TYPE=\"INPUT\" "
1211                                         "NAME=\"suffix\" "
1212                                         "MAXLENGTH=128>"
1213                                         "</TD><TD>");
1214                                 wprintf("<INPUT TYPE=\"hidden\" "
1215                                         "NAME=\"line\" "
1216                                         "VALUE=\"ignet_push_share|");
1217                                 urlescputs(node);
1218                                 wprintf("|\">");
1219                                 wprintf("<INPUT TYPE=\"hidden\" NAME=\"tab\" "
1220                                         "VALUE=\"sharing\">\n");
1221                                 wprintf("<INPUT TYPE=\"hidden\" NAME=\"cmd\" "
1222                                         "VALUE=\"add\">\n");
1223                                 wprintf("<INPUT TYPE=\"submit\" "
1224                                         "NAME=\"sc\" VALUE=\"Share\">");
1225                                 wprintf("</TD></TR></FORM>\n");
1226                         }
1227                 }
1228
1229                 wprintf("</TABLE>\n");
1230                 wprintf("</TD></TR>"
1231                         "</TABLE></CENTER><br />\n"
1232                         "<I><B>Notes:</B><UL><LI>When sharing a room, "
1233                         "it must be shared from both ends.  Adding a node to "
1234                         "the 'shared' list sends messages out, but in order to"
1235                         " receive messages, the other nodes must be configured"
1236                         " to send messages out to your system as well.\n"
1237                         "<LI>If the remote room name is blank, it is assumed "
1238                         "that the room name is identical on the remote node."
1239                         "<LI>If the remote room name is different, the remote "
1240                         "node must also configure the name of the room here."
1241                         "</UL></I><br />\n"
1242                 );
1243
1244         }
1245
1246         /* Mailing list management */
1247         if (!strcmp(tab, "listserv")) {
1248
1249                 wprintf("<br /><center>"
1250                         "<TABLE BORDER=0 WIDTH=100%% CELLPADDING=5>"
1251                         "<TR><TD VALIGN=TOP>");
1252
1253                 wprintf("<i>The contents of this room are being "
1254                         "mailed <b>as individual messages</b> "
1255                         "to the following list recipients:"
1256                         "</i><br /><br />\n");
1257
1258                 serv_puts("GNET");
1259                 serv_gets(buf);
1260                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
1261                         extract(cmd, buf, 0);
1262                         if (!strcasecmp(cmd, "listrecp")) {
1263                                 extract(recp, buf, 1);
1264                         
1265                                 escputs(recp);
1266                                 wprintf(" <A HREF=\"/netedit&cmd=remove&line="
1267                                         "listrecp|");
1268                                 urlescputs(recp);
1269                                 wprintf("&tab=listserv\">(remove)</A><br />");
1270
1271                         }
1272                 }
1273                 wprintf("<br /><FORM METHOD=\"POST\" ACTION=\"/netedit\">\n"
1274                         "<INPUT TYPE=\"hidden\" NAME=\"tab\" VALUE=\"listserv\">\n"
1275                         "<INPUT TYPE=\"hidden\" NAME=\"prefix\" VALUE=\"listrecp|\">\n");
1276                 wprintf("<INPUT TYPE=\"text\" NAME=\"line\">\n");
1277                 wprintf("<INPUT TYPE=\"submit\" NAME=\"cmd\" VALUE=\"Add\">");
1278                 wprintf("</FORM>\n");
1279
1280                 wprintf("</TD><TD VALIGN=TOP>\n");
1281                 
1282                 wprintf("<i>The contents of this room are being "
1283                         "mailed <b>in digest form</b> "
1284                         "to the following list recipients:"
1285                         "</i><br /><br />\n");
1286
1287                 serv_puts("GNET");
1288                 serv_gets(buf);
1289                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
1290                         extract(cmd, buf, 0);
1291                         if (!strcasecmp(cmd, "digestrecp")) {
1292                                 extract(recp, buf, 1);
1293                         
1294                                 escputs(recp);
1295                                 wprintf(" <A HREF=\"/netedit&cmd=remove&line="
1296                                         "digestrecp|");
1297                                 urlescputs(recp);
1298                                 wprintf("&tab=listserv\">(remove)</A><br />");
1299
1300                         }
1301                 }
1302                 wprintf("<br /><FORM METHOD=\"POST\" ACTION=\"/netedit\">\n"
1303                         "<INPUT TYPE=\"hidden\" NAME=\"tab\" VALUE=\"listserv\">\n"
1304                         "<INPUT TYPE=\"hidden\" NAME=\"prefix\" VALUE=\"digestrecp|\">\n");
1305                 wprintf("<INPUT TYPE=\"text\" NAME=\"line\">\n");
1306                 wprintf("<INPUT TYPE=\"submit\" NAME=\"cmd\" VALUE=\"Add\">");
1307                 wprintf("</FORM>\n");
1308                 
1309                 wprintf("</TD></TR></TABLE><hr />\n");
1310
1311                 if (self_service(999) == 1) {
1312                         wprintf("This room is configured to allow "
1313                                 "self-service subscribe/unsubscribe requests."
1314                                 " <A HREF=\"/toggle_self_service?newval=0&"
1315                                 "tab=listserv\">"
1316                                 "Click to disable.</A><br />\n"
1317                                 "The URL for subscribe/unsubscribe is: "
1318                                 "<TT>http://%s/listsub</TT><br />\n",
1319                                 WC->http_host
1320                         );
1321                 }
1322                 else {
1323                         wprintf("This room is <i>not</i> configured to allow "
1324                                 "self-service subscribe/unsubscribe requests."
1325                                 " <A HREF=\"/toggle_self_service?newval=1&"
1326                                 "tab=listserv\">"
1327                                 "Click to enable.</A><br />\n"
1328                         );
1329                 }
1330
1331
1332                 wprintf("</CENTER>\n");
1333         }
1334
1335
1336         /* Mailing list management */
1337         if (!strcmp(tab, "expire")) {
1338
1339                 serv_puts("GPEX room");
1340                 serv_gets(buf);
1341                 if (buf[0] == '2') {
1342                         roompolicy = extract_int(&buf[4], 0);
1343                         roomvalue = extract_int(&buf[4], 1);
1344                 }
1345                 
1346                 serv_puts("GPEX floor");
1347                 serv_gets(buf);
1348                 if (buf[0] == '2') {
1349                         floorpolicy = extract_int(&buf[4], 0);
1350                         floorvalue = extract_int(&buf[4], 1);
1351                 }
1352                 
1353                 wprintf("<br /><FORM METHOD=\"POST\" ACTION=\"/set_room_policy\">\n");
1354                 wprintf("<TABLE border=0 cellspacing=5>\n");
1355                 wprintf("<TR><TD>Message expire policy for this room<br />(");
1356                 escputs(WC->wc_roomname);
1357                 wprintf(")</TD><TD>");
1358                 wprintf("<INPUT TYPE=\"radio\" NAME=\"roompolicy\" VALUE=\"0\" %s>",
1359                         ((roompolicy == 0) ? "CHECKED" : "") );
1360                 wprintf("Use the default policy for this floor<br />\n");
1361                 wprintf("<INPUT TYPE=\"radio\" NAME=\"roompolicy\" VALUE=\"1\" %s>",
1362                         ((roompolicy == 1) ? "CHECKED" : "") );
1363                 wprintf("Never automatically expire messages<br />\n");
1364                 wprintf("<INPUT TYPE=\"radio\" NAME=\"roompolicy\" VALUE=\"2\" %s>",
1365                         ((roompolicy == 2) ? "CHECKED" : "") );
1366                 wprintf("Expire by message count<br />\n");
1367                 wprintf("<INPUT TYPE=\"radio\" NAME=\"roompolicy\" VALUE=\"3\" %s>",
1368                         ((roompolicy == 3) ? "CHECKED" : "") );
1369                 wprintf("Expire by message age<br />");
1370                 wprintf("Number of messages or days: ");
1371                 wprintf("<INPUT TYPE=\"text\" NAME=\"roomvalue\" MAXLENGTH=\"5\" VALUE=\"%d\">", roomvalue);
1372                 wprintf("</TD></TR>\n");
1373
1374                 if (WC->axlevel >= 6) {
1375                         wprintf("<TR><TD COLSPAN=2><hr /></TD></TR>\n");
1376                         wprintf("<TR><TD>Message expire policy for this floor<br />(");
1377                         escputs(floorlist[WC->wc_floor]);
1378                         wprintf(")</TD><TD>");
1379                         wprintf("<INPUT TYPE=\"radio\" NAME=\"floorpolicy\" VALUE=\"0\" %s>",
1380                                 ((floorpolicy == 0) ? "CHECKED" : "") );
1381                         wprintf("Use the system default<br />\n");
1382                         wprintf("<INPUT TYPE=\"radio\" NAME=\"floorpolicy\" VALUE=\"1\" %s>",
1383                                 ((floorpolicy == 1) ? "CHECKED" : "") );
1384                         wprintf("Never automatically expire messages<br />\n");
1385                         wprintf("<INPUT TYPE=\"radio\" NAME=\"floorpolicy\" VALUE=\"2\" %s>",
1386                                 ((floorpolicy == 2) ? "CHECKED" : "") );
1387                         wprintf("Expire by message count<br />\n");
1388                         wprintf("<INPUT TYPE=\"radio\" NAME=\"floorpolicy\" VALUE=\"3\" %s>",
1389                                 ((floorpolicy == 3) ? "CHECKED" : "") );
1390                         wprintf("Expire by message age<br />");
1391                         wprintf("Number of messages or days: ");
1392                         wprintf("<INPUT TYPE=\"text\" NAME=\"floorvalue\" MAXLENGTH=\"5\" VALUE=\"%d\">",
1393                                 floorvalue);
1394                 }
1395
1396                 wprintf("<CENTER>\n");
1397                 wprintf("<TR><TD COLSPAN=2><hr /><CENTER>\n");
1398                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1399                 wprintf("&nbsp;");
1400                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1401                 wprintf("</CENTER></TD><TR>\n");
1402
1403                 wprintf("</TABLE>\n"
1404                         "<INPUT TYPE=\"hidden\" NAME=\"tab\" VALUE=\"expire\">\n"
1405                         "</FORM>\n"
1406                 );
1407
1408         }
1409
1410         /* Mailing list management */
1411         if (!strcmp(tab, "access")) {
1412                 display_whok();
1413         }
1414
1415         /* end content of whatever tab is open now */
1416         wprintf("</TD></TR></TABLE></div>\n");
1417
1418         wDumpContent(1);
1419 }
1420
1421
1422 /* 
1423  * Toggle self-service list subscription
1424  */
1425 void toggle_self_service(void) {
1426         int newval = 0;
1427
1428         newval = atoi(bstr("newval"));
1429         self_service(newval);
1430         display_editroom();
1431 }
1432
1433
1434
1435 /*
1436  * save new parameters for a room
1437  */
1438 void editroom(void)
1439 {
1440         char buf[SIZ];
1441         char er_name[20];
1442         char er_password[10];
1443         char er_dirname[15];
1444         char er_roomaide[26];
1445         int er_floor;
1446         unsigned er_flags;
1447         int bump;
1448
1449
1450         if (strcmp(bstr("sc"), "OK")) {
1451                 strcpy(WC->ImportantMessage,
1452                         "Cancelled.  Changes were not saved.");
1453                 display_editroom();
1454                 return;
1455         }
1456         serv_puts("GETR");
1457         serv_gets(buf);
1458
1459         if (buf[0] != '2') {
1460                 strcpy(WC->ImportantMessage, &buf[4]);
1461                 display_editroom();
1462                 return;
1463         }
1464         extract(er_name, &buf[4], 0);
1465         extract(er_password, &buf[4], 1);
1466         extract(er_dirname, &buf[4], 2);
1467         er_flags = extract_int(&buf[4], 3);
1468
1469         strcpy(er_roomaide, bstr("er_roomaide"));
1470         if (strlen(er_roomaide) == 0) {
1471                 serv_puts("GETA");
1472                 serv_gets(buf);
1473                 if (buf[0] != '2') {
1474                         strcpy(er_roomaide, "");
1475                 } else {
1476                         extract(er_roomaide, &buf[4], 0);
1477                 }
1478         }
1479         strcpy(buf, bstr("er_name"));
1480         buf[20] = 0;
1481         if (strlen(buf) > 0)
1482                 strcpy(er_name, buf);
1483
1484         strcpy(buf, bstr("er_password"));
1485         buf[10] = 0;
1486         if (strlen(buf) > 0)
1487                 strcpy(er_password, buf);
1488
1489         strcpy(buf, bstr("er_dirname"));
1490         buf[15] = 0;
1491         if (strlen(buf) > 0)
1492                 strcpy(er_dirname, buf);
1493
1494         strcpy(buf, bstr("type"));
1495         er_flags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
1496
1497         if (!strcmp(buf, "invonly")) {
1498                 er_flags |= (QR_PRIVATE);
1499         }
1500         if (!strcmp(buf, "hidden")) {
1501                 er_flags |= (QR_PRIVATE | QR_GUESSNAME);
1502         }
1503         if (!strcmp(buf, "passworded")) {
1504                 er_flags |= (QR_PRIVATE | QR_PASSWORDED);
1505         }
1506         if (!strcmp(bstr("prefonly"), "yes")) {
1507                 er_flags |= QR_PREFONLY;
1508         } else {
1509                 er_flags &= ~QR_PREFONLY;
1510         }
1511
1512         if (!strcmp(bstr("readonly"), "yes")) {
1513                 er_flags |= QR_READONLY;
1514         } else {
1515                 er_flags &= ~QR_READONLY;
1516         }
1517
1518         if (!strcmp(bstr("permanent"), "yes")) {
1519                 er_flags |= QR_PERMANENT;
1520         } else {
1521                 er_flags &= ~QR_PERMANENT;
1522         }
1523
1524         if (!strcmp(bstr("network"), "yes")) {
1525                 er_flags |= QR_NETWORK;
1526         } else {
1527                 er_flags &= ~QR_NETWORK;
1528         }
1529
1530         if (!strcmp(bstr("directory"), "yes")) {
1531                 er_flags |= QR_DIRECTORY;
1532         } else {
1533                 er_flags &= ~QR_DIRECTORY;
1534         }
1535
1536         if (!strcmp(bstr("ulallowed"), "yes")) {
1537                 er_flags |= QR_UPLOAD;
1538         } else {
1539                 er_flags &= ~QR_UPLOAD;
1540         }
1541
1542         if (!strcmp(bstr("dlallowed"), "yes")) {
1543                 er_flags |= QR_DOWNLOAD;
1544         } else {
1545                 er_flags &= ~QR_DOWNLOAD;
1546         }
1547
1548         if (!strcmp(bstr("visdir"), "yes")) {
1549                 er_flags |= QR_VISDIR;
1550         } else {
1551                 er_flags &= ~QR_VISDIR;
1552         }
1553
1554         strcpy(buf, bstr("anon"));
1555
1556         er_flags &= ~(QR_ANONONLY | QR_ANONOPT);
1557         if (!strcmp(buf, "anononly"))
1558                 er_flags |= QR_ANONONLY;
1559         if (!strcmp(buf, "anon2"))
1560                 er_flags |= QR_ANONOPT;
1561
1562         bump = 0;
1563         if (!strcmp(bstr("bump"), "yes"))
1564                 bump = 1;
1565
1566         er_floor = atoi(bstr("er_floor"));
1567
1568         sprintf(buf, "SETR %s|%s|%s|%u|%d|%d",
1569              er_name, er_password, er_dirname, er_flags, bump, er_floor);
1570         serv_puts(buf);
1571         serv_gets(buf);
1572         if (buf[0] != '2') {
1573                 strcpy(WC->ImportantMessage, &buf[4]);
1574                 display_editroom();
1575                 return;
1576         }
1577         gotoroom(er_name);
1578
1579         if (strlen(er_roomaide) > 0) {
1580                 sprintf(buf, "SETA %s", er_roomaide);
1581                 serv_puts(buf);
1582                 serv_gets(buf);
1583                 if (buf[0] != '2') {
1584                         strcpy(WC->ImportantMessage, &buf[4]);
1585                         display_main_menu();
1586                         return;
1587                 }
1588         }
1589         gotoroom(er_name);
1590         strcpy(WC->ImportantMessage, "Your changes have been saved.");
1591         display_editroom();
1592         return;
1593 }
1594
1595
1596 /*
1597  * Display form for Invite, Kick, and show Who Knows a room
1598  */
1599 void do_invt_kick(void) {
1600         char buf[SIZ], room[SIZ], username[SIZ];
1601
1602         serv_puts("GETR");
1603         serv_gets(buf);
1604
1605         if (buf[0] != '2') {
1606                 escputs(&buf[4]);
1607                 return;
1608         }
1609         extract(room, &buf[4], 0);
1610
1611         strcpy(username, bstr("username"));
1612
1613         if (!strcmp(bstr("sc"), "Kick")) {
1614                 sprintf(buf, "KICK %s", username);
1615                 serv_puts(buf);
1616                 serv_gets(buf);
1617
1618                 if (buf[0] != '2') {
1619                         strcpy(WC->ImportantMessage, &buf[4]);
1620                 } else {
1621                         sprintf(WC->ImportantMessage,
1622                                 "<B><I>User %s kicked out of room %s.</I></B>\n", 
1623                                 username, room);
1624                 }
1625         }
1626
1627         if (!strcmp(bstr("sc"), "Invite")) {
1628                 sprintf(buf, "INVT %s", username);
1629                 serv_puts(buf);
1630                 serv_gets(buf);
1631
1632                 if (buf[0] != '2') {
1633                         strcpy(WC->ImportantMessage, &buf[4]);
1634                 } else {
1635                         sprintf(WC->ImportantMessage,
1636                                 "<B><I>User %s invited to room %s.</I></B>\n", 
1637                                 username, room);
1638                 }
1639         }
1640
1641         display_editroom();
1642 }
1643
1644
1645
1646 /*
1647  * Display form for Invite, Kick, and show Who Knows a room
1648  */
1649 void display_whok(void)
1650 {
1651         char buf[SIZ], room[SIZ], username[SIZ];
1652
1653         serv_puts("GETR");
1654         serv_gets(buf);
1655
1656         if (buf[0] != '2') {
1657                 escputs(&buf[4]);
1658                 return;
1659         }
1660         extract(room, &buf[4], 0);
1661
1662         
1663         wprintf("<TABLE border=0 CELLSPACING=10><TR VALIGN=TOP>"
1664                 "<TD>The users listed below have access to this room.  "
1665                 "To remove a user from the access list, select the user "
1666                 "name from the list and click 'Kick'.<br /><br />");
1667         
1668         wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/do_invt_kick\">\n");
1669         wprintf("<INPUT TYPE=\"hidden\" NAME=\"tab\" VALUE=\"access\">\n");
1670         wprintf("<SELECT NAME=\"username\" SIZE=\"10\" style=\"width:100%%\">\n");
1671         serv_puts("WHOK");
1672         serv_gets(buf);
1673         if (buf[0] == '1') {
1674                 while (serv_gets(buf), strcmp(buf, "000")) {
1675                         extract(username, buf, 0);
1676                         wprintf("<OPTION>");
1677                         escputs(username);
1678                         wprintf("\n");
1679                 }
1680         }
1681         wprintf("</SELECT><br />\n");
1682
1683         wprintf("<input type=submit name=sc value=\"Kick\">");
1684         wprintf("</FORM></CENTER>\n");
1685
1686         wprintf("</TD><TD>"
1687                 "To grant another user access to this room, enter the "
1688                 "user name in the box below and click 'Invite'.<br /><br />");
1689
1690         wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/do_invt_kick\">\n");
1691         wprintf("<INPUT TYPE=\"hidden\" NAME=\"tab\" VALUE=\"access\">\n");
1692         wprintf("Invite: ");
1693         wprintf("<input type=\"text\" name=\"username\" style=\"width:100%%\"><br />\n"
1694                 "<input type=\"hidden\" name=\"sc\" value=\"Invite\">"
1695                 "<input type=\"submit\" value=\"Invite\">"
1696                 "</FORM></CENTER>\n");
1697
1698         wprintf("</TD></TR></TABLE>\n");
1699         wDumpContent(1);
1700 }
1701
1702
1703
1704 /*
1705  * display the form for entering a new room
1706  */
1707 void display_entroom(void)
1708 {
1709         int i;
1710         char buf[SIZ];
1711
1712         serv_puts("CRE8 0");
1713         serv_gets(buf);
1714
1715         if (buf[0] != '2') {
1716                 strcpy(WC->ImportantMessage, &buf[4]);
1717                 display_main_menu();
1718                 return;
1719         }
1720
1721         output_headers(1, 1, 2, 0, 0, 0, 0);
1722         wprintf("<div id=\"banner\">\n"
1723                 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
1724                 "<SPAN CLASS=\"titlebar\">Create a new room</SPAN>"
1725                 "</TD></TR></TABLE>\n"
1726                 "</div>\n<div id=\"content\">\n"
1727         );
1728
1729         wprintf("<div id=\"fix_scrollbar_bug\">"
1730                 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
1731
1732         wprintf("<form name=\"create_room_form\" method=\"POST\" action=\"/entroom\">\n");
1733
1734         wprintf("<UL><LI>Name of room: ");
1735         wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" MAXLENGTH=\"127\">\n");
1736
1737         wprintf("<LI>Resides on floor: ");
1738         load_floorlist(); 
1739         wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
1740         for (i = 0; i < 128; ++i)
1741                 if (strlen(floorlist[i]) > 0) {
1742                         wprintf("<OPTION ");
1743                         wprintf("VALUE=\"%d\">", i);
1744                         escputs(floorlist[i]);
1745                         wprintf("</OPTION>\n");
1746                 }
1747         wprintf("</SELECT>\n");
1748
1749         /* Our clever little snippet of JavaScript automatically selects
1750          * a public room if the view is set to Bulletin Board, and it
1751          * selects a mailbox room otherwise.  The user can override this,
1752          * of course.
1753          */
1754         wprintf("<LI>Default view for room: ");
1755         wprintf("<SELECT NAME=\"er_view\" SIZE=\"1\" OnChange=\""
1756                 "       if (this.form.er_view.value == 0) {     "       
1757                 "               this.form.type[0].checked=true;         "
1758                 "               this.form.er_floor.disabled = false;    "
1759                 "       }                                               "
1760                 "       else {                                          "
1761                 "               this.form.type[4].checked=true;         "
1762                 "               this.form.er_floor.disabled = true;     "
1763                 "       }                                               "
1764                 "\">\n");
1765         for (i=0; i<(sizeof viewdefs / sizeof (char *)); ++i) {
1766                 wprintf("<OPTION %s VALUE=\"%d\">",
1767                         ((i == 0) ? "SELECTED" : ""), i );
1768                 escputs(viewdefs[i]);
1769                 wprintf("</OPTION>\n");
1770         }
1771         wprintf("</SELECT>\n");
1772
1773         wprintf("<LI>Type of room:<UL>\n");
1774
1775         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
1776         wprintf("CHECKED OnChange=\""
1777                 "       if (this.form.type[0].checked == true) {        "
1778                 "               this.form.er_floor.disabled = false;    "
1779                 "       }                                               "
1780                 "\"> Public (automatically appears to everyone)\n");
1781
1782         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"hidden\" OnChange=\""
1783                 "       if (this.form.type[1].checked == true) {        "
1784                 "               this.form.er_floor.disabled = false;    "
1785                 "       }                                               "
1786                 "\"> Private - hidden (accessible to anyone who knows its name)\n");
1787
1788         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" OnChange=\""
1789                 "       if (this.form.type[2].checked == true) {        "
1790                 "               this.form.er_floor.disabled = false;    "
1791                 "       }                                               "
1792                 "\"> Private - require password:\n");
1793         wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" MAXLENGTH=\"9\">\n");
1794
1795         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" OnChange=\""
1796                 "       if (this.form.type[3].checked == true) {        "
1797                 "               this.form.er_floor.disabled = false;    "
1798                 "       }                                               "
1799                 "\"> Private - invitation only\n");
1800
1801         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"personal\" "
1802                 "OnChange=\""
1803                 "       if (this.form.type[4].checked == true) {        "
1804                 "               this.form.er_floor.disabled = true;     "
1805                 "       }                                               "
1806                 "\"> Personal (mailbox for you only)\n");
1807
1808         wprintf("</UL>\n");
1809
1810         wprintf("<CENTER>\n");
1811         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1812         wprintf("&nbsp;");
1813         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1814         wprintf("</CENTER>\n");
1815         wprintf("</FORM>\n<hr />");
1816         serv_printf("MESG roomaccess");
1817         serv_gets(buf);
1818         if (buf[0] == '1') {
1819                 fmout(NULL, "CENTER");
1820         }
1821         wprintf("</td></tr></table></div>\n");
1822         wDumpContent(1);
1823 }
1824
1825
1826
1827
1828 /*
1829  * support function for entroom() -- sets the default view 
1830  */
1831 void er_set_default_view(int newview) {
1832
1833         char buf[SIZ];
1834
1835         char rm_name[SIZ];
1836         char rm_pass[SIZ];
1837         char rm_dir[SIZ];
1838         int rm_bits1;
1839         int rm_floor;
1840         int rm_listorder;
1841         int rm_bits2;
1842
1843         serv_puts("GETR");
1844         serv_gets(buf);
1845         if (buf[0] != '2') return;
1846
1847         extract(rm_name, &buf[4], 0);
1848         extract(rm_pass, &buf[4], 1);
1849         extract(rm_dir, &buf[4], 2);
1850         rm_bits1 = extract_int(&buf[4], 3);
1851         rm_floor = extract_int(&buf[4], 4);
1852         rm_listorder = extract_int(&buf[4], 5);
1853         rm_bits2 = extract_int(&buf[4], 7);
1854
1855         serv_printf("SETR %s|%s|%s|%d|0|%d|%d|%d|%d",
1856                 rm_name, rm_pass, rm_dir, rm_bits1, rm_floor,
1857                 rm_listorder, newview, rm_bits2
1858         );
1859         serv_gets(buf);
1860 }
1861
1862
1863
1864 /*
1865  * enter a new room
1866  */
1867 void entroom(void)
1868 {
1869         char buf[SIZ];
1870         char er_name[SIZ];
1871         char er_type[SIZ];
1872         char er_password[SIZ];
1873         int er_floor;
1874         int er_num_type;
1875         int er_view;
1876
1877         if (strcmp(bstr("sc"), "OK")) {
1878                 strcpy(WC->ImportantMessage,
1879                         "Cancelled.  No new room was created.");
1880                 display_main_menu();
1881                 return;
1882         }
1883         strcpy(er_name, bstr("er_name"));
1884         strcpy(er_type, bstr("type"));
1885         strcpy(er_password, bstr("er_password"));
1886         er_floor = atoi(bstr("er_floor"));
1887         er_view = atoi(bstr("er_view"));
1888
1889         er_num_type = 0;
1890         if (!strcmp(er_type, "hidden"))
1891                 er_num_type = 1;
1892         if (!strcmp(er_type, "passworded"))
1893                 er_num_type = 2;
1894         if (!strcmp(er_type, "invonly"))
1895                 er_num_type = 3;
1896         if (!strcmp(er_type, "personal"))
1897                 er_num_type = 4;
1898
1899         sprintf(buf, "CRE8 1|%s|%d|%s|%d|%d|%d", 
1900                 er_name, er_num_type, er_password, er_floor, 0, er_view);
1901         serv_puts(buf);
1902         serv_gets(buf);
1903         if (buf[0] != '2') {
1904                 strcpy(WC->ImportantMessage, &buf[4]);
1905                 display_main_menu();
1906                 return;
1907         }
1908         gotoroom(er_name);
1909         do_change_view(er_view);                /* Now go there */
1910 }
1911
1912
1913 /*
1914  * display the screen to enter a private room
1915  */
1916 void display_private(char *rname, int req_pass)
1917 {
1918         output_headers(1, 1, 2, 0, 0, 0, 0);
1919         wprintf("<div id=\"banner\">\n"
1920                 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
1921                 "<SPAN CLASS=\"titlebar\">Go to a hidden room</SPAN>"
1922                 "</TD></TR></TABLE>\n"
1923                 "</div>\n<div id=\"content\">\n"
1924         );
1925
1926         wprintf("<div id=\"fix_scrollbar_bug\">"
1927                 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
1928
1929         wprintf("<CENTER>\n");
1930         wprintf("<br />If you know the name of a hidden (guess-name) or\n");
1931         wprintf("passworded room, you can enter that room by typing\n");
1932         wprintf("its name below.  Once you gain access to a private\n");
1933         wprintf("room, it will appear in your regular room listings\n");
1934         wprintf("so you don't have to keep returning here.\n");
1935         wprintf("<br /><br />");
1936
1937         wprintf("<FORM METHOD=\"GET\" ACTION=\"/goto_private\">\n");
1938
1939         wprintf("<table border=\"0\" cellspacing=\"5\" "
1940                 "cellpadding=\"5\" BGCOLOR=\"#EEEEEE\">\n"
1941                 "<TR><TD>"
1942                 "Enter room name:</TD><TD>"
1943                 "<INPUT TYPE=\"text\" NAME=\"gr_name\" "
1944                 "VALUE=\"%s\" MAXLENGTH=\"19\">\n", rname);
1945
1946         if (req_pass) {
1947                 wprintf("</TD></TR><TR><TD>");
1948                 wprintf("Enter room password:</TD><TD>");
1949                 wprintf("<INPUT TYPE=\"password\" NAME=\"gr_pass\" MAXLENGTH=\"9\">\n");
1950         }
1951         wprintf("</TD></TR></TABLE><br />\n");
1952
1953         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">"
1954                 "&nbsp;"
1955                 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1956         wprintf("</FORM>\n");
1957         wprintf("</td></tr></table></div>\n");
1958         wDumpContent(1);
1959 }
1960
1961 /* 
1962  * goto a private room
1963  */
1964 void goto_private(void)
1965 {
1966         char hold_rm[SIZ];
1967         char buf[SIZ];
1968
1969         if (strcasecmp(bstr("sc"), "OK")) {
1970                 display_main_menu();
1971                 return;
1972         }
1973         strcpy(hold_rm, WC->wc_roomname);
1974         strcpy(buf, "GOTO ");
1975         strcat(buf, bstr("gr_name"));
1976         strcat(buf, "|");
1977         strcat(buf, bstr("gr_pass"));
1978         serv_puts(buf);
1979         serv_gets(buf);
1980
1981         if (buf[0] == '2') {
1982                 smart_goto(bstr("gr_name"));
1983                 return;
1984         }
1985         if (!strncmp(buf, "540", 3)) {
1986                 display_private(bstr("gr_name"), 1);
1987                 return;
1988         }
1989         output_headers(1, 1, 1, 0, 0, 0, 0);
1990         wprintf("%s\n", &buf[4]);
1991         wDumpContent(1);
1992         return;
1993 }
1994
1995
1996 /*
1997  * display the screen to zap a room
1998  */
1999 void display_zap(void)
2000 {
2001         output_headers(1, 1, 2, 0, 0, 0, 0);
2002
2003         wprintf("<div id=\"banner\">\n");
2004         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
2005         wprintf("<SPAN CLASS=\"titlebar\">Zap (forget/unsubscribe) the current room</SPAN>\n");
2006         wprintf("</TD></TR></TABLE>\n");
2007         wprintf("</div>\n<div id=\"content\">\n");
2008
2009         wprintf("If you select this option, <em>%s</em> will ", WC->wc_roomname);
2010         wprintf("disappear from your room list.  Is this what you wish ");
2011         wprintf("to do?<br />\n");
2012
2013         wprintf("<FORM METHOD=\"GET\" ACTION=\"/zap\">\n");
2014         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
2015         wprintf("&nbsp;");
2016         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
2017         wprintf("</FORM>\n");
2018         wDumpContent(1);
2019 }
2020
2021
2022 /* 
2023  * zap a room
2024  */
2025 void zap(void)
2026 {
2027         char buf[SIZ];
2028         char final_destination[SIZ];
2029
2030         /* If the forget-room routine fails for any reason, we fall back
2031          * to the current room; otherwise, we go to the Lobby
2032          */
2033         strcpy(final_destination, WC->wc_roomname);
2034
2035         if (!strcasecmp(bstr("sc"), "OK")) {
2036                 serv_printf("GOTO %s", WC->wc_roomname);
2037                 serv_gets(buf);
2038                 if (buf[0] == '2') {
2039                         serv_puts("FORG");
2040                         serv_gets(buf);
2041                         if (buf[0] == '2') {
2042                                 strcpy(final_destination, "_BASEROOM_");
2043                         }
2044                 }
2045         }
2046         smart_goto(final_destination);
2047 }
2048
2049
2050
2051
2052 /*
2053  * Confirm deletion of the current room
2054  */
2055 void confirm_delete_room(void)
2056 {
2057         char buf[SIZ];
2058
2059         serv_puts("KILL 0");
2060         serv_gets(buf);
2061         if (buf[0] != '2') {
2062                 strcpy(WC->ImportantMessage, &buf[4]);
2063                 display_main_menu();
2064                 return;
2065         }
2066         output_headers(1, 1, 2, 0, 0, 0, 0);
2067         wprintf("<div id=\"banner\">\n");
2068         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
2069         wprintf("<SPAN CLASS=\"titlebar\">Confirm deletion of room</SPAN>\n");
2070         wprintf("</TD></TR></TABLE>\n");
2071         wprintf("</div>\n<div id=\"content\">\n");
2072
2073         wprintf("<CENTER>");
2074         wprintf("<FORM METHOD=\"GET\" ACTION=\"/delete_room\">\n");
2075
2076         wprintf("Are you sure you want to delete <FONT SIZE=+1>");
2077         escputs(WC->wc_roomname);
2078         wprintf("</FONT>?<br />\n");
2079
2080         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">");
2081         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
2082
2083         wprintf("</FORM></CENTER>\n");
2084         wDumpContent(1);
2085 }
2086
2087
2088 /*
2089  * Delete the current room
2090  */
2091 void delete_room(void)
2092 {
2093         char buf[SIZ];
2094         char sc[SIZ];
2095
2096         strcpy(sc, bstr("sc"));
2097
2098         if (strcasecmp(sc, "Delete")) {
2099                 strcpy(WC->ImportantMessage,
2100                         "Cancelled.  This room was not deleted.");
2101                 display_main_menu();
2102                 return;
2103         }
2104         serv_puts("KILL 1");
2105         serv_gets(buf);
2106         if (buf[0] != '2') {
2107                 strcpy(WC->ImportantMessage, &buf[4]);
2108                 display_main_menu();
2109                 return;
2110         } else {
2111                 smart_goto("_BASEROOM_");
2112         }
2113 }
2114
2115
2116
2117 /*
2118  * Perform changes to a room's network configuration
2119  */
2120 void netedit(void) {
2121         FILE *fp;
2122         char buf[SIZ];
2123         char line[SIZ];
2124         char cmpa0[SIZ];
2125         char cmpa1[SIZ];
2126         char cmpb0[SIZ];
2127         char cmpb1[SIZ];
2128
2129         if (strlen(bstr("line"))==0) {
2130                 display_editroom();
2131                 return;
2132         }
2133
2134         strcpy(line, bstr("prefix"));
2135         strcat(line, bstr("line"));
2136         strcat(line, bstr("suffix"));
2137
2138         fp = tmpfile();
2139         if (fp == NULL) {
2140                 display_editroom();
2141                 return;
2142         }
2143
2144         serv_puts("GNET");
2145         serv_gets(buf);
2146         if (buf[0] != '1') {
2147                 fclose(fp);
2148                 display_editroom();
2149                 return;
2150         }
2151
2152         /* This loop works for add *or* remove.  Spiffy, eh? */
2153         while (serv_gets(buf), strcmp(buf, "000")) {
2154                 extract(cmpa0, buf, 0);
2155                 extract(cmpa1, buf, 1);
2156                 extract(cmpb0, line, 0);
2157                 extract(cmpb1, line, 1);
2158                 if ( (strcasecmp(cmpa0, cmpb0)) 
2159                    || (strcasecmp(cmpa1, cmpb1)) ) {
2160                         fprintf(fp, "%s\n", buf);
2161                 }
2162         }
2163
2164         rewind(fp);
2165         serv_puts("SNET");
2166         serv_gets(buf);
2167         if (buf[0] != '4') {
2168                 fclose(fp);
2169                 display_editroom();
2170                 return;
2171         }
2172
2173         while (fgets(buf, sizeof buf, fp) != NULL) {
2174                 buf[strlen(buf)-1] = 0;
2175                 serv_puts(buf);
2176         }
2177
2178         if (!strcasecmp(bstr("cmd"), "add")) {
2179                 serv_puts(line);
2180         }
2181
2182         serv_puts("000");
2183         fclose(fp);
2184         display_editroom();
2185 }
2186
2187
2188
2189 /*
2190  * Convert a room name to a folder-ish-looking name.
2191  */
2192 void room_to_folder(char *folder, char *room, int floor, int is_mailbox)
2193 {
2194         int i;
2195
2196         /*
2197          * For mailboxes, just do it straight...
2198          */
2199         if (is_mailbox) {
2200                 sprintf(folder, "My folders|%s", room);
2201         }
2202
2203         /*
2204          * Otherwise, prefix the floor name as a "public folders" moniker
2205          */
2206         else {
2207                 sprintf(folder, "%s|%s", floorlist[floor], room);
2208         }
2209
2210         /*
2211          * Replace "\" characters with "|" for pseudo-folder-delimiting
2212          */
2213         for (i=0; i<strlen(folder); ++i) {
2214                 if (folder[i] == '\\') folder[i] = '|';
2215         }
2216 }
2217
2218
2219
2220
2221 /*
2222  * Back end for change_view()
2223  */
2224 void do_change_view(int newview) {
2225         char buf[SIZ];
2226
2227         serv_printf("VIEW %d", newview);
2228         serv_gets(buf);
2229         WC->wc_view = newview;
2230         smart_goto(WC->wc_roomname);
2231 }
2232
2233
2234
2235 /*
2236  * Change the view for this room
2237  */
2238 void change_view(void) {
2239         int view;
2240
2241         view = atol(bstr("view"));
2242         do_change_view(view);
2243 }
2244
2245
2246 /*
2247  * One big expanded tree list view --- like a folder list
2248  */
2249 void do_folder_view(struct folder *fold, int max_folders, int num_floors) {
2250         char buf[SIZ];
2251         int levels, oldlevels;
2252         int i, t;
2253         int actnum = 0;
2254         int has_subfolders = 0;
2255
2256         /* Include the menu expanding/collapsing code */
2257         wprintf("<script type=\"text/javascript\" src=\"/static/menuExpandable3.js\"></script>\n");
2258
2259         /* BEGIN TREE MENU */
2260         wprintf("<div style=\"background: white\">\n");
2261         wprintf("<div id=\"mainMenu\">\n");
2262         wprintf("<UL id=\"menuList\">\n");
2263         levels = 0;
2264         oldlevels = 0;
2265
2266         for (i=0; i<max_folders; ++i) {
2267
2268                 has_subfolders = 0;
2269                 if ((i+1) < max_folders) {
2270                         if ( (!strncasecmp(fold[i].name, fold[i+1].name, strlen(fold[i].name)))
2271                            && (fold[i+1].name[strlen(fold[i].name)] == '|') ) {
2272                                 has_subfolders = 1;
2273                         }
2274                 }
2275
2276                 levels = num_tokens(fold[i].name, '|');
2277
2278                 if ( (levels < oldlevels) || ((levels==1)&&(i!=0)) ) {
2279                         for (t=0; t<(oldlevels-levels); ++t) {
2280                                 wprintf("</UL>\n");
2281                         }
2282                 }
2283
2284                 if (has_subfolders) {
2285                         wprintf("<LI");
2286                         if (levels == 1) wprintf(" class=\"menubar\"");
2287                         wprintf(">");
2288                         wprintf("<A href=\"#\" id=\"actuator%d\" class=\"actuator\"></a>\n", actnum);
2289                 }
2290                 else {
2291                         wprintf("<LI>");
2292                 }
2293
2294                 if (fold[i].selectable) {
2295                         wprintf("<A HREF=\"/dotgoto?room=");
2296                         urlescputs(fold[i].room);
2297                         wprintf("\">");
2298                 }
2299
2300                 if (levels == 1) {
2301                         wprintf("<SPAN CLASS=\"roomlist_floor\">");
2302                 }
2303                 else if (fold[i].hasnewmsgs) {
2304                         wprintf("<SPAN CLASS=\"roomlist_new\">");
2305                 }
2306                 else {
2307                         wprintf("<SPAN CLASS=\"roomlist_old\">");
2308                 }
2309                 extract(buf, fold[i].name, levels-1);
2310                 escputs(buf);
2311                 wprintf("</SPAN>");
2312
2313                 if (!strcasecmp(fold[i].name, "My Folders|Mail")) {
2314                         wprintf(" (INBOX)");
2315                 }
2316
2317                 if (fold[i].selectable) {
2318                         wprintf("</A>");
2319                 }
2320                 wprintf("\n");
2321
2322                 if (has_subfolders) {
2323                         wprintf("<UL id=\"menu%d\" class=\"%s\">\n",
2324                                 actnum++,
2325                                 ( (levels == 1) ? "menu" : "submenu")
2326                         );
2327                 }
2328
2329                 oldlevels = levels;
2330         }
2331         wprintf("</UL></UL>\n");
2332         wprintf("<img src=\"/static/blank.gif\" onLoad = ' \n");
2333         for (i=0; i<actnum; ++i) {
2334                 wprintf(" initializeMenu(\"menu%d\", \"actuator%d\");\n", i, i);
2335         }
2336         wprintf(" ' > \n");
2337         wprintf("</DIV>\n");
2338         /* END TREE MENU */
2339 }
2340
2341 /*
2342  * Boxes and rooms and lists ... oh my!
2343  */
2344 void do_rooms_view(struct folder *fold, int max_folders, int num_floors) {
2345         char buf[SIZ];
2346         char boxtitle[SIZ];
2347         int levels, oldlevels;
2348         int i, t;
2349         int num_boxes = 0;
2350         static int columns = 3;
2351         int boxes_per_column = 0;
2352         int current_column = 0;
2353         int nf;
2354
2355         nf = num_floors;
2356         while (nf % columns != 0) ++nf;
2357         boxes_per_column = (nf / columns);
2358         if (boxes_per_column < 1) boxes_per_column = 1;
2359
2360         /* Outer table (for columnization) */
2361         wprintf("<TABLE BORDER=0 WIDTH=96%% CELLPADDING=5>"
2362                 "<tr><td valign=top>");
2363
2364         levels = 0;
2365         oldlevels = 0;
2366         for (i=0; i<max_folders; ++i) {
2367
2368                 levels = num_tokens(fold[i].name, '|');
2369
2370                 if ((levels == 1) && (oldlevels > 1)) {
2371
2372                         /* End inner box */
2373                         do_template("endbox");
2374
2375                         ++num_boxes;
2376                         if ((num_boxes % boxes_per_column) == 0) {
2377                                 ++current_column;
2378                                 if (current_column < columns) {
2379                                         wprintf("</td><td valign=top>\n");
2380                                 }
2381                         }
2382                 }
2383
2384                 if (levels == 1) {
2385
2386                         /* Begin inner box */
2387                         extract(buf, fold[i].name, levels-1);
2388                         stresc(boxtitle, buf, 1, 0);
2389                         svprintf("BOXTITLE", WCS_STRING, boxtitle);
2390                         do_template("beginbox");
2391
2392                 }
2393
2394                 oldlevels = levels;
2395
2396                 if (levels > 1) {
2397                         wprintf("&nbsp;");
2398                         if (levels>2) for (t=0; t<(levels-2); ++t) wprintf("&nbsp;&nbsp;&nbsp;");
2399                         if (fold[i].selectable) {
2400                                 wprintf("<A HREF=\"/dotgoto?room=");
2401                                 urlescputs(fold[i].room);
2402                                 wprintf("\">");
2403                         }
2404                         else {
2405                                 wprintf("<i>");
2406                         }
2407                         if (fold[i].hasnewmsgs) {
2408                                 wprintf("<SPAN CLASS=\"roomlist_new\">");
2409                         }
2410                         else {
2411                                 wprintf("<SPAN CLASS=\"roomlist_old\">");
2412                         }
2413                         extract(buf, fold[i].name, levels-1);
2414                         escputs(buf);
2415                         wprintf("</SPAN>");
2416                         if (fold[i].selectable) {
2417                                 wprintf("</A>");
2418                         }
2419                         else {
2420                                 wprintf("</i>");
2421                         }
2422                         if (!strcasecmp(fold[i].name, "My Folders|Mail")) {
2423                                 wprintf(" (INBOX)");
2424                         }
2425                         wprintf("<br />\n");
2426                 }
2427         }
2428         /* End the final inner box */
2429         do_template("endbox");
2430
2431         wprintf("</TD></TR></TABLE>\n");
2432 }
2433
2434
2435 /*
2436  * Show the room list.  (only should get called by
2437  * knrooms() because that's where output_headers() is called from)
2438  */
2439
2440 void list_all_rooms_by_floor(char *viewpref) {
2441         char buf[SIZ];
2442         int swap = 0;
2443         struct folder *fold = NULL;
2444         struct folder ftmp;
2445         int max_folders = 0;
2446         int alloc_folders = 0;
2447         int i, j;
2448         int ra_flags = 0;
2449         int flags = 0;
2450         int num_floors = 1;     /* add an extra one for private folders */
2451
2452         /* Start with the mailboxes */
2453         max_folders = 1;
2454         alloc_folders = 1;
2455         fold = malloc(sizeof(struct folder));
2456         memset(fold, 0, sizeof(struct folder));
2457         strcpy(fold[0].name, "My folders");
2458         fold[0].is_mailbox = 1;
2459
2460         /* Then add floors */
2461         serv_puts("LFLR");
2462         serv_gets(buf);
2463         if (buf[0]=='1') while(serv_gets(buf), strcmp(buf, "000")) {
2464                 if (max_folders >= alloc_folders) {
2465                         alloc_folders = max_folders + 100;
2466                         fold = realloc(fold,
2467                                 alloc_folders * sizeof(struct folder));
2468                 }
2469                 memset(&fold[max_folders], 0, sizeof(struct folder));
2470                 extract(fold[max_folders].name, buf, 1);
2471                 ++max_folders;
2472                 ++num_floors;
2473         }
2474
2475         /* Now add rooms */
2476         serv_puts("LKRA");
2477         serv_gets(buf);
2478         if (buf[0]=='1') while(serv_gets(buf), strcmp(buf, "000")) {
2479                 if (max_folders >= alloc_folders) {
2480                         alloc_folders = max_folders + 100;
2481                         fold = realloc(fold,
2482                                 alloc_folders * sizeof(struct folder));
2483                 }
2484                 memset(&fold[max_folders], 0, sizeof(struct folder));
2485                 extract(fold[max_folders].room, buf, 0);
2486                 ra_flags = extract_int(buf, 5);
2487                 flags = extract_int(buf, 1);
2488                 fold[max_folders].floor = extract_int(buf, 2);
2489                 fold[max_folders].hasnewmsgs =
2490                         ((ra_flags & UA_HASNEWMSGS) ? 1 : 0 );
2491                 if (flags & QR_MAILBOX) {
2492                         fold[max_folders].is_mailbox = 1;
2493                 }
2494                 room_to_folder(fold[max_folders].name,
2495                                 fold[max_folders].room,
2496                                 fold[max_folders].floor,
2497                                 fold[max_folders].is_mailbox);
2498                 fold[max_folders].selectable = 1;
2499                 ++max_folders;
2500         }
2501
2502         /* Bubble-sort the folder list */
2503         for (i=0; i<max_folders; ++i) {
2504                 for (j=0; j<(max_folders-1)-i; ++j) {
2505                         if (fold[j].is_mailbox == fold[j+1].is_mailbox) {
2506                                 swap = strcasecmp(fold[j].name, fold[j+1].name);
2507                         }
2508                         else {
2509                                 if ( (fold[j+1].is_mailbox)
2510                                    && (!fold[j].is_mailbox)) {
2511                                         swap = 1;
2512                                 }
2513                                 else {
2514                                         swap = 0;
2515                                 }
2516                         }
2517                         if (swap > 0) {
2518                                 memcpy(&ftmp, &fold[j], sizeof(struct folder));
2519                                 memcpy(&fold[j], &fold[j+1],
2520                                                         sizeof(struct folder));
2521                                 memcpy(&fold[j+1], &ftmp,
2522                                                         sizeof(struct folder));
2523                         }
2524                 }
2525         }
2526
2527 /* test only hackish view 
2528         wprintf("<table><TR><TD>A Table</TD></TR></table>\n");
2529         for (i=0; i<max_folders; ++i) {
2530                 escputs(fold[i].name);
2531                 wprintf("<br />\n");
2532         }
2533  */
2534
2535         if (!strcasecmp(viewpref, "folders")) {
2536                 do_folder_view(fold, max_folders, num_floors);
2537         }
2538         else {
2539                 do_rooms_view(fold, max_folders, num_floors);
2540         }
2541
2542         free(fold);
2543         wDumpContent(1);
2544 }
2545
2546
2547 /* Do either a known rooms list or a folders list, depending on the
2548  * user's preference
2549  */
2550 void knrooms() {
2551         char listviewpref[SIZ];
2552
2553         output_headers(1, 1, 2, 0, 0, 0, 0);
2554         load_floorlist();
2555
2556         /* Determine whether the user is trying to change views */
2557         if (bstr("view") != NULL) {
2558                 if (strlen(bstr("view")) > 0) {
2559                         set_preference("roomlistview", bstr("view"));
2560                 }
2561         }
2562
2563         get_preference("roomlistview", listviewpref);
2564
2565         if ( (strcasecmp(listviewpref, "folders"))
2566            && (strcasecmp(listviewpref, "table")) ) {
2567                 strcpy(listviewpref, "rooms");
2568         }
2569
2570         /* title bar */
2571         wprintf("<div id=\"banner\">\n"
2572                 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
2573                 "<SPAN CLASS=\"titlebar\">"
2574         );
2575         if (!strcasecmp(listviewpref, "rooms")) {
2576                 wprintf("Room list");
2577         }
2578         if (!strcasecmp(listviewpref, "folders")) {
2579                 wprintf("Folder list");
2580         }
2581         if (!strcasecmp(listviewpref, "table")) {
2582                 wprintf("Room list");
2583         }
2584         wprintf("</SPAN></TD>\n");
2585
2586         /* offer the ability to switch views */
2587         wprintf("<TD ALIGN=RIGHT><FORM NAME=\"roomlistomatic\">\n"
2588                 "<SELECT NAME=\"newview\" SIZE=\"1\" "
2589                 "OnChange=\"location.href=roomlistomatic.newview.options"
2590                 "[selectedIndex].value\">\n");
2591
2592         wprintf("<OPTION %s VALUE=\"/knrooms&view=rooms\">"
2593                 "View as room list"
2594                 "</OPTION>\n",
2595                 ( !strcasecmp(listviewpref, "rooms") ? "SELECTED" : "" )
2596         );
2597
2598         wprintf("<OPTION %s VALUE=\"/knrooms&view=folders\">"
2599                 "View as folder list"
2600                 "</OPTION>\n",
2601                 ( !strcasecmp(listviewpref, "folders") ? "SELECTED" : "" )
2602         );
2603
2604         wprintf("</SELECT><br />");
2605         offer_start_page();
2606         wprintf("</FORM></TD></TR></TABLE>\n");
2607         wprintf("</div>\n"
2608                 "</div>\n"
2609                 "<div id=\"content\">\n");
2610
2611         /* Display the room list in the user's preferred format */
2612         list_all_rooms_by_floor(listviewpref);
2613 }
2614
2615
2616
2617 /* 
2618  * Set the message expire policy for this room and/or floor
2619  */
2620 void set_room_policy(void) {
2621         char buf[SIZ];
2622
2623         if (strcmp(bstr("sc"), "OK")) {
2624                 strcpy(WC->ImportantMessage,
2625                         "Cancelled.  Changes were not saved.");
2626                 display_editroom();
2627                 return;
2628         }
2629
2630         serv_printf("SPEX room|%d|%d", atoi(bstr("roompolicy")), atoi(bstr("roomvalue")));
2631         serv_gets(buf);
2632         strcpy(WC->ImportantMessage, &buf[4]);
2633
2634         if (WC->axlevel >= 6) {
2635                 strcat(WC->ImportantMessage, "<br />\n");
2636                 serv_printf("SPEX floor|%d|%d", atoi(bstr("floorpolicy")), atoi(bstr("floorvalue")));
2637                 serv_gets(buf);
2638                 strcat(WC->ImportantMessage, &buf[4]);
2639         }
2640
2641         display_editroom();
2642 }