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