* Begin migration to the new "rounded boxes" look
[citadel.git] / webcit / roomops.c
1 /* $Id$ */
2
3
4 #include <ctype.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <stdio.h>
8 #include <fcntl.h>
9 #include <signal.h>
10 #include <sys/types.h>
11 #include <sys/wait.h>
12 #include <sys/socket.h>
13 #include <sys/time.h>
14 #include <limits.h>
15 #include <netinet/in.h>
16 #include <netdb.h>
17 #include <string.h>
18 #include <pwd.h>
19 #include <errno.h>
20 #include <stdarg.h>
21 #include <pthread.h>
22 #include <signal.h>
23 #include "webcit.h"
24
25 struct folder {
26         int floor;
27         char room[SIZ];
28         char name[SIZ];
29         int hasnewmsgs;
30         int is_mailbox;
31         int selectable;
32 };
33
34 char *viewdefs[] = {
35         "Messages",
36         "Summary",
37         "Address Book",
38         "Calendar",
39         "Tasks"
40 };
41
42 char floorlist[128][SIZ];
43
44 /*
45  * load the list of floors
46  */
47 void load_floorlist(void)
48 {
49         int a;
50         char buf[SIZ];
51
52         for (a = 0; a < 128; ++a)
53                 floorlist[a][0] = 0;
54
55         serv_puts("LFLR");
56         serv_gets(buf);
57         if (buf[0] != '1') {
58                 strcpy(floorlist[0], "Main Floor");
59                 return;
60         }
61         while (serv_gets(buf), strcmp(buf, "000")) {
62                 extract(floorlist[extract_int(buf, 0)], buf, 1);
63         }
64 }
65
66
67 /*
68  * remove a room from the march list
69  */
70 void remove_march(char *aaa)
71 {
72         struct march *mptr, *mptr2;
73
74         if (WC->march == NULL)
75                 return;
76
77         if (!strcasecmp(WC->march->march_name, aaa)) {
78                 mptr = WC->march->next;
79                 free(WC->march);
80                 WC->march = mptr;
81                 return;
82         }
83         mptr2 = WC->march;
84         for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
85                 if (!strcasecmp(mptr->march_name, aaa)) {
86                         mptr2->next = mptr->next;
87                         free(mptr);
88                         mptr = mptr2;
89                 } else {
90                         mptr2 = mptr;
91                 }
92         }
93 }
94
95
96
97
98
99 void room_tree_list(struct roomlisting *rp)
100 {
101         char rmname[64];
102         int f;
103
104         if (rp == NULL) {
105                 return;
106         }
107
108         room_tree_list(rp->lnext);
109
110         strcpy(rmname, rp->rlname);
111         f = rp->rlflags;
112
113         wprintf("<A HREF=\"/dotgoto&room=");
114         urlescputs(rmname);
115         wprintf("\"");
116         wprintf(">");
117         escputs1(rmname, 1);
118         if ((f & QR_DIRECTORY) && (f & QR_NETWORK))
119                 wprintf("}");
120         else if (f & QR_DIRECTORY)
121                 wprintf("]");
122         else if (f & QR_NETWORK)
123                 wprintf(")");
124         else
125                 wprintf("&gt;");
126         wprintf("</A><TT> </TT>\n");
127
128         room_tree_list(rp->rnext);
129         free(rp);
130 }
131
132
133 /* 
134  * Room ordering stuff (compare first by floor, then by order)
135  */
136 int rordercmp(struct roomlisting *r1, struct roomlisting *r2)
137 {
138         if ((r1 == NULL) && (r2 == NULL))
139                 return (0);
140         if (r1 == NULL)
141                 return (-1);
142         if (r2 == NULL)
143                 return (1);
144         if (r1->rlfloor < r2->rlfloor)
145                 return (-1);
146         if (r1->rlfloor > r2->rlfloor)
147                 return (1);
148         if (r1->rlorder < r2->rlorder)
149                 return (-1);
150         if (r1->rlorder > r2->rlorder)
151                 return (1);
152         return (0);
153 }
154
155
156 /*
157  * Common code for all room listings
158  */
159 void listrms(char *variety)
160 {
161         char buf[SIZ];
162         int num_rooms = 0;
163
164         struct roomlisting *rl = NULL;
165         struct roomlisting *rp;
166         struct roomlisting *rs;
167
168
169         /* Ask the server for a room list */
170         serv_puts(variety);
171         serv_gets(buf);
172         if (buf[0] != '1') {
173                 wprintf("&nbsp;");
174                 return;
175         }
176         while (serv_gets(buf), strcmp(buf, "000")) {
177                 ++num_rooms;
178                 rp = malloc(sizeof(struct roomlisting));
179                 extract(rp->rlname, buf, 0);
180                 rp->rlflags = extract_int(buf, 1);
181                 rp->rlfloor = extract_int(buf, 2);
182                 rp->rlorder = extract_int(buf, 3);
183                 rp->lnext = NULL;
184                 rp->rnext = NULL;
185
186                 rs = rl;
187                 if (rl == NULL) {
188                         rl = rp;
189                 } else
190                         while (rp != NULL) {
191                                 if (rordercmp(rp, rs) < 0) {
192                                         if (rs->lnext == NULL) {
193                                                 rs->lnext = rp;
194                                                 rp = NULL;
195                                         } else {
196                                                 rs = rs->lnext;
197                                         }
198                                 } else {
199                                         if (rs->rnext == NULL) {
200                                                 rs->rnext = rp;
201                                                 rp = NULL;
202                                         } else {
203                                                 rs = rs->rnext;
204                                         }
205                                 }
206                         }
207         }
208
209         room_tree_list(rl);
210
211         /* If no rooms were listed, print an nbsp to make the cell
212          * borders show up anyway.
213          */
214         if (num_rooms == 0) wprintf("&nbsp;");
215 }
216
217
218 /*
219  * list all rooms by floor (only should get called from knrooms() because
220  * that's where output_headers() is called from)
221  */
222 void tabular_room_list(void)
223 {
224         int a;
225         char buf[SIZ];
226
227         do_template("beginbox_nt");
228         wprintf("<TABLE width=100%% border><TR><TH>Floor</TH>");
229         wprintf("<TH>Rooms with new messages</TH>");
230         wprintf("<TH>Rooms with no new messages</TH></TR>\n");
231
232         for (a = 0; a < 128; ++a)
233                 if (floorlist[a][0] != 0) {
234
235                         /* Floor name column */
236                         wprintf("<TR><TD>");
237
238                         serv_printf("OIMG _floorpic_|%d", a);
239                         serv_gets(buf);
240                         if (buf[0] == '2') {
241                                 serv_puts("CLOS");
242                                 serv_gets(buf);
243                                 wprintf("<IMG SRC=\"/image&name=_floorpic_&parm=%d\" ALT=\"%s\">",
244                                         a, &floorlist[a][0]);
245                         } else {
246                                 escputs(&floorlist[a][0]);
247                         }
248
249                         wprintf("</TD>");
250
251                         /* Rooms with new messages column */
252                         wprintf("<TD>");
253                         sprintf(buf, "LKRN %d", a);
254                         listrms(buf);
255                         wprintf("</TD>\n<TD>");
256
257                         /* Rooms with old messages column */
258                         sprintf(buf, "LKRO %d", a);
259                         listrms(buf);
260                         wprintf("</TD></TR>\n");
261                 }
262         wprintf("</TABLE>\n");
263         do_template("endbox");
264         wDumpContent(1);
265 }
266
267
268
269
270
271
272
273
274
275 /*
276  * list all forgotten rooms
277  */
278 void zapped_list(void)
279 {
280         output_headers(1);
281         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
282         wprintf("<SPAN CLASS=\"titlebar\">Zapped (forgotten) rooms</SPAN>\n");
283         wprintf("</TD></TR></TABLE><BR>\n");
284         listrms("LZRM -1");
285         wprintf("<BR><BR>\n");
286         wprintf("Click on any room to un-zap it and goto that room.\n");
287         wDumpContent(1);
288 }
289
290
291 /*
292  * read this room's info file (set v to 1 for verbose mode)
293  */
294 void readinfo(void)
295 {
296         char buf[SIZ];
297
298         serv_puts("RINF");
299         serv_gets(buf);
300         if (buf[0] == '1') {
301                 fmout(NULL);
302         }
303 }
304
305
306
307
308 /* Display room graphic.  The server doesn't actually
309  * need the room name, but we supply it in order to
310  * keep the browser from using a cached graphic from 
311  * another room.
312  */
313 void embed_room_graphic(void) {
314         char buf[SIZ];
315
316         serv_puts("OIMG _roompic_");
317         serv_gets(buf);
318         if (buf[0] == '2') {
319                 wprintf("<TD BGCOLOR=\"#444455\">");
320                 wprintf("<IMG SRC=\"/image&name=_roompic_&room=");
321                 urlescputs(WC->wc_roomname);
322                 wprintf("\"></TD>");
323                 serv_puts("CLOS");
324                 serv_gets(buf);
325         }
326
327 }
328
329
330 /* Let the user know if new mail has arrived 
331  */
332 void embed_newmail_button(void) {
333         if ( (WC->new_mail > WC->remember_new_mail) && (WC->new_mail>0) ) {
334                 wprintf(
335                         "<A HREF=\"/dotgoto?room=_MAIL_\">"
336                         "<IMG SRC=\"/static/mail.gif\" border=0 "
337                         "ALT=\"You have new mail\">"
338                         "<BR><SPAN CLASS=\"youhavemail\">"
339                         "%d new mail</SPAN></A>", WC->new_mail);
340                 WC->remember_new_mail = WC->new_mail;
341         }
342 }
343
344
345
346 /*
347  * Display the current view and offer an option to change it
348  */
349 void embed_view_o_matic(void) {
350         int i;
351
352         wprintf("<FORM NAME=\"viewomatic\">\n"
353                 "<SELECT NAME=\"newview\" SIZE=\"1\" "
354                 "OnChange=\"location.href=viewomatic.newview.options"
355                 "[selectedIndex].value\">\n");
356
357         for (i=0; i<(sizeof viewdefs / sizeof (char *)); ++i) {
358                 /*
359                  * Only offer the views that make sense, given the default
360                  * view for the room.  For example, don't offer a Calendar
361                  * view in a non-Calendar room.
362                  */
363                 if (
364                         (i == WC->wc_view)
365                    ||   (i == WC->wc_default_view)
366                    ||   ( (i == 0) && (WC->wc_default_view == 1) )
367                    ||   ( (i == 1) && (WC->wc_default_view == 0) )
368                 ) {
369
370                         wprintf("<OPTION %s VALUE=\"/changeview?view=%d\">",
371                                 ((i == WC->wc_view) ? "SELECTED" : ""),
372                                 i );
373                         escputs(viewdefs[i]);
374                         wprintf("</OPTION>\n");
375                 }
376         }
377         wprintf("</SELECT></FORM>\n");
378 }
379
380
381
382 void embed_room_banner(char *got) {
383         char fakegot[SIZ];
384
385         /* We need to have the information returned by a GOTO server command.
386          * If it isn't supplied, we fake it by issuing our own GOTO.
387          */
388         if (got == NULL) {
389                 serv_printf("GOTO %s", WC->wc_roomname);
390                 serv_gets(fakegot);
391                 got = fakegot;
392         }
393
394         /* If the user happens to select the "make this my start page" link,
395          * we want it to remember the URL as a "/dotskip" one instead of
396          * a "skip" or "gotonext" or something like that.
397          */
398         snprintf(WC->this_page, sizeof(WC->this_page), "/dotskip&room=%s",
399                 WC->wc_roomname);
400
401         /* Check for new mail. */
402         WC->new_mail = extract_int(&got[4], 9);
403         WC->wc_view = extract_int(&got[4], 11);
404
405         svprintf("ROOMNAME", WCS_STRING, "%s", WC->wc_roomname);
406         svprintf("NEWMSGS", WCS_STRING, "%d", extract_int(&got[4], 1));
407         svprintf("TOTALMSGS", WCS_STRING, "%d", extract_int(&got[4], 2));
408         svcallback("ROOMPIC", embed_room_graphic);
409         svcallback("ROOMINFO", readinfo);
410         svcallback("YOUHAVEMAIL", embed_newmail_button);
411         svcallback("VIEWOMATIC", embed_view_o_matic);
412         svcallback("START", offer_start_page);
413
414         do_template("roombanner");
415         clear_local_substs();
416 }
417
418
419
420
421
422 /*
423  * generic routine to take the session to a new room
424  *
425  * display_name values:  0 = goto only
426  *                       1 = goto and display
427  *                       2 = display only
428  */
429 void gotoroom(char *gname, int display_name)
430 {
431         char buf[SIZ];
432         static long ls = (-1L);
433
434
435         if (display_name) {
436                 output_headers(0);
437                 wprintf("Pragma: no-cache\n");
438                 wprintf("Cache-Control: no-store\n");
439
440                 wprintf("<HTML><HEAD>\n"
441                         "<META HTTP-EQUIV=\"refresh\" CONTENT=\"500363689;\">\n"
442                         "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n"
443                         "<META HTTP-EQUIV=\"expired\" CONTENT=\"28-May-1971 18:10:00 GMT\">\n"
444                         "<meta name=\"MSSmartTagsPreventParsing\" content=\"TRUE\">\n"
445                         "</HEAD>\n");
446                 do_template("background");
447         }
448         if (display_name != 2) {
449                 /* store ungoto information */
450                 strcpy(WC->ugname, WC->wc_roomname);
451                 WC->uglsn = ls;
452         }
453         /* move to the new room */
454         serv_printf("GOTO %s", gname);
455         serv_gets(buf);
456         if (buf[0] != '2') {
457                 serv_puts("GOTO _BASEROOM_");
458                 serv_gets(buf);
459         }
460         if (buf[0] != '2') {
461                 if (display_name) {
462                         wprintf("<EM>%s</EM><BR>\n", &buf[4]);
463                         wDumpContent(1);
464                 }
465                 return;
466         }
467         extract(WC->wc_roomname, &buf[4], 0);
468         WC->room_flags = extract_int(&buf[4], 4);
469         /* highest_msg_read = extract_int(&buf[4],6);
470            maxmsgnum = extract_int(&buf[4],5);
471            is_mail = (char) extract_int(&buf[4],7); */
472         ls = extract_long(&buf[4], 6);
473
474         if (WC->is_aide)
475                 WC->is_room_aide = WC->is_aide;
476         else
477                 WC->is_room_aide = (char) extract_int(&buf[4], 8);
478
479         remove_march(WC->wc_roomname);
480         if (!strcasecmp(gname, "_BASEROOM_"))
481                 remove_march(gname);
482
483         /* Display the room banner */
484         if (display_name) {
485                 embed_room_banner(buf);
486                 wDumpContent(1);
487         }
488         strcpy(WC->wc_roomname, WC->wc_roomname);
489         WC->wc_view = extract_int(&buf[4], 11);
490         WC->wc_default_view = extract_int(&buf[4], 12);
491 }
492
493
494 /*
495  * Locate the room on the march list which we most want to go to.  Each room
496  * is measured given a "weight" of preference based on various factors.
497  */
498 char *pop_march(int desired_floor)
499 {
500         static char TheRoom[128];
501         int TheFloor = 0;
502         int TheOrder = 32767;
503         int TheWeight = 0;
504         int weight;
505         struct march *mptr = NULL;
506
507         strcpy(TheRoom, "_BASEROOM_");
508         if (WC->march == NULL)
509                 return (TheRoom);
510
511         for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
512                 weight = 0;
513                 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
514                         weight = weight + 10000;
515                 if (mptr->march_floor == desired_floor)
516                         weight = weight + 5000;
517
518                 weight = weight + ((128 - (mptr->march_floor)) * 128);
519                 weight = weight + (128 - (mptr->march_order));
520
521                 if (weight > TheWeight) {
522                         TheWeight = weight;
523                         strcpy(TheRoom, mptr->march_name);
524                         TheFloor = mptr->march_floor;
525                         TheOrder = mptr->march_order;
526                 }
527         }
528         return (TheRoom);
529 }
530
531
532
533 /* Goto next room having unread messages.
534  * We want to skip over rooms that the user has already been to, and take the
535  * user back to the lobby when done.  The room we end up in is placed in
536  * newroom - which is set to 0 (the lobby) initially.
537  * We start the search in the current room rather than the beginning to prevent
538  * two or more concurrent users from dragging each other back to the same room.
539  */
540 void gotonext(void)
541 {
542         char buf[SIZ];
543         struct march *mptr, *mptr2;
544         char next_room[128];
545
546         /* First check to see if the march-mode list is already allocated.
547          * If it is, pop the first room off the list and go there.
548          */
549
550         if (WC->march == NULL) {
551                 serv_puts("LKRN");
552                 serv_gets(buf);
553                 if (buf[0] == '1')
554                         while (serv_gets(buf), strcmp(buf, "000")) {
555                                 mptr = (struct march *) malloc(sizeof(struct march));
556                                 mptr->next = NULL;
557                                 extract(mptr->march_name, buf, 0);
558                                 mptr->march_floor = extract_int(buf, 2);
559                                 mptr->march_order = extract_int(buf, 3);
560                                 if (WC->march == NULL) {
561                                         WC->march = mptr;
562                                 } else {
563                                         mptr2 = WC->march;
564                                         while (mptr2->next != NULL)
565                                                 mptr2 = mptr2->next;
566                                         mptr2->next = mptr;
567                                 }
568                         }
569 /* add _BASEROOM_ to the end of the march list, so the user will end up
570  * in the system base room (usually the Lobby>) at the end of the loop
571  */
572                 mptr = (struct march *) malloc(sizeof(struct march));
573                 mptr->next = NULL;
574                 strcpy(mptr->march_name, "_BASEROOM_");
575                 if (WC->march == NULL) {
576                         WC->march = mptr;
577                 } else {
578                         mptr2 = WC->march;
579                         while (mptr2->next != NULL)
580                                 mptr2 = mptr2->next;
581                         mptr2->next = mptr;
582                 }
583 /*
584  * ...and remove the room we're currently in, so a <G>oto doesn't make us
585  * walk around in circles
586  */
587                 remove_march(WC->wc_roomname);
588         }
589         if (WC->march != NULL) {
590                 strcpy(next_room, pop_march(-1));
591         } else {
592                 strcpy(next_room, "_BASEROOM_");
593         }
594
595
596         smart_goto(next_room);
597 }
598
599
600 void smart_goto(char *next_room) {
601         gotoroom(next_room, 0);
602         readloop("readnew");
603 }
604
605
606
607 /*
608  * mark all messages in current room as having been read
609  */
610 void slrp_highest(void)
611 {
612         char buf[SIZ];
613
614         /* set pointer */
615         serv_puts("SLRP HIGHEST");
616         serv_gets(buf);
617         if (buf[0] != '2') {
618                 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
619                 return;
620         }
621 }
622
623
624 /*
625  * un-goto the previous room
626  */
627 void ungoto(void)
628 {
629         char buf[SIZ];
630
631         if (!strcmp(WC->ugname, "")) {
632                 smart_goto(WC->wc_roomname);
633                 return;
634         }
635         serv_printf("GOTO %s", WC->ugname);
636         serv_gets(buf);
637         if (buf[0] != '2') {
638                 smart_goto(WC->wc_roomname);
639                 return;
640         }
641         if (WC->uglsn >= 0L) {
642                 serv_printf("SLRP %ld", WC->uglsn);
643                 serv_gets(buf);
644         }
645         strcpy(buf, WC->ugname);
646         strcpy(WC->ugname, "");
647         smart_goto(buf);
648 }
649
650
651
652
653
654 /*
655  * Set/clear/read the "self-service list subscribe" flag for a room
656  * 
657  * Set 'newval' to 0 to clear, 1 to set, any other value to leave unchanged.
658  * Always returns the new value.
659  */
660
661 int self_service(int newval) {
662         int current_value = 0;
663         char buf[SIZ];
664         
665         char name[SIZ];
666         char password[SIZ];
667         char dirname[SIZ];
668         int flags, floor, order, view, flags2;
669
670         serv_puts("GETR");
671         serv_gets(buf);
672         if (buf[0] != '2') return(0);
673
674         extract(name, &buf[4], 0);
675         extract(password, &buf[4], 1);
676         extract(dirname, &buf[4], 2);
677         flags = extract_int(&buf[4], 3);
678         floor = extract_int(&buf[4], 4);
679         order = extract_int(&buf[4], 5);
680         view = extract_int(&buf[4], 6);
681         flags2 = extract_int(&buf[4], 7);
682
683         if (flags2 & QR2_SELFLIST) {
684                 current_value = 1;
685         }
686         else {
687                 current_value = 0;
688         }
689
690         if (newval == 1) {
691                 flags2 = flags2 | QR2_SELFLIST;
692         }
693         else if (newval == 0) {
694                 flags2 = flags2 & ~QR2_SELFLIST;
695         }
696         else {
697                 return(current_value);
698         }
699
700         if (newval != current_value) {
701                 serv_printf("SETR %s|%s|%s|%d|0|%d|%d|%d|%d",
702                         name, password, dirname, flags,
703                         floor, order, view, flags2);
704                 serv_gets(buf);
705         }
706
707         return(newval);
708
709 }
710
711
712
713
714
715
716 /*
717  * display the form for editing a room
718  */
719 void display_editroom(void)
720 {
721         char buf[SIZ];
722         char cmd[SIZ];
723         char node[SIZ];
724         char recp[SIZ];
725         char er_name[20];
726         char er_password[10];
727         char er_dirname[15];
728         char er_roomaide[26];
729         unsigned er_flags;
730         int er_floor;
731         int i, j;
732         char *tab;
733         char *shared_with;
734         char *not_shared_with;
735
736         tab = bstr("tab");
737         if (strlen(tab) == 0) tab = "admin";
738
739         serv_puts("GETR");
740         serv_gets(buf);
741
742         if (buf[0] != '2') {
743                 display_error(&buf[4]);
744                 return;
745         }
746         extract(er_name, &buf[4], 0);
747         extract(er_password, &buf[4], 1);
748         extract(er_dirname, &buf[4], 2);
749         er_flags = extract_int(&buf[4], 3);
750         er_floor = extract_int(&buf[4], 4);
751
752         output_headers(1);
753
754         /* print the tabbed dialog */
755         wprintf("<TABLE border=0 cellspacing=0 cellpadding=0 width=100%%>"
756                 "<TR ALIGN=CENTER BGCOLOR=\"#FFFFFF\">"
757                 "<TD>&nbsp;</TD>\n");
758
759         if (!strcmp(tab, "admin")) {
760                 wprintf("<TD BGCOLOR=\"#000077\"><SPAN CLASS=\"tablabel\">");
761         }
762         else {
763                 wprintf("<TD BGCOLOR=\"#AAAAAA\"><A HREF=\"/display_editroom&tab=admin\">");
764         }
765         wprintf("Room administration");
766         if (!strcmp(tab, "admin")) {
767                 wprintf("</SPAN></TD>\n");
768         }
769         else {
770                 wprintf("</A></TD>\n");
771         }
772
773         wprintf("<TD>&nbsp;</TD>\n");
774
775         if (!strcmp(tab, "config")) {
776                 wprintf("<TD BGCOLOR=\"#000077\"><SPAN CLASS=\"tablabel\">");
777         }
778         else {
779                 wprintf("<TD BGCOLOR=\"#AAAAAA\"><A HREF=\"/display_editroom&tab=config\">");
780         }
781         wprintf("Room configuration");
782         if (!strcmp(tab, "config")) {
783                 wprintf("</SPAN></TD>\n");
784         }
785         else {
786                 wprintf("</A></TD>\n");
787         }
788
789         wprintf("<TD>&nbsp;</TD>\n");
790
791         if (!strcmp(tab, "sharing")) {
792                 wprintf("<TD BGCOLOR=\"#000077\"><SPAN CLASS=\"tablabel\">");
793         }
794         else {
795                 wprintf("<TD BGCOLOR=\"#AAAAAA\"><A HREF=\"/display_editroom&tab=sharing\">");
796         }
797         wprintf("Sharing");
798         if (!strcmp(tab, "sharing")) {
799                 wprintf("</SPAN></TD>\n");
800         }
801         else {
802                 wprintf("</A></TD>\n");
803         }
804
805         wprintf("<TD>&nbsp;</TD>\n");
806
807         if (!strcmp(tab, "listserv")) {
808                 wprintf("<TD BGCOLOR=\"#000077\"><SPAN CLASS=\"tablabel\">");
809         }
810         else {
811                 wprintf("<TD BGCOLOR=\"#AAAAAA\"><A HREF=\"/display_editroom&tab=listserv\">");
812         }
813         wprintf("Mailing list service");
814         if (!strcmp(tab, "listserv")) {
815                 wprintf("</SPAN></TD>\n");
816         }
817         else {
818                 wprintf("</A></TD>\n");
819         }
820
821         wprintf("<TD>&nbsp;</TD></TR>"
822                 "<TR><TD BGCOLOR=\"#000077\" COLSPAN=9 HEIGHT=5> </TD></TR>"
823                 "</TABLE>\n");
824
825         /* end tabbed dialog */ 
826
827
828         if (!strcmp(tab, "admin")) {
829                 wprintf("<UL>"
830                         "<LI><A HREF=\"/confirm_delete_room\">\n"
831                         "Delete this room</A>\n"
832                         "<LI><A HREF=\"/display_editroompic\">\n"
833                         "Set or change the graphic for this room's banner</A>\n"
834                         "<LI><A HREF=\"/display_editinfo\">\n"
835                         "Edit this room's Info file</A>\n"
836                         "</UL>");
837         }
838
839         if (!strcmp(tab, "config")) {
840                 wprintf("<FORM METHOD=\"POST\" ACTION=\"/editroom\">\n");
841         
842                 wprintf("<UL><LI>Name of room: ");
843                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", er_name);
844         
845                 wprintf("<LI>Resides on floor: ");
846                 load_floorlist();
847                 wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
848                 for (i = 0; i < 128; ++i)
849                         if (strlen(floorlist[i]) > 0) {
850                                 wprintf("<OPTION ");
851                                 if (i == er_floor)
852                                         wprintf("SELECTED ");
853                                 wprintf("VALUE=\"%d\">", i);
854                                 escputs(floorlist[i]);
855                                 wprintf("</OPTION>\n");
856                         }
857                 wprintf("</SELECT>\n");
858         
859                 wprintf("<LI>Type of room:<UL>\n");
860
861                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
862                 if ((er_flags & QR_PRIVATE) == 0)
863                 wprintf("CHECKED ");
864                 wprintf("> Public room\n");
865
866                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
867                 if ((er_flags & QR_PRIVATE) &&
868                     (er_flags & QR_GUESSNAME))
869                         wprintf("CHECKED ");
870                 wprintf("> Private - guess name\n");
871         
872                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
873                 if ((er_flags & QR_PRIVATE) &&
874                     (er_flags & QR_PASSWORDED))
875                         wprintf("CHECKED ");
876                 wprintf("> Private - require password:\n");
877                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" VALUE=\"%s\" MAXLENGTH=\"9\">\n", er_password);
878         
879                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
880                 if ((er_flags & QR_PRIVATE)
881                     && ((er_flags & QR_GUESSNAME) == 0)
882                     && ((er_flags & QR_PASSWORDED) == 0))
883                         wprintf("CHECKED ");
884                 wprintf("> Private - invitation only\n");
885         
886                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"bump\" VALUE=\"yes\" ");
887                 wprintf("> If private, cause current users to forget room\n");
888         
889                 wprintf("</UL>\n");
890         
891                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"prefonly\" VALUE=\"yes\" ");
892                 if (er_flags & QR_PREFONLY)
893                         wprintf("CHECKED ");
894                 wprintf("> Preferred users only\n");
895         
896                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"readonly\" VALUE=\"yes\" ");
897                 if (er_flags & QR_READONLY)
898                         wprintf("CHECKED ");
899                 wprintf("> Read-only room\n");
900         
901         /* directory stuff */
902                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"directory\" VALUE=\"yes\" ");
903                 if (er_flags & QR_DIRECTORY)
904                         wprintf("CHECKED ");
905                 wprintf("> File directory room\n");
906
907                 wprintf("<UL><LI>Directory name: ");
908                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_dirname\" VALUE=\"%s\" MAXLENGTH=\"14\">\n", er_dirname);
909
910                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"ulallowed\" VALUE=\"yes\" ");
911                 if (er_flags & QR_UPLOAD)
912                         wprintf("CHECKED ");
913                 wprintf("> Uploading allowed\n");
914         
915                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"dlallowed\" VALUE=\"yes\" ");
916                 if (er_flags & QR_DOWNLOAD)
917                         wprintf("CHECKED ");
918                 wprintf("> Downloading allowed\n");
919         
920                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"visdir\" VALUE=\"yes\" ");
921                 if (er_flags & QR_VISDIR)
922                         wprintf("CHECKED ");
923                 wprintf("> Visible directory</UL>\n");
924         
925         /* end of directory stuff */
926         
927                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"network\" VALUE=\"yes\" ");
928                 if (er_flags & QR_NETWORK)
929                         wprintf("CHECKED ");
930                 wprintf("> Network shared room\n");
931
932         /* start of anon options */
933         
934                 wprintf("<LI>Anonymous messages<UL>\n");
935         
936                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"no\" ");
937                 if (((er_flags & QR_ANONONLY) == 0)
938                     && ((er_flags & QR_ANONOPT) == 0))
939                         wprintf("CHECKED ");
940                 wprintf("> No anonymous messages\n");
941         
942                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anononly\" ");
943                 if (er_flags & QR_ANONONLY)
944                         wprintf("CHECKED ");
945                 wprintf("> All messages are anonymous\n");
946         
947                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anon2\" ");
948                 if (er_flags & QR_ANONOPT)
949                         wprintf("CHECKED ");
950                 wprintf("> Prompt user when entering messages</UL>\n");
951         
952         /* end of anon options */
953         
954                 wprintf("<LI>Room aide: \n");
955                 serv_puts("GETA");
956                 serv_gets(buf);
957                 if (buf[0] != '2') {
958                         wprintf("<EM>%s</EM>\n", &buf[4]);
959                 } else {
960                         extract(er_roomaide, &buf[4], 0);
961                         wprintf("<INPUT TYPE=\"text\" NAME=\"er_roomaide\" VALUE=\"%s\" MAXLENGTH=\"25\">\n", er_roomaide);
962                 }
963         
964                 wprintf("</UL><CENTER>\n");
965                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
966                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
967                 wprintf("</CENTER>\n");
968         }
969
970
971         /* Sharing the room with other Citadel nodes... */
972         if (!strcmp(tab, "sharing")) {
973
974                 shared_with = strdup("");
975                 not_shared_with = strdup("");
976
977                 /* Learn the current configuration */
978                 serv_puts("CONF getsys|application/x-citadel-ignet-config");
979                 serv_gets(buf);
980                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
981                         extract(node, buf, 0);
982                         not_shared_with = realloc(not_shared_with,
983                                         strlen(not_shared_with) + 32);
984                         strcat(not_shared_with, node);
985                         strcat(not_shared_with, "|");
986                 }
987
988                 serv_puts("GNET");
989                 serv_gets(buf);
990                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
991                         extract(cmd, buf, 0);
992                         extract(node, buf, 1);
993                         if (!strcasecmp(cmd, "ignet_push_share")) {
994                                 shared_with = realloc(shared_with,
995                                                 strlen(shared_with) + 32);
996                                 strcat(shared_with, node);
997                                 strcat(shared_with, "|");
998                         }
999                 }
1000
1001                 for (i=0; i<num_tokens(shared_with, '|'); ++i) {
1002                         extract(node, shared_with, i);
1003                         for (j=0; j<num_tokens(not_shared_with, '|'); ++j) {
1004                                 extract(cmd, not_shared_with, j);
1005                                 if (!strcasecmp(node, cmd)) {
1006                                         remove_token(not_shared_with, j, '|');
1007                                 }
1008                         }
1009                 }
1010
1011                 /* Display the stuff */
1012                 wprintf("<CENTER><BR>"
1013                         "<TABLE border=1 cellpadding=5><TR>"
1014                         "<TD><B><I>Shared with</I></B></TD>"
1015                         "<TD><B><I>Not shared with</I></B></TD></TR>\n"
1016                         "<TR><TD>\n");
1017
1018                 for (i=0; i<num_tokens(shared_with, '|'); ++i) {
1019                         extract(node, shared_with, i);
1020                         if (strlen(node) > 0) {
1021                                 wprintf("%s ", node);
1022                                 wprintf("<A HREF=\"/netedit&cmd=remove&line="
1023                                         "ignet_push_share|");
1024                                 urlescputs(node);
1025                                 wprintf("&tab=sharing\">(unshare)</A><BR>");
1026                         }
1027                 }
1028
1029                 wprintf("</TD><TD>\n");
1030
1031                 for (i=0; i<num_tokens(not_shared_with, '|'); ++i) {
1032                         extract(node, not_shared_with, i);
1033                         if (strlen(node) > 0) {
1034                                 wprintf("%s ", node);
1035                                 wprintf("<A HREF=\"/netedit&cmd=add&line="
1036                                         "ignet_push_share|");
1037                                 urlescputs(node);
1038                                 wprintf("&tab=sharing\">(share)</A><BR>");
1039                         }
1040                 }
1041
1042                 wprintf("</TD></TR>"
1043                         "</TABLE><BR>\n"
1044                         "<I><B>Reminder:</B> When sharing a room, "
1045                         "it must be shared from both ends.  Adding a node to "
1046                         "the 'shared' list sends messages out, but in order to"
1047                         " receive messages, the other nodes must be configured"
1048                         " to send messages out to your system as well.</I><BR>"
1049                         "</CENTER>\n");
1050
1051         }
1052
1053         /* Mailing list management */
1054         if (!strcmp(tab, "listserv")) {
1055
1056                 wprintf("<BR><center>"
1057                         "<TABLE BORDER=0 WIDTH=100%% CELLPADDING=5>"
1058                         "<TR><TD VALIGN=TOP>");
1059
1060                 wprintf("<i>The contents of this room are being "
1061                         "mailed <b>as individual messages</b> "
1062                         "to the following list recipients:"
1063                         "</i><br><br>\n");
1064
1065                 serv_puts("GNET");
1066                 serv_gets(buf);
1067                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
1068                         extract(cmd, buf, 0);
1069                         if (!strcasecmp(cmd, "listrecp")) {
1070                                 extract(recp, buf, 1);
1071                         
1072                                 escputs(recp);
1073                                 wprintf(" <A HREF=\"/netedit&cmd=remove&line="
1074                                         "listrecp|");
1075                                 urlescputs(recp);
1076                                 wprintf("&tab=listserv\">(remove)</A><BR>");
1077
1078                         }
1079                 }
1080                 wprintf("<BR><FORM METHOD=\"POST\" ACTION=\"/netedit\">\n"
1081                         "<INPUT TYPE=\"hidden\" NAME=\"tab\" VALUE=\"listserv\">\n"
1082                         "<INPUT TYPE=\"hidden\" NAME=\"prefix\" VALUE=\"listrecp|\">\n");
1083                 wprintf("<INPUT TYPE=\"text\" NAME=\"line\">\n");
1084                 wprintf("<INPUT TYPE=\"submit\" NAME=\"cmd\" VALUE=\"Add\">");
1085                 wprintf("</FORM>\n");
1086
1087                 wprintf("</TD><TD VALIGN=TOP>\n");
1088                 
1089                 wprintf("<i>The contents of this room are being "
1090                         "mailed <b>in digest form</b> "
1091                         "to the following list recipients:"
1092                         "</i><br><br>\n");
1093
1094                 serv_puts("GNET");
1095                 serv_gets(buf);
1096                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
1097                         extract(cmd, buf, 0);
1098                         if (!strcasecmp(cmd, "digestrecp")) {
1099                                 extract(recp, buf, 1);
1100                         
1101                                 escputs(recp);
1102                                 wprintf(" <A HREF=\"/netedit&cmd=remove&line="
1103                                         "digestrecp|");
1104                                 urlescputs(recp);
1105                                 wprintf("&tab=listserv\">(remove)</A><BR>");
1106
1107                         }
1108                 }
1109                 wprintf("<BR><FORM METHOD=\"POST\" ACTION=\"/netedit\">\n"
1110                         "<INPUT TYPE=\"hidden\" NAME=\"tab\" VALUE=\"listserv\">\n"
1111                         "<INPUT TYPE=\"hidden\" NAME=\"prefix\" VALUE=\"digestrecp|\">\n");
1112                 wprintf("<INPUT TYPE=\"text\" NAME=\"line\">\n");
1113                 wprintf("<INPUT TYPE=\"submit\" NAME=\"cmd\" VALUE=\"Add\">");
1114                 wprintf("</FORM>\n");
1115                 
1116                 wprintf("</TD></TR></TABLE><HR>\n");
1117
1118                 if (self_service(999) == 1) {
1119                         wprintf("This room is configured to allow "
1120                                 "self-service subscribe/unsubscribe requests."
1121                                 " <A HREF=\"/toggle_self_service?newval=0&"
1122                                 "tab=listserv\">"
1123                                 "Click to disable.</A><BR>\n"
1124                                 "The URL for subscribe/unsubscribe is: "
1125                                 "<TT>http://%s/listsub</TT><BR>\n",
1126                                 WC->http_host
1127                         );
1128                 }
1129                 else {
1130                         wprintf("This room is <i>not</i> configured to allow "
1131                                 "self-service subscribe/unsubscribe requests."
1132                                 " <A HREF=\"/toggle_self_service?newval=1&"
1133                                 "tab=listserv\">"
1134                                 "Click to enable.</A><BR>\n"
1135                         );
1136                 }
1137
1138
1139                 wprintf("</CENTER>\n");
1140         }
1141
1142         wDumpContent(1);
1143 }
1144
1145
1146 /* 
1147  * Toggle self-service list subscription
1148  */
1149 void toggle_self_service(void) {
1150         int newval = 0;
1151
1152         newval = atoi(bstr("newval"));
1153         self_service(newval);
1154         display_editroom();
1155 }
1156
1157
1158
1159 /*
1160  * save new parameters for a room
1161  */
1162 void editroom(void)
1163 {
1164         char buf[SIZ];
1165         char er_name[20];
1166         char er_password[10];
1167         char er_dirname[15];
1168         char er_roomaide[26];
1169         int er_floor;
1170         unsigned er_flags;
1171         int bump;
1172
1173
1174         if (strcmp(bstr("sc"), "OK")) {
1175                 display_error("Cancelled.  Changes were not saved.");
1176                 return;
1177         }
1178         serv_puts("GETR");
1179         serv_gets(buf);
1180
1181         if (buf[0] != '2') {
1182                 display_error(&buf[4]);
1183                 return;
1184         }
1185         extract(er_name, &buf[4], 0);
1186         extract(er_password, &buf[4], 1);
1187         extract(er_dirname, &buf[4], 2);
1188         er_flags = extract_int(&buf[4], 3);
1189
1190         strcpy(er_roomaide, bstr("er_roomaide"));
1191         if (strlen(er_roomaide) == 0) {
1192                 serv_puts("GETA");
1193                 serv_gets(buf);
1194                 if (buf[0] != '2') {
1195                         strcpy(er_roomaide, "");
1196                 } else {
1197                         extract(er_roomaide, &buf[4], 0);
1198                 }
1199         }
1200         strcpy(buf, bstr("er_name"));
1201         buf[20] = 0;
1202         if (strlen(buf) > 0)
1203                 strcpy(er_name, buf);
1204
1205         strcpy(buf, bstr("er_password"));
1206         buf[10] = 0;
1207         if (strlen(buf) > 0)
1208                 strcpy(er_password, buf);
1209
1210         strcpy(buf, bstr("er_dirname"));
1211         buf[15] = 0;
1212         if (strlen(buf) > 0)
1213                 strcpy(er_dirname, buf);
1214
1215         strcpy(buf, bstr("type"));
1216         er_flags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
1217
1218         if (!strcmp(buf, "invonly")) {
1219                 er_flags |= (QR_PRIVATE);
1220         }
1221         if (!strcmp(buf, "guessname")) {
1222                 er_flags |= (QR_PRIVATE | QR_GUESSNAME);
1223         }
1224         if (!strcmp(buf, "passworded")) {
1225                 er_flags |= (QR_PRIVATE | QR_PASSWORDED);
1226         }
1227         if (!strcmp(bstr("prefonly"), "yes")) {
1228                 er_flags |= QR_PREFONLY;
1229         } else {
1230                 er_flags &= ~QR_PREFONLY;
1231         }
1232
1233         if (!strcmp(bstr("readonly"), "yes")) {
1234                 er_flags |= QR_READONLY;
1235         } else {
1236                 er_flags &= ~QR_READONLY;
1237         }
1238
1239         if (!strcmp(bstr("network"), "yes")) {
1240                 er_flags |= QR_NETWORK;
1241         } else {
1242                 er_flags &= ~QR_NETWORK;
1243         }
1244
1245         if (!strcmp(bstr("directory"), "yes")) {
1246                 er_flags |= QR_DIRECTORY;
1247         } else {
1248                 er_flags &= ~QR_DIRECTORY;
1249         }
1250
1251         if (!strcmp(bstr("ulallowed"), "yes")) {
1252                 er_flags |= QR_UPLOAD;
1253         } else {
1254                 er_flags &= ~QR_UPLOAD;
1255         }
1256
1257         if (!strcmp(bstr("dlallowed"), "yes")) {
1258                 er_flags |= QR_DOWNLOAD;
1259         } else {
1260                 er_flags &= ~QR_DOWNLOAD;
1261         }
1262
1263         if (!strcmp(bstr("visdir"), "yes")) {
1264                 er_flags |= QR_VISDIR;
1265         } else {
1266                 er_flags &= ~QR_VISDIR;
1267         }
1268
1269         strcpy(buf, bstr("anon"));
1270
1271         er_flags &= ~(QR_ANONONLY | QR_ANONOPT);
1272         if (!strcmp(buf, "anononly"))
1273                 er_flags |= QR_ANONONLY;
1274         if (!strcmp(buf, "anon2"))
1275                 er_flags |= QR_ANONOPT;
1276
1277         bump = 0;
1278         if (!strcmp(bstr("bump"), "yes"))
1279                 bump = 1;
1280
1281         er_floor = atoi(bstr("er_floor"));
1282
1283         sprintf(buf, "SETR %s|%s|%s|%u|%d|%d",
1284              er_name, er_password, er_dirname, er_flags, bump, er_floor);
1285         serv_puts(buf);
1286         serv_gets(buf);
1287         if (buf[0] != '2') {
1288                 display_error(&buf[4]);
1289                 return;
1290         }
1291         gotoroom(er_name, 0);
1292
1293         if (strlen(er_roomaide) > 0) {
1294                 sprintf(buf, "SETA %s", er_roomaide);
1295                 serv_puts(buf);
1296                 serv_gets(buf);
1297                 if (buf[0] != '2') {
1298                         display_error(&buf[4]);
1299                         return;
1300                 }
1301         }
1302         smart_goto(er_name);
1303 }
1304
1305 /*
1306  * Invite, Kick, and show Who Knows a room
1307  */
1308 void display_whok(void)
1309 {
1310         char buf[SIZ], room[SIZ], username[SIZ];
1311
1312         serv_puts("GETR");
1313         serv_gets(buf);
1314
1315         if (buf[0] != '2') {
1316                 display_error(&buf[4]);
1317                 return;
1318         }
1319         extract(room, &buf[4], 0);
1320
1321         strcpy(username, bstr("username"));
1322
1323         output_headers(1);
1324
1325         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#007700\"><TR><TD>");
1326         wprintf("<SPAN CLASS=\"titlebar\">Access control list for ");
1327         escputs(WC->wc_roomname);
1328         wprintf("</SPAN></TD></TR></TABLE>\n");
1329
1330         if(!strcmp(bstr("sc"), "Kick")) {
1331                 sprintf(buf, "KICK %s", username);
1332                 serv_puts(buf);
1333                 serv_gets(buf);
1334
1335                 if (buf[0] != '2') {
1336                         display_error(&buf[4]);
1337                         return;
1338                 } else {
1339                         wprintf("<B><I>User %s kicked out of room %s.</I></B>\n", 
1340                                 username, room);
1341                 }
1342         } else if(!strcmp(bstr("sc"), "Invite")) {
1343                 sprintf(buf, "INVT %s", username);
1344                 serv_puts(buf);
1345                 serv_gets(buf);
1346
1347                 if (buf[0] != '2') {
1348                         display_error(&buf[4]);
1349                         return;
1350                 } else {
1351                         wprintf("<B><I>User %s invited to room %s.</I></B>\n", 
1352                                 username, room);
1353                 }
1354         }
1355         
1356
1357
1358         wprintf("<TABLE border=0 CELLSPACING=10><TR VALIGN=TOP>"
1359                 "<TD>The users listed below have access to this room.  "
1360                 "To remove a user from the access list, select the user "
1361                 "name from the list and click 'Kick'.<BR><BR>");
1362         
1363         wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/display_whok\">\n");
1364         wprintf("<SELECT NAME=\"username\" SIZE=10>\n");
1365         serv_puts("WHOK");
1366         serv_gets(buf);
1367         if (buf[0] == '1') {
1368                 while (serv_gets(buf), strcmp(buf, "000")) {
1369                         extract(username, buf, 0);
1370                         wprintf("<OPTION>");
1371                         escputs(username);
1372                         wprintf("\n");
1373                 }
1374         }
1375         wprintf("</SELECT><BR>\n");
1376
1377         wprintf("<input type=submit name=sc value=\"Kick\">");
1378         wprintf("</FORM></CENTER>\n");
1379
1380         wprintf("</TD><TD>"
1381                 "To grant another user access to this room, enter the "
1382                 "user name in the box below and click 'Invite'.<BR><BR>");
1383
1384         wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/display_whok\">\n");
1385         wprintf("Invite: ");
1386         wprintf("<input type=text name=username><BR>\n"
1387                 "<input type=hidden name=sc value=\"Invite\">"
1388                 "<input type=submit value=\"Invite\">"
1389                 "</FORM></CENTER>\n");
1390
1391         wprintf("</TD></TR></TABLE>\n");
1392         wDumpContent(1);
1393 }
1394
1395
1396
1397 /*
1398  * display the form for entering a new room
1399  */
1400 void display_entroom(void)
1401 {
1402         int i;
1403         char buf[SIZ];
1404
1405         serv_puts("CRE8 0");
1406         serv_gets(buf);
1407
1408         if (buf[0] != '2') {
1409                 display_error(&buf[4]);
1410                 return;
1411         }
1412         output_headers(1);
1413
1414         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#000077\"><TR><TD>");
1415         wprintf("<SPAN CLASS=\"titlebar\">Enter (create) a new room</SPAN>\n");
1416         wprintf("</TD></TR></TABLE>\n");
1417
1418         wprintf("<FORM METHOD=\"POST\" ACTION=\"/entroom\">\n");
1419
1420         wprintf("<UL><LI>Name of room: ");
1421         wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" MAXLENGTH=\"19\">\n");
1422
1423         wprintf("<LI>Type of room:<UL>\n");
1424
1425         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
1426         wprintf("CHECKED > Public room\n");
1427
1428         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
1429         wprintf("> Private - guess name\n");
1430
1431         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
1432         wprintf("> Private - require password:\n");
1433         wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" MAXLENGTH=\"9\">\n");
1434
1435         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
1436         wprintf("> Private - invitation only\n");
1437         wprintf("</UL>\n");
1438
1439         wprintf("<LI>Resides on floor: ");
1440         load_floorlist(); 
1441         wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
1442         for (i = 0; i < 128; ++i)
1443                 if (strlen(floorlist[i]) > 0) {
1444                         wprintf("<OPTION ");
1445                         wprintf("VALUE=\"%d\">", i);
1446                         escputs(floorlist[i]);
1447                         wprintf("</OPTION>\n");
1448                 }
1449         wprintf("</SELECT>\n");                
1450         wprintf("</UL>\n");
1451
1452
1453         wprintf("<CENTER>\n");
1454         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1455         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1456         wprintf("</CENTER>\n");
1457         wprintf("</FORM>\n<HR>");
1458         serv_printf("MESG roomaccess");
1459         serv_gets(buf);
1460         if (buf[0] == '1') {
1461                 fmout(NULL);
1462         }
1463         wDumpContent(1);
1464 }
1465
1466
1467
1468 /*
1469  * enter a new room
1470  */
1471 void entroom(void)
1472 {
1473         char buf[SIZ];
1474         char er_name[20];
1475         char er_type[20];
1476         char er_password[10];
1477         int er_floor;
1478         int er_num_type;
1479
1480         if (strcmp(bstr("sc"), "OK")) {
1481                 display_error("Cancelled.  No new room was created.");
1482                 return;
1483         }
1484         strcpy(er_name, bstr("er_name"));
1485         strcpy(er_type, bstr("type"));
1486         strcpy(er_password, bstr("er_password"));
1487         er_floor = atoi(bstr("er_floor"));
1488
1489         er_num_type = 0;
1490         if (!strcmp(er_type, "guessname"))
1491                 er_num_type = 1;
1492         if (!strcmp(er_type, "passworded"))
1493                 er_num_type = 2;
1494         if (!strcmp(er_type, "invonly"))
1495                 er_num_type = 3;
1496
1497         sprintf(buf, "CRE8 1|%s|%d|%s|%d", 
1498                 er_name, er_num_type, er_password, er_floor);
1499         serv_puts(buf);
1500         serv_gets(buf);
1501         if (buf[0] != '2') {
1502                 display_error(&buf[4]);
1503                 return;
1504         }
1505         smart_goto(er_name);
1506 }
1507
1508
1509 /*
1510  * display the screen to enter a private room
1511  */
1512 void display_private(char *rname, int req_pass)
1513 {
1514
1515         output_headers(1);
1516
1517         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
1518         wprintf("<SPAN CLASS=\"titlebar\">Goto a private room</SPAN>\n");
1519         wprintf("</TD></TR></TABLE>\n");
1520
1521         wprintf("<CENTER>\n");
1522         wprintf("If you know the name of a hidden (guess-name) or\n");
1523         wprintf("passworded room, you can enter that room by typing\n");
1524         wprintf("its name below.  Once you gain access to a private\n");
1525         wprintf("room, it will appear in your regular room listings\n");
1526         wprintf("so you don't have to keep returning here.\n");
1527         wprintf("<BR><BR>");
1528
1529         wprintf("<FORM METHOD=\"GET\" ACTION=\"/goto_private\">\n");
1530
1531         wprintf("<TABLE border><TR><TD>");
1532         wprintf("Enter room name:</TD><TD>");
1533         wprintf("<INPUT TYPE=\"text\" NAME=\"gr_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", rname);
1534
1535         if (req_pass) {
1536                 wprintf("</TD></TR><TR><TD>");
1537                 wprintf("Enter room password:</TD><TD>");
1538                 wprintf("<INPUT TYPE=\"password\" NAME=\"gr_pass\" MAXLENGTH=\"9\">\n");
1539         }
1540         wprintf("</TD></TR></TABLE>\n");
1541
1542         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1543         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1544         wprintf("</FORM>\n");
1545         wDumpContent(1);
1546 }
1547
1548 /* 
1549  * goto a private room
1550  */
1551 void goto_private(void)
1552 {
1553         char hold_rm[SIZ];
1554         char buf[SIZ];
1555
1556         if (strcasecmp(bstr("sc"), "OK")) {
1557                 display_main_menu();
1558                 return;
1559         }
1560         strcpy(hold_rm, WC->wc_roomname);
1561         strcpy(buf, "GOTO ");
1562         strcat(buf, bstr("gr_name"));
1563         strcat(buf, "|");
1564         strcat(buf, bstr("gr_pass"));
1565         serv_puts(buf);
1566         serv_gets(buf);
1567
1568         if (buf[0] == '2') {
1569                 smart_goto(bstr("gr_name"));
1570                 return;
1571         }
1572         if (!strncmp(buf, "540", 3)) {
1573                 display_private(bstr("gr_name"), 1);
1574                 return;
1575         }
1576         output_headers(1);
1577         wprintf("%s\n", &buf[4]);
1578         wDumpContent(1);
1579         return;
1580 }
1581
1582
1583 /*
1584  * display the screen to zap a room
1585  */
1586 void display_zap(void)
1587 {
1588         output_headers(1);
1589
1590         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
1591         wprintf("<SPAN CLASS=\"titlebar\">Zap (forget) the current room</SPAN>\n");
1592         wprintf("</TD></TR></TABLE>\n");
1593
1594         wprintf("If you select this option, <em>%s</em> will ", WC->wc_roomname);
1595         wprintf("disappear from your room list.  Is this what you wish ");
1596         wprintf("to do?<BR>\n");
1597
1598         wprintf("<FORM METHOD=\"GET\" ACTION=\"/zap\">\n");
1599         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1600         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1601         wprintf("</FORM>\n");
1602         wDumpContent(1);
1603 }
1604
1605
1606 /* 
1607  * zap a room
1608  */
1609 void zap(void)
1610 {
1611         char buf[SIZ];
1612         char final_destination[SIZ];
1613
1614         /* If the forget-room routine fails for any reason, we fall back
1615          * to the current room; otherwise, we go to the Lobby
1616          */
1617         strcpy(final_destination, WC->wc_roomname);
1618
1619         if (!strcasecmp(bstr("sc"), "OK")) {
1620                 serv_printf("GOTO %s", WC->wc_roomname);
1621                 serv_gets(buf);
1622                 if (buf[0] != '2') {
1623                         /* ExpressMessageCat(&buf[4]); */
1624                 } else {
1625                         serv_puts("FORG");
1626                         serv_gets(buf);
1627                         if (buf[0] != '2') {
1628                                 /* ExpressMessageCat(&buf[4]); */
1629                         } else {
1630                                 strcpy(final_destination, "_BASEROOM_");
1631                         }
1632                 }
1633         }
1634         smart_goto(final_destination);
1635 }
1636
1637
1638
1639
1640 /*
1641  * Confirm deletion of the current room
1642  */
1643 void confirm_delete_room(void)
1644 {
1645         char buf[SIZ];
1646
1647         serv_puts("KILL 0");
1648         serv_gets(buf);
1649         if (buf[0] != '2') {
1650                 display_error(&buf[4]);
1651                 return;
1652         }
1653         output_headers(1);
1654         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
1655         wprintf("<SPAN CLASS=\"titlebar\">Confirm deletion of room</SPAN>\n");
1656         wprintf("</TD></TR></TABLE>\n");
1657
1658         wprintf("<CENTER>");
1659         wprintf("<FORM METHOD=\"GET\" ACTION=\"/delete_room\">\n");
1660
1661         wprintf("Are you sure you want to delete <FONT SIZE=+1>");
1662         escputs(WC->wc_roomname);
1663         wprintf("</FONT>?<BR>\n");
1664
1665         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">");
1666         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1667
1668         wprintf("</FORM></CENTER>\n");
1669         wDumpContent(1);
1670 }
1671
1672
1673 /*
1674  * Delete the current room
1675  */
1676 void delete_room(void)
1677 {
1678         char buf[SIZ];
1679         char sc[SIZ];
1680
1681         strcpy(sc, bstr("sc"));
1682
1683         if (strcasecmp(sc, "Delete")) {
1684                 display_error("Cancelled.  This room was not deleted.");
1685                 return;
1686         }
1687         serv_puts("KILL 1");
1688         serv_gets(buf);
1689         if (buf[0] != '2') {
1690                 display_error(&buf[4]);
1691         } else {
1692                 smart_goto("_BASEROOM_");
1693         }
1694 }
1695
1696
1697
1698 /*
1699  * Perform changes to a room's network configuration
1700  */
1701 void netedit(void) {
1702         FILE *fp;
1703         char buf[SIZ];
1704         char line[SIZ];
1705
1706         if (strlen(bstr("line"))==0) {
1707                 display_editroom();
1708                 return;
1709         }
1710
1711         strcpy(line, bstr("prefix"));
1712         strcat(line, bstr("line"));
1713         strcat(line, bstr("suffix"));
1714
1715         fp = tmpfile();
1716         if (fp == NULL) {
1717                 display_editroom();
1718                 return;
1719         }
1720
1721         serv_puts("GNET");
1722         serv_gets(buf);
1723         if (buf[0] != '1') {
1724                 fclose(fp);
1725                 display_editroom();
1726                 return;
1727         }
1728
1729         /* This loop works for add *or* remove.  Spiffy, eh? */
1730         while (serv_gets(buf), strcmp(buf, "000")) {
1731                 if (strcasecmp(buf, line)) {
1732                         fprintf(fp, "%s\n", buf);
1733                 }
1734         }
1735
1736         rewind(fp);
1737         serv_puts("SNET");
1738         serv_gets(buf);
1739         if (buf[0] != '4') {
1740                 fclose(fp);
1741                 display_editroom();
1742                 return;
1743         }
1744
1745         while (fgets(buf, sizeof buf, fp) != NULL) {
1746                 buf[strlen(buf)-1] = 0;
1747                 serv_puts(buf);
1748         }
1749
1750         if (!strcasecmp(bstr("cmd"), "add")) {
1751                 serv_puts(line);
1752         }
1753
1754         serv_puts("000");
1755         fclose(fp);
1756         display_editroom();
1757 }
1758
1759
1760
1761 /*
1762  * Convert a room name to a folder-ish-looking name.
1763  */
1764 void room_to_folder(char *folder, char *room, int floor, int is_mailbox)
1765 {
1766         int i;
1767
1768         /*
1769          * For mailboxes, just do it straight...
1770          */
1771         if (is_mailbox) {
1772                 sprintf(folder, "My folders|%s", room);
1773         }
1774
1775         /*
1776          * Otherwise, prefix the floor name as a "public folders" moniker
1777          */
1778         else {
1779                 sprintf(folder, "%s|%s", floorlist[floor], room);
1780         }
1781
1782         /*
1783          * Replace "\" characters with "|" for pseudo-folder-delimiting
1784          */
1785         for (i=0; i<strlen(folder); ++i) {
1786                 if (folder[i] == '\\') folder[i] = '|';
1787         }
1788 }
1789
1790
1791
1792
1793
1794
1795
1796 /*
1797  * Change the view for this room
1798  */
1799 void change_view(void) {
1800         int view;
1801         char buf[SIZ];
1802
1803         view = atol(bstr("view"));
1804
1805         serv_printf("VIEW %d", view);
1806         serv_gets(buf);
1807         smart_goto(WC->wc_roomname);
1808 }
1809
1810
1811 /*
1812  * One big expanded tree list view --- like a folder list
1813  */
1814 void do_folder_view(struct folder *fold, int max_folders, int num_floors) {
1815         char buf[SIZ];
1816         int levels, oldlevels;
1817         int i, t;
1818
1819         do_template("beginbox_nt");
1820         levels = 0;
1821         oldlevels = 0;
1822         for (i=0; i<max_folders; ++i) {
1823
1824                 levels = num_tokens(fold[i].name, '|');
1825                 oldlevels = levels;
1826
1827                 for (t=0; t<levels; ++t) wprintf("&nbsp;&nbsp;&nbsp;");
1828                 if (fold[i].selectable) {
1829                         wprintf("<A HREF=\"/dotgoto?room=");
1830                         urlescputs(fold[i].room);
1831                         wprintf("\">");
1832                 }
1833                 else {
1834                         wprintf("<i>");
1835                 }
1836                 if (fold[i].hasnewmsgs) wprintf("<B>");
1837                 extract(buf, fold[i].name, levels-1);
1838                 escputs(buf);
1839                 if (fold[i].hasnewmsgs) wprintf("</B>");
1840                 if (fold[i].selectable) {
1841                         wprintf("</A>");
1842                 }
1843                 else {
1844                         wprintf("</i>");
1845                 }
1846                 if (!strcasecmp(fold[i].name, "My Folders|Mail")) {
1847                         wprintf(" (INBOX)");
1848                 }
1849                 wprintf("<BR>\n");
1850         }
1851         do_template("endbox");
1852 }
1853
1854 /*
1855  * Boxes and rooms and lists ... oh my!
1856  */
1857 void do_rooms_view(struct folder *fold, int max_folders, int num_floors) {
1858         char buf[SIZ];
1859         char boxtitle[SIZ];
1860         int levels, oldlevels;
1861         int i, t;
1862         int num_boxes = 0;
1863         static int columns = 3;
1864         int boxes_per_column = 0;
1865         int current_column = 0;
1866
1867         boxes_per_column = (num_floors / columns);
1868         if (boxes_per_column < 1) boxes_per_column = 1;
1869
1870         /* Outer table (for columnization) */
1871         wprintf("<TABLE BORDER=0 WIDTH=100%% CELLPADDING=5>"
1872                 "<TR><TD VALIGN=TOP>");
1873
1874         levels = 0;
1875         oldlevels = 0;
1876         for (i=0; i<max_folders; ++i) {
1877
1878                 levels = num_tokens(fold[i].name, '|');
1879
1880                 if ((levels == 1) && (oldlevels == 2)) {
1881
1882                         /* End inner box */
1883                         do_template("endbox");
1884
1885                         ++num_boxes;
1886                         if ((num_boxes % boxes_per_column) == 0) {
1887                                 ++current_column;
1888                                 if (current_column < columns) {
1889                                         wprintf("</TD><TD VALIGN=TOP>\n");
1890                                 }
1891                         }
1892                 }
1893
1894                 if (levels == 1) {
1895
1896                         /* Begin inner box */
1897                         extract(buf, fold[i].name, levels-1);
1898                         stresc(boxtitle, buf, 1);
1899                         svprintf("BOXTITLE", WCS_STRING, boxtitle);
1900                         do_template("beginbox");
1901
1902                 }
1903
1904                 oldlevels = levels;
1905
1906                 if (levels > 1) {
1907                         wprintf("&nbsp;");
1908                         if (levels>2) for (t=0; t<(levels-2); ++t) wprintf("&nbsp;&nbsp;&nbsp;");
1909                         if (fold[i].selectable) {
1910                                 wprintf("<A HREF=\"/dotgoto?room=");
1911                                 urlescputs(fold[i].room);
1912                                 wprintf("\">");
1913                         }
1914                         else {
1915                                 wprintf("<i>");
1916                         }
1917                         if (fold[i].hasnewmsgs) wprintf("<B>");
1918                         extract(buf, fold[i].name, levels-1);
1919                         escputs(buf);
1920                         if (fold[i].hasnewmsgs) wprintf("</B>");
1921                         if (fold[i].selectable) {
1922                                 wprintf("</A>");
1923                         }
1924                         else {
1925                                 wprintf("</i>");
1926                         }
1927                         if (!strcasecmp(fold[i].name, "My Folders|Mail")) {
1928                                 wprintf(" (INBOX)");
1929                         }
1930                         wprintf("<BR>\n");
1931                 }
1932         }
1933         /* End the final inner box */
1934         do_template("endbox");
1935
1936         wprintf("</TD></TR></TABLE>\n");
1937 }
1938
1939
1940 /*
1941  * Show the room list.  (only should get called by
1942  * knrooms() because that's where output_headers() is called from)
1943  */
1944
1945 void list_all_rooms_by_floor(char *viewpref) {
1946         char buf[SIZ];
1947         int swap = 0;
1948         struct folder *fold = NULL;
1949         struct folder ftmp;
1950         int max_folders = 0;
1951         int alloc_folders = 0;
1952         int i, j;
1953         int ra_flags = 0;
1954         int flags = 0;
1955         int num_floors = 1;     /* add an extra one for private folders */
1956
1957         /* Start with the mailboxes */
1958         max_folders = 1;
1959         alloc_folders = 1;
1960         fold = malloc(sizeof(struct folder));
1961         memset(fold, 0, sizeof(struct folder));
1962         strcpy(fold[0].name, "My folders");
1963         fold[0].is_mailbox = 1;
1964
1965         /* Then add floors */
1966         serv_puts("LFLR");
1967         serv_gets(buf);
1968         if (buf[0]=='1') while(serv_gets(buf), strcmp(buf, "000")) {
1969                 if (max_folders >= alloc_folders) {
1970                         alloc_folders = max_folders + 100;
1971                         fold = realloc(fold,
1972                                 alloc_folders * sizeof(struct folder));
1973                 }
1974                 memset(&fold[max_folders], 0, sizeof(struct folder));
1975                 extract(fold[max_folders].name, buf, 1);
1976                 ++max_folders;
1977                 ++num_floors;
1978         }
1979
1980         /* Now add rooms */
1981         serv_puts("LKRA");
1982         serv_gets(buf);
1983         if (buf[0]=='1') while(serv_gets(buf), strcmp(buf, "000")) {
1984                 if (max_folders >= alloc_folders) {
1985                         alloc_folders = max_folders + 100;
1986                         fold = realloc(fold,
1987                                 alloc_folders * sizeof(struct folder));
1988                 }
1989                 memset(&fold[max_folders], 0, sizeof(struct folder));
1990                 extract(fold[max_folders].room, buf, 0);
1991                 ra_flags = extract_int(buf, 5);
1992                 flags = extract_int(buf, 1);
1993                 fold[max_folders].floor = extract_int(buf, 2);
1994                 fold[max_folders].hasnewmsgs =
1995                         ((ra_flags & UA_HASNEWMSGS) ? 1 : 0 );
1996                 if (flags & QR_MAILBOX) {
1997                         fold[max_folders].is_mailbox = 1;
1998                 }
1999                 room_to_folder(fold[max_folders].name,
2000                                 fold[max_folders].room,
2001                                 fold[max_folders].floor,
2002                                 fold[max_folders].is_mailbox);
2003                 fold[max_folders].selectable = 1;
2004                 ++max_folders;
2005         }
2006
2007         /* Bubble-sort the folder list */
2008         for (i=0; i<max_folders; ++i) {
2009                 for (j=0; j<(max_folders-1)-i; ++j) {
2010                         if (fold[j].is_mailbox == fold[j+1].is_mailbox) {
2011                                 swap = strcasecmp(fold[j].name, fold[j+1].name);
2012                         }
2013                         else {
2014                                 if ( (fold[j+1].is_mailbox)
2015                                    && (!fold[j].is_mailbox)) {
2016                                         swap = 1;
2017                                 }
2018                                 else {
2019                                         swap = 0;
2020                                 }
2021                         }
2022                         if (swap > 0) {
2023                                 memcpy(&ftmp, &fold[j], sizeof(struct folder));
2024                                 memcpy(&fold[j], &fold[j+1],
2025                                                         sizeof(struct folder));
2026                                 memcpy(&fold[j+1], &ftmp,
2027                                                         sizeof(struct folder));
2028                         }
2029                 }
2030         }
2031
2032         if (!strcasecmp(viewpref, "folders")) {
2033                 do_folder_view(fold, max_folders, num_floors);
2034         }
2035         else {
2036                 do_rooms_view(fold, max_folders, num_floors);
2037         }
2038
2039         free(fold);
2040         wDumpContent(1);
2041 }
2042
2043
2044 /* Do either a known rooms list or a folders list, depending on the
2045  * user's preference
2046  */
2047 void knrooms() {
2048         char listviewpref[SIZ];
2049
2050         output_headers(3);
2051         load_floorlist();
2052
2053         /* Determine whether the user is trying to change views */
2054         if (bstr("view") != NULL) {
2055                 if (strlen(bstr("view")) > 0) {
2056                         set_preference("roomlistview", bstr("view"));
2057                 }
2058         }
2059
2060         get_preference("roomlistview", listviewpref);
2061
2062         if ( (strcasecmp(listviewpref, "folders"))
2063            && (strcasecmp(listviewpref, "table")) ) {
2064                 strcpy(listviewpref, "rooms");
2065         }
2066
2067         /* title bar */
2068         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#000077\"><TR><TD>"
2069                 "<SPAN CLASS=\"titlebar\">"
2070         );
2071         if (!strcasecmp(listviewpref, "rooms")) {
2072                 wprintf("Room list");
2073         }
2074         if (!strcasecmp(listviewpref, "folders")) {
2075                 wprintf("Folder list");
2076         }
2077         if (!strcasecmp(listviewpref, "table")) {
2078                 wprintf("Room list");
2079         }
2080         wprintf("</SPAN></TD>\n");
2081
2082
2083         /* offer the ability to switch views */
2084         wprintf("<TD><FORM NAME=\"roomlistomatic\">\n"
2085                 "<SELECT NAME=\"newview\" SIZE=\"1\" "
2086                 "OnChange=\"location.href=roomlistomatic.newview.options"
2087                 "[selectedIndex].value\">\n");
2088
2089         wprintf("<OPTION %s VALUE=\"/knrooms&view=rooms\">"
2090                 "View as room list"
2091                 "</OPTION>\n",
2092                 ( !strcasecmp(listviewpref, "rooms") ? "SELECTED" : "" )
2093         );
2094
2095         wprintf("<OPTION %s VALUE=\"/knrooms&view=folders\">"
2096                 "View as folder list"
2097                 "</OPTION>\n",
2098                 ( !strcasecmp(listviewpref, "folders") ? "SELECTED" : "" )
2099         );
2100
2101         wprintf("<OPTION %s VALUE=\"/knrooms&view=table\">"
2102                 "Classic table view"
2103                 "</OPTION>\n",
2104                 ( !strcasecmp(listviewpref, "table") ? "SELECTED" : "" )
2105         );
2106
2107         wprintf("</SELECT></FORM></TD><TD>\n");
2108         offer_start_page();
2109         wprintf("</TD></TR></TABLE><BR>\n");
2110
2111         /* Display the room list in the user's preferred format */
2112         if (!strcasecmp(listviewpref, "table")) {
2113                 tabular_room_list();
2114         }
2115         else {
2116                 list_all_rooms_by_floor(listviewpref);
2117         }
2118 }