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