e3886724ddbc501957b66fc0c85ef68a80e3bbc9
[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("</TR></TABLE>\n");
822         /* end tabbed dialog */ 
823
824         /* begin content of whatever tab is open now */
825         wprintf("<TABLE border=0 width=100%% bgcolor=\"#FFFFFF\">\n"
826                 "<TR><TD>\n");
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         /* end content of whatever tab is open now */
1143         wprintf("</TD></TR></TABLE>\n");
1144
1145         wDumpContent(1);
1146 }
1147
1148
1149 /* 
1150  * Toggle self-service list subscription
1151  */
1152 void toggle_self_service(void) {
1153         int newval = 0;
1154
1155         newval = atoi(bstr("newval"));
1156         self_service(newval);
1157         display_editroom();
1158 }
1159
1160
1161
1162 /*
1163  * save new parameters for a room
1164  */
1165 void editroom(void)
1166 {
1167         char buf[SIZ];
1168         char er_name[20];
1169         char er_password[10];
1170         char er_dirname[15];
1171         char er_roomaide[26];
1172         int er_floor;
1173         unsigned er_flags;
1174         int bump;
1175
1176
1177         if (strcmp(bstr("sc"), "OK")) {
1178                 display_error("Cancelled.  Changes were not saved.");
1179                 return;
1180         }
1181         serv_puts("GETR");
1182         serv_gets(buf);
1183
1184         if (buf[0] != '2') {
1185                 display_error(&buf[4]);
1186                 return;
1187         }
1188         extract(er_name, &buf[4], 0);
1189         extract(er_password, &buf[4], 1);
1190         extract(er_dirname, &buf[4], 2);
1191         er_flags = extract_int(&buf[4], 3);
1192
1193         strcpy(er_roomaide, bstr("er_roomaide"));
1194         if (strlen(er_roomaide) == 0) {
1195                 serv_puts("GETA");
1196                 serv_gets(buf);
1197                 if (buf[0] != '2') {
1198                         strcpy(er_roomaide, "");
1199                 } else {
1200                         extract(er_roomaide, &buf[4], 0);
1201                 }
1202         }
1203         strcpy(buf, bstr("er_name"));
1204         buf[20] = 0;
1205         if (strlen(buf) > 0)
1206                 strcpy(er_name, buf);
1207
1208         strcpy(buf, bstr("er_password"));
1209         buf[10] = 0;
1210         if (strlen(buf) > 0)
1211                 strcpy(er_password, buf);
1212
1213         strcpy(buf, bstr("er_dirname"));
1214         buf[15] = 0;
1215         if (strlen(buf) > 0)
1216                 strcpy(er_dirname, buf);
1217
1218         strcpy(buf, bstr("type"));
1219         er_flags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
1220
1221         if (!strcmp(buf, "invonly")) {
1222                 er_flags |= (QR_PRIVATE);
1223         }
1224         if (!strcmp(buf, "guessname")) {
1225                 er_flags |= (QR_PRIVATE | QR_GUESSNAME);
1226         }
1227         if (!strcmp(buf, "passworded")) {
1228                 er_flags |= (QR_PRIVATE | QR_PASSWORDED);
1229         }
1230         if (!strcmp(bstr("prefonly"), "yes")) {
1231                 er_flags |= QR_PREFONLY;
1232         } else {
1233                 er_flags &= ~QR_PREFONLY;
1234         }
1235
1236         if (!strcmp(bstr("readonly"), "yes")) {
1237                 er_flags |= QR_READONLY;
1238         } else {
1239                 er_flags &= ~QR_READONLY;
1240         }
1241
1242         if (!strcmp(bstr("network"), "yes")) {
1243                 er_flags |= QR_NETWORK;
1244         } else {
1245                 er_flags &= ~QR_NETWORK;
1246         }
1247
1248         if (!strcmp(bstr("directory"), "yes")) {
1249                 er_flags |= QR_DIRECTORY;
1250         } else {
1251                 er_flags &= ~QR_DIRECTORY;
1252         }
1253
1254         if (!strcmp(bstr("ulallowed"), "yes")) {
1255                 er_flags |= QR_UPLOAD;
1256         } else {
1257                 er_flags &= ~QR_UPLOAD;
1258         }
1259
1260         if (!strcmp(bstr("dlallowed"), "yes")) {
1261                 er_flags |= QR_DOWNLOAD;
1262         } else {
1263                 er_flags &= ~QR_DOWNLOAD;
1264         }
1265
1266         if (!strcmp(bstr("visdir"), "yes")) {
1267                 er_flags |= QR_VISDIR;
1268         } else {
1269                 er_flags &= ~QR_VISDIR;
1270         }
1271
1272         strcpy(buf, bstr("anon"));
1273
1274         er_flags &= ~(QR_ANONONLY | QR_ANONOPT);
1275         if (!strcmp(buf, "anononly"))
1276                 er_flags |= QR_ANONONLY;
1277         if (!strcmp(buf, "anon2"))
1278                 er_flags |= QR_ANONOPT;
1279
1280         bump = 0;
1281         if (!strcmp(bstr("bump"), "yes"))
1282                 bump = 1;
1283
1284         er_floor = atoi(bstr("er_floor"));
1285
1286         sprintf(buf, "SETR %s|%s|%s|%u|%d|%d",
1287              er_name, er_password, er_dirname, er_flags, bump, er_floor);
1288         serv_puts(buf);
1289         serv_gets(buf);
1290         if (buf[0] != '2') {
1291                 display_error(&buf[4]);
1292                 return;
1293         }
1294         gotoroom(er_name, 0);
1295
1296         if (strlen(er_roomaide) > 0) {
1297                 sprintf(buf, "SETA %s", er_roomaide);
1298                 serv_puts(buf);
1299                 serv_gets(buf);
1300                 if (buf[0] != '2') {
1301                         display_error(&buf[4]);
1302                         return;
1303                 }
1304         }
1305         smart_goto(er_name);
1306 }
1307
1308 /*
1309  * Invite, Kick, and show Who Knows a room
1310  */
1311 void display_whok(void)
1312 {
1313         char buf[SIZ], room[SIZ], username[SIZ];
1314
1315         serv_puts("GETR");
1316         serv_gets(buf);
1317
1318         if (buf[0] != '2') {
1319                 display_error(&buf[4]);
1320                 return;
1321         }
1322         extract(room, &buf[4], 0);
1323
1324         strcpy(username, bstr("username"));
1325
1326         output_headers(1);
1327
1328         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#007700\"><TR><TD>");
1329         wprintf("<SPAN CLASS=\"titlebar\">Access control list for ");
1330         escputs(WC->wc_roomname);
1331         wprintf("</SPAN></TD></TR></TABLE>\n");
1332
1333         if(!strcmp(bstr("sc"), "Kick")) {
1334                 sprintf(buf, "KICK %s", username);
1335                 serv_puts(buf);
1336                 serv_gets(buf);
1337
1338                 if (buf[0] != '2') {
1339                         display_error(&buf[4]);
1340                         return;
1341                 } else {
1342                         wprintf("<B><I>User %s kicked out of room %s.</I></B>\n", 
1343                                 username, room);
1344                 }
1345         } else if(!strcmp(bstr("sc"), "Invite")) {
1346                 sprintf(buf, "INVT %s", username);
1347                 serv_puts(buf);
1348                 serv_gets(buf);
1349
1350                 if (buf[0] != '2') {
1351                         display_error(&buf[4]);
1352                         return;
1353                 } else {
1354                         wprintf("<B><I>User %s invited to room %s.</I></B>\n", 
1355                                 username, room);
1356                 }
1357         }
1358         
1359
1360
1361         wprintf("<TABLE border=0 CELLSPACING=10><TR VALIGN=TOP>"
1362                 "<TD>The users listed below have access to this room.  "
1363                 "To remove a user from the access list, select the user "
1364                 "name from the list and click 'Kick'.<BR><BR>");
1365         
1366         wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/display_whok\">\n");
1367         wprintf("<SELECT NAME=\"username\" SIZE=10>\n");
1368         serv_puts("WHOK");
1369         serv_gets(buf);
1370         if (buf[0] == '1') {
1371                 while (serv_gets(buf), strcmp(buf, "000")) {
1372                         extract(username, buf, 0);
1373                         wprintf("<OPTION>");
1374                         escputs(username);
1375                         wprintf("\n");
1376                 }
1377         }
1378         wprintf("</SELECT><BR>\n");
1379
1380         wprintf("<input type=submit name=sc value=\"Kick\">");
1381         wprintf("</FORM></CENTER>\n");
1382
1383         wprintf("</TD><TD>"
1384                 "To grant another user access to this room, enter the "
1385                 "user name in the box below and click 'Invite'.<BR><BR>");
1386
1387         wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/display_whok\">\n");
1388         wprintf("Invite: ");
1389         wprintf("<input type=text name=username><BR>\n"
1390                 "<input type=hidden name=sc value=\"Invite\">"
1391                 "<input type=submit value=\"Invite\">"
1392                 "</FORM></CENTER>\n");
1393
1394         wprintf("</TD></TR></TABLE>\n");
1395         wDumpContent(1);
1396 }
1397
1398
1399
1400 /*
1401  * display the form for entering a new room
1402  */
1403 void display_entroom(void)
1404 {
1405         int i;
1406         char buf[SIZ];
1407
1408         serv_puts("CRE8 0");
1409         serv_gets(buf);
1410
1411         if (buf[0] != '2') {
1412                 display_error(&buf[4]);
1413                 return;
1414         }
1415         output_headers(1);
1416
1417         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#000077\"><TR><TD>");
1418         wprintf("<SPAN CLASS=\"titlebar\">Enter (create) a new room</SPAN>\n");
1419         wprintf("</TD></TR></TABLE>\n");
1420
1421         wprintf("<FORM METHOD=\"POST\" ACTION=\"/entroom\">\n");
1422
1423         wprintf("<UL><LI>Name of room: ");
1424         wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" MAXLENGTH=\"19\">\n");
1425
1426         wprintf("<LI>Type of room:<UL>\n");
1427
1428         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
1429         wprintf("CHECKED > Public room\n");
1430
1431         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
1432         wprintf("> Private - guess name\n");
1433
1434         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
1435         wprintf("> Private - require password:\n");
1436         wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" MAXLENGTH=\"9\">\n");
1437
1438         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
1439         wprintf("> Private - invitation only\n");
1440         wprintf("</UL>\n");
1441
1442         wprintf("<LI>Resides on floor: ");
1443         load_floorlist(); 
1444         wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
1445         for (i = 0; i < 128; ++i)
1446                 if (strlen(floorlist[i]) > 0) {
1447                         wprintf("<OPTION ");
1448                         wprintf("VALUE=\"%d\">", i);
1449                         escputs(floorlist[i]);
1450                         wprintf("</OPTION>\n");
1451                 }
1452         wprintf("</SELECT>\n");                
1453         wprintf("</UL>\n");
1454
1455
1456         wprintf("<CENTER>\n");
1457         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1458         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1459         wprintf("</CENTER>\n");
1460         wprintf("</FORM>\n<HR>");
1461         serv_printf("MESG roomaccess");
1462         serv_gets(buf);
1463         if (buf[0] == '1') {
1464                 fmout(NULL);
1465         }
1466         wDumpContent(1);
1467 }
1468
1469
1470
1471 /*
1472  * enter a new room
1473  */
1474 void entroom(void)
1475 {
1476         char buf[SIZ];
1477         char er_name[20];
1478         char er_type[20];
1479         char er_password[10];
1480         int er_floor;
1481         int er_num_type;
1482
1483         if (strcmp(bstr("sc"), "OK")) {
1484                 display_error("Cancelled.  No new room was created.");
1485                 return;
1486         }
1487         strcpy(er_name, bstr("er_name"));
1488         strcpy(er_type, bstr("type"));
1489         strcpy(er_password, bstr("er_password"));
1490         er_floor = atoi(bstr("er_floor"));
1491
1492         er_num_type = 0;
1493         if (!strcmp(er_type, "guessname"))
1494                 er_num_type = 1;
1495         if (!strcmp(er_type, "passworded"))
1496                 er_num_type = 2;
1497         if (!strcmp(er_type, "invonly"))
1498                 er_num_type = 3;
1499
1500         sprintf(buf, "CRE8 1|%s|%d|%s|%d", 
1501                 er_name, er_num_type, er_password, er_floor);
1502         serv_puts(buf);
1503         serv_gets(buf);
1504         if (buf[0] != '2') {
1505                 display_error(&buf[4]);
1506                 return;
1507         }
1508         smart_goto(er_name);
1509 }
1510
1511
1512 /*
1513  * display the screen to enter a private room
1514  */
1515 void display_private(char *rname, int req_pass)
1516 {
1517
1518         output_headers(1);
1519
1520         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
1521         wprintf("<SPAN CLASS=\"titlebar\">Goto a private room</SPAN>\n");
1522         wprintf("</TD></TR></TABLE>\n");
1523
1524         wprintf("<CENTER>\n");
1525         wprintf("If you know the name of a hidden (guess-name) or\n");
1526         wprintf("passworded room, you can enter that room by typing\n");
1527         wprintf("its name below.  Once you gain access to a private\n");
1528         wprintf("room, it will appear in your regular room listings\n");
1529         wprintf("so you don't have to keep returning here.\n");
1530         wprintf("<BR><BR>");
1531
1532         wprintf("<FORM METHOD=\"GET\" ACTION=\"/goto_private\">\n");
1533
1534         wprintf("<TABLE border><TR><TD>");
1535         wprintf("Enter room name:</TD><TD>");
1536         wprintf("<INPUT TYPE=\"text\" NAME=\"gr_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", rname);
1537
1538         if (req_pass) {
1539                 wprintf("</TD></TR><TR><TD>");
1540                 wprintf("Enter room password:</TD><TD>");
1541                 wprintf("<INPUT TYPE=\"password\" NAME=\"gr_pass\" MAXLENGTH=\"9\">\n");
1542         }
1543         wprintf("</TD></TR></TABLE>\n");
1544
1545         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1546         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1547         wprintf("</FORM>\n");
1548         wDumpContent(1);
1549 }
1550
1551 /* 
1552  * goto a private room
1553  */
1554 void goto_private(void)
1555 {
1556         char hold_rm[SIZ];
1557         char buf[SIZ];
1558
1559         if (strcasecmp(bstr("sc"), "OK")) {
1560                 display_main_menu();
1561                 return;
1562         }
1563         strcpy(hold_rm, WC->wc_roomname);
1564         strcpy(buf, "GOTO ");
1565         strcat(buf, bstr("gr_name"));
1566         strcat(buf, "|");
1567         strcat(buf, bstr("gr_pass"));
1568         serv_puts(buf);
1569         serv_gets(buf);
1570
1571         if (buf[0] == '2') {
1572                 smart_goto(bstr("gr_name"));
1573                 return;
1574         }
1575         if (!strncmp(buf, "540", 3)) {
1576                 display_private(bstr("gr_name"), 1);
1577                 return;
1578         }
1579         output_headers(1);
1580         wprintf("%s\n", &buf[4]);
1581         wDumpContent(1);
1582         return;
1583 }
1584
1585
1586 /*
1587  * display the screen to zap a room
1588  */
1589 void display_zap(void)
1590 {
1591         output_headers(1);
1592
1593         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
1594         wprintf("<SPAN CLASS=\"titlebar\">Zap (forget) the current room</SPAN>\n");
1595         wprintf("</TD></TR></TABLE>\n");
1596
1597         wprintf("If you select this option, <em>%s</em> will ", WC->wc_roomname);
1598         wprintf("disappear from your room list.  Is this what you wish ");
1599         wprintf("to do?<BR>\n");
1600
1601         wprintf("<FORM METHOD=\"GET\" ACTION=\"/zap\">\n");
1602         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1603         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1604         wprintf("</FORM>\n");
1605         wDumpContent(1);
1606 }
1607
1608
1609 /* 
1610  * zap a room
1611  */
1612 void zap(void)
1613 {
1614         char buf[SIZ];
1615         char final_destination[SIZ];
1616
1617         /* If the forget-room routine fails for any reason, we fall back
1618          * to the current room; otherwise, we go to the Lobby
1619          */
1620         strcpy(final_destination, WC->wc_roomname);
1621
1622         if (!strcasecmp(bstr("sc"), "OK")) {
1623                 serv_printf("GOTO %s", WC->wc_roomname);
1624                 serv_gets(buf);
1625                 if (buf[0] != '2') {
1626                         /* ExpressMessageCat(&buf[4]); */
1627                 } else {
1628                         serv_puts("FORG");
1629                         serv_gets(buf);
1630                         if (buf[0] != '2') {
1631                                 /* ExpressMessageCat(&buf[4]); */
1632                         } else {
1633                                 strcpy(final_destination, "_BASEROOM_");
1634                         }
1635                 }
1636         }
1637         smart_goto(final_destination);
1638 }
1639
1640
1641
1642
1643 /*
1644  * Confirm deletion of the current room
1645  */
1646 void confirm_delete_room(void)
1647 {
1648         char buf[SIZ];
1649
1650         serv_puts("KILL 0");
1651         serv_gets(buf);
1652         if (buf[0] != '2') {
1653                 display_error(&buf[4]);
1654                 return;
1655         }
1656         output_headers(1);
1657         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
1658         wprintf("<SPAN CLASS=\"titlebar\">Confirm deletion of room</SPAN>\n");
1659         wprintf("</TD></TR></TABLE>\n");
1660
1661         wprintf("<CENTER>");
1662         wprintf("<FORM METHOD=\"GET\" ACTION=\"/delete_room\">\n");
1663
1664         wprintf("Are you sure you want to delete <FONT SIZE=+1>");
1665         escputs(WC->wc_roomname);
1666         wprintf("</FONT>?<BR>\n");
1667
1668         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">");
1669         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1670
1671         wprintf("</FORM></CENTER>\n");
1672         wDumpContent(1);
1673 }
1674
1675
1676 /*
1677  * Delete the current room
1678  */
1679 void delete_room(void)
1680 {
1681         char buf[SIZ];
1682         char sc[SIZ];
1683
1684         strcpy(sc, bstr("sc"));
1685
1686         if (strcasecmp(sc, "Delete")) {
1687                 display_error("Cancelled.  This room was not deleted.");
1688                 return;
1689         }
1690         serv_puts("KILL 1");
1691         serv_gets(buf);
1692         if (buf[0] != '2') {
1693                 display_error(&buf[4]);
1694         } else {
1695                 smart_goto("_BASEROOM_");
1696         }
1697 }
1698
1699
1700
1701 /*
1702  * Perform changes to a room's network configuration
1703  */
1704 void netedit(void) {
1705         FILE *fp;
1706         char buf[SIZ];
1707         char line[SIZ];
1708
1709         if (strlen(bstr("line"))==0) {
1710                 display_editroom();
1711                 return;
1712         }
1713
1714         strcpy(line, bstr("prefix"));
1715         strcat(line, bstr("line"));
1716         strcat(line, bstr("suffix"));
1717
1718         fp = tmpfile();
1719         if (fp == NULL) {
1720                 display_editroom();
1721                 return;
1722         }
1723
1724         serv_puts("GNET");
1725         serv_gets(buf);
1726         if (buf[0] != '1') {
1727                 fclose(fp);
1728                 display_editroom();
1729                 return;
1730         }
1731
1732         /* This loop works for add *or* remove.  Spiffy, eh? */
1733         while (serv_gets(buf), strcmp(buf, "000")) {
1734                 if (strcasecmp(buf, line)) {
1735                         fprintf(fp, "%s\n", buf);
1736                 }
1737         }
1738
1739         rewind(fp);
1740         serv_puts("SNET");
1741         serv_gets(buf);
1742         if (buf[0] != '4') {
1743                 fclose(fp);
1744                 display_editroom();
1745                 return;
1746         }
1747
1748         while (fgets(buf, sizeof buf, fp) != NULL) {
1749                 buf[strlen(buf)-1] = 0;
1750                 serv_puts(buf);
1751         }
1752
1753         if (!strcasecmp(bstr("cmd"), "add")) {
1754                 serv_puts(line);
1755         }
1756
1757         serv_puts("000");
1758         fclose(fp);
1759         display_editroom();
1760 }
1761
1762
1763
1764 /*
1765  * Convert a room name to a folder-ish-looking name.
1766  */
1767 void room_to_folder(char *folder, char *room, int floor, int is_mailbox)
1768 {
1769         int i;
1770
1771         /*
1772          * For mailboxes, just do it straight...
1773          */
1774         if (is_mailbox) {
1775                 sprintf(folder, "My folders|%s", room);
1776         }
1777
1778         /*
1779          * Otherwise, prefix the floor name as a "public folders" moniker
1780          */
1781         else {
1782                 sprintf(folder, "%s|%s", floorlist[floor], room);
1783         }
1784
1785         /*
1786          * Replace "\" characters with "|" for pseudo-folder-delimiting
1787          */
1788         for (i=0; i<strlen(folder); ++i) {
1789                 if (folder[i] == '\\') folder[i] = '|';
1790         }
1791 }
1792
1793
1794
1795
1796
1797
1798
1799 /*
1800  * Change the view for this room
1801  */
1802 void change_view(void) {
1803         int view;
1804         char buf[SIZ];
1805
1806         view = atol(bstr("view"));
1807
1808         serv_printf("VIEW %d", view);
1809         serv_gets(buf);
1810         smart_goto(WC->wc_roomname);
1811 }
1812
1813
1814 /*
1815  * One big expanded tree list view --- like a folder list
1816  */
1817 void do_folder_view(struct folder *fold, int max_folders, int num_floors) {
1818         char buf[SIZ];
1819         int levels, oldlevels;
1820         int i, t;
1821
1822         do_template("beginbox_nt");
1823         levels = 0;
1824         oldlevels = 0;
1825         for (i=0; i<max_folders; ++i) {
1826
1827                 levels = num_tokens(fold[i].name, '|');
1828                 oldlevels = levels;
1829
1830                 for (t=0; t<levels; ++t) wprintf("&nbsp;&nbsp;&nbsp;");
1831                 if (fold[i].selectable) {
1832                         wprintf("<A HREF=\"/dotgoto?room=");
1833                         urlescputs(fold[i].room);
1834                         wprintf("\">");
1835                 }
1836                 else {
1837                         wprintf("<i>");
1838                 }
1839                 if (fold[i].hasnewmsgs) wprintf("<B>");
1840                 extract(buf, fold[i].name, levels-1);
1841                 escputs(buf);
1842                 if (fold[i].hasnewmsgs) wprintf("</B>");
1843                 if (fold[i].selectable) {
1844                         wprintf("</A>");
1845                 }
1846                 else {
1847                         wprintf("</i>");
1848                 }
1849                 if (!strcasecmp(fold[i].name, "My Folders|Mail")) {
1850                         wprintf(" (INBOX)");
1851                 }
1852                 wprintf("<BR>\n");
1853         }
1854         do_template("endbox");
1855 }
1856
1857 /*
1858  * Boxes and rooms and lists ... oh my!
1859  */
1860 void do_rooms_view(struct folder *fold, int max_folders, int num_floors) {
1861         char buf[SIZ];
1862         char boxtitle[SIZ];
1863         int levels, oldlevels;
1864         int i, t;
1865         int num_boxes = 0;
1866         static int columns = 3;
1867         int boxes_per_column = 0;
1868         int current_column = 0;
1869
1870         boxes_per_column = (num_floors / columns);
1871         if (boxes_per_column < 1) boxes_per_column = 1;
1872
1873         /* Outer table (for columnization) */
1874         wprintf("<TABLE BORDER=0 WIDTH=100%% CELLPADDING=5>"
1875                 "<TR><TD VALIGN=TOP>");
1876
1877         levels = 0;
1878         oldlevels = 0;
1879         for (i=0; i<max_folders; ++i) {
1880
1881                 levels = num_tokens(fold[i].name, '|');
1882
1883                 if ((levels == 1) && (oldlevels == 2)) {
1884
1885                         /* End inner box */
1886                         do_template("endbox");
1887
1888                         ++num_boxes;
1889                         if ((num_boxes % boxes_per_column) == 0) {
1890                                 ++current_column;
1891                                 if (current_column < columns) {
1892                                         wprintf("</TD><TD VALIGN=TOP>\n");
1893                                 }
1894                         }
1895                 }
1896
1897                 if (levels == 1) {
1898
1899                         /* Begin inner box */
1900                         extract(buf, fold[i].name, levels-1);
1901                         stresc(boxtitle, buf, 1);
1902                         svprintf("BOXTITLE", WCS_STRING, boxtitle);
1903                         do_template("beginbox");
1904
1905                 }
1906
1907                 oldlevels = levels;
1908
1909                 if (levels > 1) {
1910                         wprintf("&nbsp;");
1911                         if (levels>2) for (t=0; t<(levels-2); ++t) wprintf("&nbsp;&nbsp;&nbsp;");
1912                         if (fold[i].selectable) {
1913                                 wprintf("<A HREF=\"/dotgoto?room=");
1914                                 urlescputs(fold[i].room);
1915                                 wprintf("\">");
1916                         }
1917                         else {
1918                                 wprintf("<i>");
1919                         }
1920                         if (fold[i].hasnewmsgs) wprintf("<B>");
1921                         extract(buf, fold[i].name, levels-1);
1922                         escputs(buf);
1923                         if (fold[i].hasnewmsgs) wprintf("</B>");
1924                         if (fold[i].selectable) {
1925                                 wprintf("</A>");
1926                         }
1927                         else {
1928                                 wprintf("</i>");
1929                         }
1930                         if (!strcasecmp(fold[i].name, "My Folders|Mail")) {
1931                                 wprintf(" (INBOX)");
1932                         }
1933                         wprintf("<BR>\n");
1934                 }
1935         }
1936         /* End the final inner box */
1937         do_template("endbox");
1938
1939         wprintf("</TD></TR></TABLE>\n");
1940 }
1941
1942
1943 /*
1944  * Show the room list.  (only should get called by
1945  * knrooms() because that's where output_headers() is called from)
1946  */
1947
1948 void list_all_rooms_by_floor(char *viewpref) {
1949         char buf[SIZ];
1950         int swap = 0;
1951         struct folder *fold = NULL;
1952         struct folder ftmp;
1953         int max_folders = 0;
1954         int alloc_folders = 0;
1955         int i, j;
1956         int ra_flags = 0;
1957         int flags = 0;
1958         int num_floors = 1;     /* add an extra one for private folders */
1959
1960         /* Start with the mailboxes */
1961         max_folders = 1;
1962         alloc_folders = 1;
1963         fold = malloc(sizeof(struct folder));
1964         memset(fold, 0, sizeof(struct folder));
1965         strcpy(fold[0].name, "My folders");
1966         fold[0].is_mailbox = 1;
1967
1968         /* Then add floors */
1969         serv_puts("LFLR");
1970         serv_gets(buf);
1971         if (buf[0]=='1') while(serv_gets(buf), strcmp(buf, "000")) {
1972                 if (max_folders >= alloc_folders) {
1973                         alloc_folders = max_folders + 100;
1974                         fold = realloc(fold,
1975                                 alloc_folders * sizeof(struct folder));
1976                 }
1977                 memset(&fold[max_folders], 0, sizeof(struct folder));
1978                 extract(fold[max_folders].name, buf, 1);
1979                 ++max_folders;
1980                 ++num_floors;
1981         }
1982
1983         /* Now add rooms */
1984         serv_puts("LKRA");
1985         serv_gets(buf);
1986         if (buf[0]=='1') while(serv_gets(buf), strcmp(buf, "000")) {
1987                 if (max_folders >= alloc_folders) {
1988                         alloc_folders = max_folders + 100;
1989                         fold = realloc(fold,
1990                                 alloc_folders * sizeof(struct folder));
1991                 }
1992                 memset(&fold[max_folders], 0, sizeof(struct folder));
1993                 extract(fold[max_folders].room, buf, 0);
1994                 ra_flags = extract_int(buf, 5);
1995                 flags = extract_int(buf, 1);
1996                 fold[max_folders].floor = extract_int(buf, 2);
1997                 fold[max_folders].hasnewmsgs =
1998                         ((ra_flags & UA_HASNEWMSGS) ? 1 : 0 );
1999                 if (flags & QR_MAILBOX) {
2000                         fold[max_folders].is_mailbox = 1;
2001                 }
2002                 room_to_folder(fold[max_folders].name,
2003                                 fold[max_folders].room,
2004                                 fold[max_folders].floor,
2005                                 fold[max_folders].is_mailbox);
2006                 fold[max_folders].selectable = 1;
2007                 ++max_folders;
2008         }
2009
2010         /* Bubble-sort the folder list */
2011         for (i=0; i<max_folders; ++i) {
2012                 for (j=0; j<(max_folders-1)-i; ++j) {
2013                         if (fold[j].is_mailbox == fold[j+1].is_mailbox) {
2014                                 swap = strcasecmp(fold[j].name, fold[j+1].name);
2015                         }
2016                         else {
2017                                 if ( (fold[j+1].is_mailbox)
2018                                    && (!fold[j].is_mailbox)) {
2019                                         swap = 1;
2020                                 }
2021                                 else {
2022                                         swap = 0;
2023                                 }
2024                         }
2025                         if (swap > 0) {
2026                                 memcpy(&ftmp, &fold[j], sizeof(struct folder));
2027                                 memcpy(&fold[j], &fold[j+1],
2028                                                         sizeof(struct folder));
2029                                 memcpy(&fold[j+1], &ftmp,
2030                                                         sizeof(struct folder));
2031                         }
2032                 }
2033         }
2034
2035         if (!strcasecmp(viewpref, "folders")) {
2036                 do_folder_view(fold, max_folders, num_floors);
2037         }
2038         else {
2039                 do_rooms_view(fold, max_folders, num_floors);
2040         }
2041
2042         free(fold);
2043         wDumpContent(1);
2044 }
2045
2046
2047 /* Do either a known rooms list or a folders list, depending on the
2048  * user's preference
2049  */
2050 void knrooms() {
2051         char listviewpref[SIZ];
2052
2053         output_headers(3);
2054         load_floorlist();
2055
2056         /* Determine whether the user is trying to change views */
2057         if (bstr("view") != NULL) {
2058                 if (strlen(bstr("view")) > 0) {
2059                         set_preference("roomlistview", bstr("view"));
2060                 }
2061         }
2062
2063         get_preference("roomlistview", listviewpref);
2064
2065         if ( (strcasecmp(listviewpref, "folders"))
2066            && (strcasecmp(listviewpref, "table")) ) {
2067                 strcpy(listviewpref, "rooms");
2068         }
2069
2070         /* title bar */
2071         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#000077\"><TR><TD>"
2072                 "<SPAN CLASS=\"titlebar\">"
2073         );
2074         if (!strcasecmp(listviewpref, "rooms")) {
2075                 wprintf("Room list");
2076         }
2077         if (!strcasecmp(listviewpref, "folders")) {
2078                 wprintf("Folder list");
2079         }
2080         if (!strcasecmp(listviewpref, "table")) {
2081                 wprintf("Room list");
2082         }
2083         wprintf("</SPAN></TD>\n");
2084
2085
2086         /* offer the ability to switch views */
2087         wprintf("<TD><FORM NAME=\"roomlistomatic\">\n"
2088                 "<SELECT NAME=\"newview\" SIZE=\"1\" "
2089                 "OnChange=\"location.href=roomlistomatic.newview.options"
2090                 "[selectedIndex].value\">\n");
2091
2092         wprintf("<OPTION %s VALUE=\"/knrooms&view=rooms\">"
2093                 "View as room list"
2094                 "</OPTION>\n",
2095                 ( !strcasecmp(listviewpref, "rooms") ? "SELECTED" : "" )
2096         );
2097
2098         wprintf("<OPTION %s VALUE=\"/knrooms&view=folders\">"
2099                 "View as folder list"
2100                 "</OPTION>\n",
2101                 ( !strcasecmp(listviewpref, "folders") ? "SELECTED" : "" )
2102         );
2103
2104         wprintf("<OPTION %s VALUE=\"/knrooms&view=table\">"
2105                 "Classic table view"
2106                 "</OPTION>\n",
2107                 ( !strcasecmp(listviewpref, "table") ? "SELECTED" : "" )
2108         );
2109
2110         wprintf("</SELECT></FORM></TD><TD>\n");
2111         offer_start_page();
2112         wprintf("</TD></TR></TABLE><BR>\n");
2113
2114         /* Display the room list in the user's preferred format */
2115         if (!strcasecmp(listviewpref, "table")) {
2116                 tabular_room_list();
2117         }
2118         else {
2119                 list_all_rooms_by_floor(listviewpref);
2120         }
2121 }