aaac83ae69380bfc01df194204ba459bf38a7b55
[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 HEIGHT=64 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>"
760                 "<TD>&nbsp;</TD>\n");
761
762         if (!strcmp(tab, "admin")) {
763                 wprintf("<TD BGCOLOR=\"#FFFFFF\"><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=\"#FFFFFF\"><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=\"#FFFFFF\"><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=\"#FFFFFF\"><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("<BR>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=\"0\" cellspacing=\"5\" "
1540                 "cellpadding=\"5\" BGCOLOR=\"#EEEEEE\">\n"
1541                 "<TR><TD>"
1542                 "Enter room name:</TD><TD>"
1543                 "<INPUT TYPE=\"text\" NAME=\"gr_name\" "
1544                 "VALUE=\"%s\" MAXLENGTH=\"19\">\n", rname);
1545
1546         if (req_pass) {
1547                 wprintf("</TD></TR><TR><TD>");
1548                 wprintf("Enter room password:</TD><TD>");
1549                 wprintf("<INPUT TYPE=\"password\" NAME=\"gr_pass\" MAXLENGTH=\"9\">\n");
1550         }
1551         wprintf("</TD></TR></TABLE><BR>\n");
1552
1553         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">"
1554                 "&nbsp;"
1555                 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1556         wprintf("</FORM>\n");
1557         do_template("endbox");
1558         wDumpContent(1);
1559 }
1560
1561 /* 
1562  * goto a private room
1563  */
1564 void goto_private(void)
1565 {
1566         char hold_rm[SIZ];
1567         char buf[SIZ];
1568
1569         if (strcasecmp(bstr("sc"), "OK")) {
1570                 display_main_menu();
1571                 return;
1572         }
1573         strcpy(hold_rm, WC->wc_roomname);
1574         strcpy(buf, "GOTO ");
1575         strcat(buf, bstr("gr_name"));
1576         strcat(buf, "|");
1577         strcat(buf, bstr("gr_pass"));
1578         serv_puts(buf);
1579         serv_gets(buf);
1580
1581         if (buf[0] == '2') {
1582                 smart_goto(bstr("gr_name"));
1583                 return;
1584         }
1585         if (!strncmp(buf, "540", 3)) {
1586                 display_private(bstr("gr_name"), 1);
1587                 return;
1588         }
1589         output_headers(1);
1590         wprintf("%s\n", &buf[4]);
1591         wDumpContent(1);
1592         return;
1593 }
1594
1595
1596 /*
1597  * display the screen to zap a room
1598  */
1599 void display_zap(void)
1600 {
1601         output_headers(1);
1602
1603         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
1604         wprintf("<SPAN CLASS=\"titlebar\">Zap (forget) the current room</SPAN>\n");
1605         wprintf("</TD></TR></TABLE>\n");
1606
1607         wprintf("If you select this option, <em>%s</em> will ", WC->wc_roomname);
1608         wprintf("disappear from your room list.  Is this what you wish ");
1609         wprintf("to do?<BR>\n");
1610
1611         wprintf("<FORM METHOD=\"GET\" ACTION=\"/zap\">\n");
1612         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1613         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1614         wprintf("</FORM>\n");
1615         wDumpContent(1);
1616 }
1617
1618
1619 /* 
1620  * zap a room
1621  */
1622 void zap(void)
1623 {
1624         char buf[SIZ];
1625         char final_destination[SIZ];
1626
1627         /* If the forget-room routine fails for any reason, we fall back
1628          * to the current room; otherwise, we go to the Lobby
1629          */
1630         strcpy(final_destination, WC->wc_roomname);
1631
1632         if (!strcasecmp(bstr("sc"), "OK")) {
1633                 serv_printf("GOTO %s", WC->wc_roomname);
1634                 serv_gets(buf);
1635                 if (buf[0] != '2') {
1636                         /* ExpressMessageCat(&buf[4]); */
1637                 } else {
1638                         serv_puts("FORG");
1639                         serv_gets(buf);
1640                         if (buf[0] != '2') {
1641                                 /* ExpressMessageCat(&buf[4]); */
1642                         } else {
1643                                 strcpy(final_destination, "_BASEROOM_");
1644                         }
1645                 }
1646         }
1647         smart_goto(final_destination);
1648 }
1649
1650
1651
1652
1653 /*
1654  * Confirm deletion of the current room
1655  */
1656 void confirm_delete_room(void)
1657 {
1658         char buf[SIZ];
1659
1660         serv_puts("KILL 0");
1661         serv_gets(buf);
1662         if (buf[0] != '2') {
1663                 display_error(&buf[4]);
1664                 return;
1665         }
1666         output_headers(1);
1667         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
1668         wprintf("<SPAN CLASS=\"titlebar\">Confirm deletion of room</SPAN>\n");
1669         wprintf("</TD></TR></TABLE>\n");
1670
1671         wprintf("<CENTER>");
1672         wprintf("<FORM METHOD=\"GET\" ACTION=\"/delete_room\">\n");
1673
1674         wprintf("Are you sure you want to delete <FONT SIZE=+1>");
1675         escputs(WC->wc_roomname);
1676         wprintf("</FONT>?<BR>\n");
1677
1678         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">");
1679         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1680
1681         wprintf("</FORM></CENTER>\n");
1682         wDumpContent(1);
1683 }
1684
1685
1686 /*
1687  * Delete the current room
1688  */
1689 void delete_room(void)
1690 {
1691         char buf[SIZ];
1692         char sc[SIZ];
1693
1694         strcpy(sc, bstr("sc"));
1695
1696         if (strcasecmp(sc, "Delete")) {
1697                 display_error("Cancelled.  This room was not deleted.");
1698                 return;
1699         }
1700         serv_puts("KILL 1");
1701         serv_gets(buf);
1702         if (buf[0] != '2') {
1703                 display_error(&buf[4]);
1704         } else {
1705                 smart_goto("_BASEROOM_");
1706         }
1707 }
1708
1709
1710
1711 /*
1712  * Perform changes to a room's network configuration
1713  */
1714 void netedit(void) {
1715         FILE *fp;
1716         char buf[SIZ];
1717         char line[SIZ];
1718
1719         if (strlen(bstr("line"))==0) {
1720                 display_editroom();
1721                 return;
1722         }
1723
1724         strcpy(line, bstr("prefix"));
1725         strcat(line, bstr("line"));
1726         strcat(line, bstr("suffix"));
1727
1728         fp = tmpfile();
1729         if (fp == NULL) {
1730                 display_editroom();
1731                 return;
1732         }
1733
1734         serv_puts("GNET");
1735         serv_gets(buf);
1736         if (buf[0] != '1') {
1737                 fclose(fp);
1738                 display_editroom();
1739                 return;
1740         }
1741
1742         /* This loop works for add *or* remove.  Spiffy, eh? */
1743         while (serv_gets(buf), strcmp(buf, "000")) {
1744                 if (strcasecmp(buf, line)) {
1745                         fprintf(fp, "%s\n", buf);
1746                 }
1747         }
1748
1749         rewind(fp);
1750         serv_puts("SNET");
1751         serv_gets(buf);
1752         if (buf[0] != '4') {
1753                 fclose(fp);
1754                 display_editroom();
1755                 return;
1756         }
1757
1758         while (fgets(buf, sizeof buf, fp) != NULL) {
1759                 buf[strlen(buf)-1] = 0;
1760                 serv_puts(buf);
1761         }
1762
1763         if (!strcasecmp(bstr("cmd"), "add")) {
1764                 serv_puts(line);
1765         }
1766
1767         serv_puts("000");
1768         fclose(fp);
1769         display_editroom();
1770 }
1771
1772
1773
1774 /*
1775  * Convert a room name to a folder-ish-looking name.
1776  */
1777 void room_to_folder(char *folder, char *room, int floor, int is_mailbox)
1778 {
1779         int i;
1780
1781         /*
1782          * For mailboxes, just do it straight...
1783          */
1784         if (is_mailbox) {
1785                 sprintf(folder, "My folders|%s", room);
1786         }
1787
1788         /*
1789          * Otherwise, prefix the floor name as a "public folders" moniker
1790          */
1791         else {
1792                 sprintf(folder, "%s|%s", floorlist[floor], room);
1793         }
1794
1795         /*
1796          * Replace "\" characters with "|" for pseudo-folder-delimiting
1797          */
1798         for (i=0; i<strlen(folder); ++i) {
1799                 if (folder[i] == '\\') folder[i] = '|';
1800         }
1801 }
1802
1803
1804
1805
1806
1807
1808
1809 /*
1810  * Change the view for this room
1811  */
1812 void change_view(void) {
1813         int view;
1814         char buf[SIZ];
1815
1816         view = atol(bstr("view"));
1817
1818         serv_printf("VIEW %d", view);
1819         serv_gets(buf);
1820         smart_goto(WC->wc_roomname);
1821 }
1822
1823
1824 /*
1825  * One big expanded tree list view --- like a folder list
1826  */
1827 void do_folder_view(struct folder *fold, int max_folders, int num_floors) {
1828         char buf[SIZ];
1829         int levels, oldlevels;
1830         int i, t;
1831
1832         do_template("beginbox_nt");
1833         levels = 0;
1834         oldlevels = 0;
1835         for (i=0; i<max_folders; ++i) {
1836
1837                 levels = num_tokens(fold[i].name, '|');
1838                 oldlevels = levels;
1839
1840                 for (t=0; t<levels; ++t) wprintf("&nbsp;&nbsp;&nbsp;");
1841                 if (fold[i].selectable) {
1842                         wprintf("<A HREF=\"/dotgoto?room=");
1843                         urlescputs(fold[i].room);
1844                         wprintf("\">");
1845                 }
1846                 else {
1847                         wprintf("<i>");
1848                 }
1849                 if (fold[i].hasnewmsgs) {
1850                         wprintf("<SPAN CLASS=\"roomlist_new\">");
1851                 }
1852                 else {
1853                         wprintf("<SPAN CLASS=\"roomlist_old\">");
1854                 }
1855                 extract(buf, fold[i].name, levels-1);
1856                 escputs(buf);
1857                 wprintf("</SPAN>");
1858                 if (fold[i].selectable) {
1859                         wprintf("</A>");
1860                 }
1861                 else {
1862                         wprintf("</i>");
1863                 }
1864                 if (!strcasecmp(fold[i].name, "My Folders|Mail")) {
1865                         wprintf(" (INBOX)");
1866                 }
1867                 wprintf("<BR>\n");
1868         }
1869         do_template("endbox");
1870 }
1871
1872 /*
1873  * Boxes and rooms and lists ... oh my!
1874  */
1875 void do_rooms_view(struct folder *fold, int max_folders, int num_floors) {
1876         char buf[SIZ];
1877         char boxtitle[SIZ];
1878         int levels, oldlevels;
1879         int i, t;
1880         int num_boxes = 0;
1881         static int columns = 3;
1882         int boxes_per_column = 0;
1883         int current_column = 0;
1884         int nf;
1885
1886         nf = num_floors;
1887         while (nf % columns != 0) ++nf;
1888         boxes_per_column = (nf / columns);
1889         if (boxes_per_column < 1) boxes_per_column = 1;
1890
1891         /* Outer table (for columnization) */
1892         wprintf("<TABLE BORDER=0 WIDTH=100%% CELLPADDING=5>"
1893                 "<TR><TD VALIGN=TOP>");
1894
1895         levels = 0;
1896         oldlevels = 0;
1897         for (i=0; i<max_folders; ++i) {
1898
1899                 levels = num_tokens(fold[i].name, '|');
1900
1901                 if ((levels == 1) && (oldlevels == 2)) {
1902
1903                         /* End inner box */
1904                         do_template("endbox");
1905
1906                         ++num_boxes;
1907                         if ((num_boxes % boxes_per_column) == 0) {
1908                                 ++current_column;
1909                                 if (current_column < columns) {
1910                                         wprintf("</TD><TD VALIGN=TOP>\n");
1911                                 }
1912                         }
1913                 }
1914
1915                 if (levels == 1) {
1916
1917                         /* Begin inner box */
1918                         extract(buf, fold[i].name, levels-1);
1919                         stresc(boxtitle, buf, 1);
1920                         svprintf("BOXTITLE", WCS_STRING, boxtitle);
1921                         do_template("beginbox");
1922
1923                 }
1924
1925                 oldlevels = levels;
1926
1927                 if (levels > 1) {
1928                         wprintf("&nbsp;");
1929                         if (levels>2) for (t=0; t<(levels-2); ++t) wprintf("&nbsp;&nbsp;&nbsp;");
1930                         if (fold[i].selectable) {
1931                                 wprintf("<A HREF=\"/dotgoto?room=");
1932                                 urlescputs(fold[i].room);
1933                                 wprintf("\">");
1934                         }
1935                         else {
1936                                 wprintf("<i>");
1937                         }
1938                         if (fold[i].hasnewmsgs) {
1939                                 wprintf("<SPAN CLASS=\"roomlist_new\">");
1940                         }
1941                         else {
1942                                 wprintf("<SPAN CLASS=\"roomlist_old\">");
1943                         }
1944                         extract(buf, fold[i].name, levels-1);
1945                         escputs(buf);
1946                         wprintf("</SPAN>");
1947                         if (fold[i].selectable) {
1948                                 wprintf("</A>");
1949                         }
1950                         else {
1951                                 wprintf("</i>");
1952                         }
1953                         if (!strcasecmp(fold[i].name, "My Folders|Mail")) {
1954                                 wprintf(" (INBOX)");
1955                         }
1956                         wprintf("<BR>\n");
1957                 }
1958         }
1959         /* End the final inner box */
1960         do_template("endbox");
1961
1962         wprintf("</TD></TR></TABLE>\n");
1963 }
1964
1965
1966 /*
1967  * Show the room list.  (only should get called by
1968  * knrooms() because that's where output_headers() is called from)
1969  */
1970
1971 void list_all_rooms_by_floor(char *viewpref) {
1972         char buf[SIZ];
1973         int swap = 0;
1974         struct folder *fold = NULL;
1975         struct folder ftmp;
1976         int max_folders = 0;
1977         int alloc_folders = 0;
1978         int i, j;
1979         int ra_flags = 0;
1980         int flags = 0;
1981         int num_floors = 1;     /* add an extra one for private folders */
1982
1983         /* Start with the mailboxes */
1984         max_folders = 1;
1985         alloc_folders = 1;
1986         fold = malloc(sizeof(struct folder));
1987         memset(fold, 0, sizeof(struct folder));
1988         strcpy(fold[0].name, "My folders");
1989         fold[0].is_mailbox = 1;
1990
1991         /* Then add floors */
1992         serv_puts("LFLR");
1993         serv_gets(buf);
1994         if (buf[0]=='1') while(serv_gets(buf), strcmp(buf, "000")) {
1995                 if (max_folders >= alloc_folders) {
1996                         alloc_folders = max_folders + 100;
1997                         fold = realloc(fold,
1998                                 alloc_folders * sizeof(struct folder));
1999                 }
2000                 memset(&fold[max_folders], 0, sizeof(struct folder));
2001                 extract(fold[max_folders].name, buf, 1);
2002                 ++max_folders;
2003                 ++num_floors;
2004         }
2005
2006         /* Now add rooms */
2007         serv_puts("LKRA");
2008         serv_gets(buf);
2009         if (buf[0]=='1') while(serv_gets(buf), strcmp(buf, "000")) {
2010                 if (max_folders >= alloc_folders) {
2011                         alloc_folders = max_folders + 100;
2012                         fold = realloc(fold,
2013                                 alloc_folders * sizeof(struct folder));
2014                 }
2015                 memset(&fold[max_folders], 0, sizeof(struct folder));
2016                 extract(fold[max_folders].room, buf, 0);
2017                 ra_flags = extract_int(buf, 5);
2018                 flags = extract_int(buf, 1);
2019                 fold[max_folders].floor = extract_int(buf, 2);
2020                 fold[max_folders].hasnewmsgs =
2021                         ((ra_flags & UA_HASNEWMSGS) ? 1 : 0 );
2022                 if (flags & QR_MAILBOX) {
2023                         fold[max_folders].is_mailbox = 1;
2024                 }
2025                 room_to_folder(fold[max_folders].name,
2026                                 fold[max_folders].room,
2027                                 fold[max_folders].floor,
2028                                 fold[max_folders].is_mailbox);
2029                 fold[max_folders].selectable = 1;
2030                 ++max_folders;
2031         }
2032
2033         /* Bubble-sort the folder list */
2034         for (i=0; i<max_folders; ++i) {
2035                 for (j=0; j<(max_folders-1)-i; ++j) {
2036                         if (fold[j].is_mailbox == fold[j+1].is_mailbox) {
2037                                 swap = strcasecmp(fold[j].name, fold[j+1].name);
2038                         }
2039                         else {
2040                                 if ( (fold[j+1].is_mailbox)
2041                                    && (!fold[j].is_mailbox)) {
2042                                         swap = 1;
2043                                 }
2044                                 else {
2045                                         swap = 0;
2046                                 }
2047                         }
2048                         if (swap > 0) {
2049                                 memcpy(&ftmp, &fold[j], sizeof(struct folder));
2050                                 memcpy(&fold[j], &fold[j+1],
2051                                                         sizeof(struct folder));
2052                                 memcpy(&fold[j+1], &ftmp,
2053                                                         sizeof(struct folder));
2054                         }
2055                 }
2056         }
2057
2058         if (!strcasecmp(viewpref, "folders")) {
2059                 do_folder_view(fold, max_folders, num_floors);
2060         }
2061         else {
2062                 do_rooms_view(fold, max_folders, num_floors);
2063         }
2064
2065         free(fold);
2066         wDumpContent(1);
2067 }
2068
2069
2070 /* Do either a known rooms list or a folders list, depending on the
2071  * user's preference
2072  */
2073 void knrooms() {
2074         char listviewpref[SIZ];
2075
2076         output_headers(3);
2077         load_floorlist();
2078
2079         /* Determine whether the user is trying to change views */
2080         if (bstr("view") != NULL) {
2081                 if (strlen(bstr("view")) > 0) {
2082                         set_preference("roomlistview", bstr("view"));
2083                 }
2084         }
2085
2086         get_preference("roomlistview", listviewpref);
2087
2088         if ( (strcasecmp(listviewpref, "folders"))
2089            && (strcasecmp(listviewpref, "table")) ) {
2090                 strcpy(listviewpref, "rooms");
2091         }
2092
2093         /* title bar */
2094         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#000077\"><TR><TD>"
2095                 "<SPAN CLASS=\"titlebar\">"
2096         );
2097         if (!strcasecmp(listviewpref, "rooms")) {
2098                 wprintf("Room list");
2099         }
2100         if (!strcasecmp(listviewpref, "folders")) {
2101                 wprintf("Folder list");
2102         }
2103         if (!strcasecmp(listviewpref, "table")) {
2104                 wprintf("Room list");
2105         }
2106         wprintf("</SPAN></TD>\n");
2107
2108
2109         /* offer the ability to switch views */
2110         wprintf("<TD><FORM NAME=\"roomlistomatic\">\n"
2111                 "<SELECT NAME=\"newview\" SIZE=\"1\" "
2112                 "OnChange=\"location.href=roomlistomatic.newview.options"
2113                 "[selectedIndex].value\">\n");
2114
2115         wprintf("<OPTION %s VALUE=\"/knrooms&view=rooms\">"
2116                 "View as room list"
2117                 "</OPTION>\n",
2118                 ( !strcasecmp(listviewpref, "rooms") ? "SELECTED" : "" )
2119         );
2120
2121         wprintf("<OPTION %s VALUE=\"/knrooms&view=folders\">"
2122                 "View as folder list"
2123                 "</OPTION>\n",
2124                 ( !strcasecmp(listviewpref, "folders") ? "SELECTED" : "" )
2125         );
2126
2127         wprintf("<OPTION %s VALUE=\"/knrooms&view=table\">"
2128                 "Classic table view"
2129                 "</OPTION>\n",
2130                 ( !strcasecmp(listviewpref, "table") ? "SELECTED" : "" )
2131         );
2132
2133         wprintf("</SELECT></FORM></TD><TD>\n");
2134         offer_start_page();
2135         wprintf("</TD></TR></TABLE>\n");
2136
2137         /* Display the room list in the user's preferred format */
2138         if (!strcasecmp(listviewpref, "table")) {
2139                 tabular_room_list();
2140         }
2141         else {
2142                 list_all_rooms_by_floor(listviewpref);
2143         }
2144 }