* roomops.c: Display one less floor in the first column in romlist view
[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, "CENTER");
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                 strcpy(WC->ImportantMessage, &buf[4]);
747                 display_main_menu();
748                 return;
749         }
750         extract(er_name, &buf[4], 0);
751         extract(er_password, &buf[4], 1);
752         extract(er_dirname, &buf[4], 2);
753         er_flags = extract_int(&buf[4], 3);
754         er_floor = extract_int(&buf[4], 4);
755
756         output_headers(1);
757
758         /* print the tabbed dialog */
759         wprintf("<TABLE border=0 cellspacing=0 cellpadding=0 width=100%%>"
760                 "<TR ALIGN=CENTER>"
761                 "<TD>&nbsp;</TD>\n");
762
763         if (!strcmp(tab, "admin")) {
764                 wprintf("<TD BGCOLOR=\"#FFFFFF\"><SPAN CLASS=\"tablabel\">");
765         }
766         else {
767                 wprintf("<TD BGCOLOR=\"#AAAAAA\"><A HREF=\"/display_editroom&tab=admin\">");
768         }
769         wprintf("Room administration");
770         if (!strcmp(tab, "admin")) {
771                 wprintf("</SPAN></TD>\n");
772         }
773         else {
774                 wprintf("</A></TD>\n");
775         }
776
777         wprintf("<TD>&nbsp;</TD>\n");
778
779         if (!strcmp(tab, "config")) {
780                 wprintf("<TD BGCOLOR=\"#FFFFFF\"><SPAN CLASS=\"tablabel\">");
781         }
782         else {
783                 wprintf("<TD BGCOLOR=\"#AAAAAA\"><A HREF=\"/display_editroom&tab=config\">");
784         }
785         wprintf("Room configuration");
786         if (!strcmp(tab, "config")) {
787                 wprintf("</SPAN></TD>\n");
788         }
789         else {
790                 wprintf("</A></TD>\n");
791         }
792
793         wprintf("<TD>&nbsp;</TD>\n");
794
795         if (!strcmp(tab, "sharing")) {
796                 wprintf("<TD BGCOLOR=\"#FFFFFF\"><SPAN CLASS=\"tablabel\">");
797         }
798         else {
799                 wprintf("<TD BGCOLOR=\"#AAAAAA\"><A HREF=\"/display_editroom&tab=sharing\">");
800         }
801         wprintf("Sharing");
802         if (!strcmp(tab, "sharing")) {
803                 wprintf("</SPAN></TD>\n");
804         }
805         else {
806                 wprintf("</A></TD>\n");
807         }
808
809         wprintf("<TD>&nbsp;</TD>\n");
810
811         if (!strcmp(tab, "listserv")) {
812                 wprintf("<TD BGCOLOR=\"#FFFFFF\"><SPAN CLASS=\"tablabel\">");
813         }
814         else {
815                 wprintf("<TD BGCOLOR=\"#AAAAAA\"><A HREF=\"/display_editroom&tab=listserv\">");
816         }
817         wprintf("Mailing list service");
818         if (!strcmp(tab, "listserv")) {
819                 wprintf("</SPAN></TD>\n");
820         }
821         else {
822                 wprintf("</A></TD>\n");
823         }
824
825         wprintf("</TR></TABLE>\n");
826         /* end tabbed dialog */ 
827
828         /* begin content of whatever tab is open now */
829         wprintf("<TABLE border=0 width=100%% bgcolor=\"#FFFFFF\">\n"
830                 "<TR><TD>\n");
831
832         if (!strcmp(tab, "admin")) {
833                 wprintf("<UL>"
834                         "<LI><A HREF=\"/confirm_delete_room\">\n"
835                         "Delete this room</A>\n"
836                         "<LI><A HREF=\"/display_editroompic\">\n"
837                         "Set or change the graphic for this room's banner</A>\n"
838                         "<LI><A HREF=\"/display_editinfo\">\n"
839                         "Edit this room's Info file</A>\n"
840                         "</UL>");
841         }
842
843         if (!strcmp(tab, "config")) {
844                 wprintf("<FORM METHOD=\"POST\" ACTION=\"/editroom\">\n");
845         
846                 wprintf("<UL><LI>Name of room: ");
847                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", er_name);
848         
849                 wprintf("<LI>Resides on floor: ");
850                 load_floorlist();
851                 wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
852                 for (i = 0; i < 128; ++i)
853                         if (strlen(floorlist[i]) > 0) {
854                                 wprintf("<OPTION ");
855                                 if (i == er_floor)
856                                         wprintf("SELECTED ");
857                                 wprintf("VALUE=\"%d\">", i);
858                                 escputs(floorlist[i]);
859                                 wprintf("</OPTION>\n");
860                         }
861                 wprintf("</SELECT>\n");
862         
863                 wprintf("<LI>Type of room:<UL>\n");
864
865                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
866                 if ((er_flags & QR_PRIVATE) == 0)
867                 wprintf("CHECKED ");
868                 wprintf("> Public room\n");
869
870                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
871                 if ((er_flags & QR_PRIVATE) &&
872                     (er_flags & QR_GUESSNAME))
873                         wprintf("CHECKED ");
874                 wprintf("> Private - guess name\n");
875         
876                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
877                 if ((er_flags & QR_PRIVATE) &&
878                     (er_flags & QR_PASSWORDED))
879                         wprintf("CHECKED ");
880                 wprintf("> Private - require password:\n");
881                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" VALUE=\"%s\" MAXLENGTH=\"9\">\n", er_password);
882         
883                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
884                 if ((er_flags & QR_PRIVATE)
885                     && ((er_flags & QR_GUESSNAME) == 0)
886                     && ((er_flags & QR_PASSWORDED) == 0))
887                         wprintf("CHECKED ");
888                 wprintf("> Private - invitation only\n");
889         
890                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"bump\" VALUE=\"yes\" ");
891                 wprintf("> If private, cause current users to forget room\n");
892         
893                 wprintf("</UL>\n");
894         
895                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"prefonly\" VALUE=\"yes\" ");
896                 if (er_flags & QR_PREFONLY)
897                         wprintf("CHECKED ");
898                 wprintf("> Preferred users only\n");
899         
900                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"readonly\" VALUE=\"yes\" ");
901                 if (er_flags & QR_READONLY)
902                         wprintf("CHECKED ");
903                 wprintf("> Read-only room\n");
904         
905         /* directory stuff */
906                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"directory\" VALUE=\"yes\" ");
907                 if (er_flags & QR_DIRECTORY)
908                         wprintf("CHECKED ");
909                 wprintf("> File directory room\n");
910
911                 wprintf("<UL><LI>Directory name: ");
912                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_dirname\" VALUE=\"%s\" MAXLENGTH=\"14\">\n", er_dirname);
913
914                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"ulallowed\" VALUE=\"yes\" ");
915                 if (er_flags & QR_UPLOAD)
916                         wprintf("CHECKED ");
917                 wprintf("> Uploading allowed\n");
918         
919                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"dlallowed\" VALUE=\"yes\" ");
920                 if (er_flags & QR_DOWNLOAD)
921                         wprintf("CHECKED ");
922                 wprintf("> Downloading allowed\n");
923         
924                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"visdir\" VALUE=\"yes\" ");
925                 if (er_flags & QR_VISDIR)
926                         wprintf("CHECKED ");
927                 wprintf("> Visible directory</UL>\n");
928         
929         /* end of directory stuff */
930         
931                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"network\" VALUE=\"yes\" ");
932                 if (er_flags & QR_NETWORK)
933                         wprintf("CHECKED ");
934                 wprintf("> Network shared room\n");
935
936         /* start of anon options */
937         
938                 wprintf("<LI>Anonymous messages<UL>\n");
939         
940                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"no\" ");
941                 if (((er_flags & QR_ANONONLY) == 0)
942                     && ((er_flags & QR_ANONOPT) == 0))
943                         wprintf("CHECKED ");
944                 wprintf("> No anonymous messages\n");
945         
946                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anononly\" ");
947                 if (er_flags & QR_ANONONLY)
948                         wprintf("CHECKED ");
949                 wprintf("> All messages are anonymous\n");
950         
951                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anon2\" ");
952                 if (er_flags & QR_ANONOPT)
953                         wprintf("CHECKED ");
954                 wprintf("> Prompt user when entering messages</UL>\n");
955         
956         /* end of anon options */
957         
958                 wprintf("<LI>Room aide: \n");
959                 serv_puts("GETA");
960                 serv_gets(buf);
961                 if (buf[0] != '2') {
962                         wprintf("<EM>%s</EM>\n", &buf[4]);
963                 } else {
964                         extract(er_roomaide, &buf[4], 0);
965                         wprintf("<INPUT TYPE=\"text\" NAME=\"er_roomaide\" VALUE=\"%s\" MAXLENGTH=\"25\">\n", er_roomaide);
966                 }
967         
968                 wprintf("</UL><CENTER>\n");
969                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
970                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
971                 wprintf("</CENTER>\n");
972         }
973
974
975         /* Sharing the room with other Citadel nodes... */
976         if (!strcmp(tab, "sharing")) {
977
978                 shared_with = strdup("");
979                 not_shared_with = strdup("");
980
981                 /* Learn the current configuration */
982                 serv_puts("CONF getsys|application/x-citadel-ignet-config");
983                 serv_gets(buf);
984                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
985                         extract(node, buf, 0);
986                         not_shared_with = realloc(not_shared_with,
987                                         strlen(not_shared_with) + 32);
988                         strcat(not_shared_with, node);
989                         strcat(not_shared_with, "|");
990                 }
991
992                 serv_puts("GNET");
993                 serv_gets(buf);
994                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
995                         extract(cmd, buf, 0);
996                         extract(node, buf, 1);
997                         if (!strcasecmp(cmd, "ignet_push_share")) {
998                                 shared_with = realloc(shared_with,
999                                                 strlen(shared_with) + 32);
1000                                 strcat(shared_with, node);
1001                                 strcat(shared_with, "|");
1002                         }
1003                 }
1004
1005                 for (i=0; i<num_tokens(shared_with, '|'); ++i) {
1006                         extract(node, shared_with, i);
1007                         for (j=0; j<num_tokens(not_shared_with, '|'); ++j) {
1008                                 extract(cmd, not_shared_with, j);
1009                                 if (!strcasecmp(node, cmd)) {
1010                                         remove_token(not_shared_with, j, '|');
1011                                 }
1012                         }
1013                 }
1014
1015                 /* Display the stuff */
1016                 wprintf("<CENTER><BR>"
1017                         "<TABLE border=1 cellpadding=5><TR>"
1018                         "<TD><B><I>Shared with</I></B></TD>"
1019                         "<TD><B><I>Not shared with</I></B></TD></TR>\n"
1020                         "<TR><TD>\n");
1021
1022                 for (i=0; i<num_tokens(shared_with, '|'); ++i) {
1023                         extract(node, shared_with, i);
1024                         if (strlen(node) > 0) {
1025                                 wprintf("%s ", node);
1026                                 wprintf("<A HREF=\"/netedit&cmd=remove&line="
1027                                         "ignet_push_share|");
1028                                 urlescputs(node);
1029                                 wprintf("&tab=sharing\">(unshare)</A><BR>");
1030                         }
1031                 }
1032
1033                 wprintf("</TD><TD>\n");
1034
1035                 for (i=0; i<num_tokens(not_shared_with, '|'); ++i) {
1036                         extract(node, not_shared_with, i);
1037                         if (strlen(node) > 0) {
1038                                 wprintf("%s ", node);
1039                                 wprintf("<A HREF=\"/netedit&cmd=add&line="
1040                                         "ignet_push_share|");
1041                                 urlescputs(node);
1042                                 wprintf("&tab=sharing\">(share)</A><BR>");
1043                         }
1044                 }
1045
1046                 wprintf("</TD></TR>"
1047                         "</TABLE><BR>\n"
1048                         "<I><B>Reminder:</B> When sharing a room, "
1049                         "it must be shared from both ends.  Adding a node to "
1050                         "the 'shared' list sends messages out, but in order to"
1051                         " receive messages, the other nodes must be configured"
1052                         " to send messages out to your system as well.</I><BR>"
1053                         "</CENTER>\n");
1054
1055         }
1056
1057         /* Mailing list management */
1058         if (!strcmp(tab, "listserv")) {
1059
1060                 wprintf("<BR><center>"
1061                         "<TABLE BORDER=0 WIDTH=100%% CELLPADDING=5>"
1062                         "<TR><TD VALIGN=TOP>");
1063
1064                 wprintf("<i>The contents of this room are being "
1065                         "mailed <b>as individual messages</b> "
1066                         "to the following list recipients:"
1067                         "</i><br><br>\n");
1068
1069                 serv_puts("GNET");
1070                 serv_gets(buf);
1071                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
1072                         extract(cmd, buf, 0);
1073                         if (!strcasecmp(cmd, "listrecp")) {
1074                                 extract(recp, buf, 1);
1075                         
1076                                 escputs(recp);
1077                                 wprintf(" <A HREF=\"/netedit&cmd=remove&line="
1078                                         "listrecp|");
1079                                 urlescputs(recp);
1080                                 wprintf("&tab=listserv\">(remove)</A><BR>");
1081
1082                         }
1083                 }
1084                 wprintf("<BR><FORM METHOD=\"POST\" ACTION=\"/netedit\">\n"
1085                         "<INPUT TYPE=\"hidden\" NAME=\"tab\" VALUE=\"listserv\">\n"
1086                         "<INPUT TYPE=\"hidden\" NAME=\"prefix\" VALUE=\"listrecp|\">\n");
1087                 wprintf("<INPUT TYPE=\"text\" NAME=\"line\">\n");
1088                 wprintf("<INPUT TYPE=\"submit\" NAME=\"cmd\" VALUE=\"Add\">");
1089                 wprintf("</FORM>\n");
1090
1091                 wprintf("</TD><TD VALIGN=TOP>\n");
1092                 
1093                 wprintf("<i>The contents of this room are being "
1094                         "mailed <b>in digest form</b> "
1095                         "to the following list recipients:"
1096                         "</i><br><br>\n");
1097
1098                 serv_puts("GNET");
1099                 serv_gets(buf);
1100                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
1101                         extract(cmd, buf, 0);
1102                         if (!strcasecmp(cmd, "digestrecp")) {
1103                                 extract(recp, buf, 1);
1104                         
1105                                 escputs(recp);
1106                                 wprintf(" <A HREF=\"/netedit&cmd=remove&line="
1107                                         "digestrecp|");
1108                                 urlescputs(recp);
1109                                 wprintf("&tab=listserv\">(remove)</A><BR>");
1110
1111                         }
1112                 }
1113                 wprintf("<BR><FORM METHOD=\"POST\" ACTION=\"/netedit\">\n"
1114                         "<INPUT TYPE=\"hidden\" NAME=\"tab\" VALUE=\"listserv\">\n"
1115                         "<INPUT TYPE=\"hidden\" NAME=\"prefix\" VALUE=\"digestrecp|\">\n");
1116                 wprintf("<INPUT TYPE=\"text\" NAME=\"line\">\n");
1117                 wprintf("<INPUT TYPE=\"submit\" NAME=\"cmd\" VALUE=\"Add\">");
1118                 wprintf("</FORM>\n");
1119                 
1120                 wprintf("</TD></TR></TABLE><HR>\n");
1121
1122                 if (self_service(999) == 1) {
1123                         wprintf("This room is configured to allow "
1124                                 "self-service subscribe/unsubscribe requests."
1125                                 " <A HREF=\"/toggle_self_service?newval=0&"
1126                                 "tab=listserv\">"
1127                                 "Click to disable.</A><BR>\n"
1128                                 "The URL for subscribe/unsubscribe is: "
1129                                 "<TT>http://%s/listsub</TT><BR>\n",
1130                                 WC->http_host
1131                         );
1132                 }
1133                 else {
1134                         wprintf("This room is <i>not</i> configured to allow "
1135                                 "self-service subscribe/unsubscribe requests."
1136                                 " <A HREF=\"/toggle_self_service?newval=1&"
1137                                 "tab=listserv\">"
1138                                 "Click to enable.</A><BR>\n"
1139                         );
1140                 }
1141
1142
1143                 wprintf("</CENTER>\n");
1144         }
1145
1146         /* end content of whatever tab is open now */
1147         wprintf("</TD></TR></TABLE>\n");
1148
1149         wDumpContent(1);
1150 }
1151
1152
1153 /* 
1154  * Toggle self-service list subscription
1155  */
1156 void toggle_self_service(void) {
1157         int newval = 0;
1158
1159         newval = atoi(bstr("newval"));
1160         self_service(newval);
1161         display_editroom();
1162 }
1163
1164
1165
1166 /*
1167  * save new parameters for a room
1168  */
1169 void editroom(void)
1170 {
1171         char buf[SIZ];
1172         char er_name[20];
1173         char er_password[10];
1174         char er_dirname[15];
1175         char er_roomaide[26];
1176         int er_floor;
1177         unsigned er_flags;
1178         int bump;
1179
1180
1181         if (strcmp(bstr("sc"), "OK")) {
1182                 strcpy(WC->ImportantMessage,
1183                         "Cancelled.  Changes were not saved.");
1184                 display_main_menu();
1185                 return;
1186         }
1187         serv_puts("GETR");
1188         serv_gets(buf);
1189
1190         if (buf[0] != '2') {
1191                 strcpy(WC->ImportantMessage, &buf[4]);
1192                 display_main_menu();
1193                 return;
1194         }
1195         extract(er_name, &buf[4], 0);
1196         extract(er_password, &buf[4], 1);
1197         extract(er_dirname, &buf[4], 2);
1198         er_flags = extract_int(&buf[4], 3);
1199
1200         strcpy(er_roomaide, bstr("er_roomaide"));
1201         if (strlen(er_roomaide) == 0) {
1202                 serv_puts("GETA");
1203                 serv_gets(buf);
1204                 if (buf[0] != '2') {
1205                         strcpy(er_roomaide, "");
1206                 } else {
1207                         extract(er_roomaide, &buf[4], 0);
1208                 }
1209         }
1210         strcpy(buf, bstr("er_name"));
1211         buf[20] = 0;
1212         if (strlen(buf) > 0)
1213                 strcpy(er_name, buf);
1214
1215         strcpy(buf, bstr("er_password"));
1216         buf[10] = 0;
1217         if (strlen(buf) > 0)
1218                 strcpy(er_password, buf);
1219
1220         strcpy(buf, bstr("er_dirname"));
1221         buf[15] = 0;
1222         if (strlen(buf) > 0)
1223                 strcpy(er_dirname, buf);
1224
1225         strcpy(buf, bstr("type"));
1226         er_flags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
1227
1228         if (!strcmp(buf, "invonly")) {
1229                 er_flags |= (QR_PRIVATE);
1230         }
1231         if (!strcmp(buf, "guessname")) {
1232                 er_flags |= (QR_PRIVATE | QR_GUESSNAME);
1233         }
1234         if (!strcmp(buf, "passworded")) {
1235                 er_flags |= (QR_PRIVATE | QR_PASSWORDED);
1236         }
1237         if (!strcmp(bstr("prefonly"), "yes")) {
1238                 er_flags |= QR_PREFONLY;
1239         } else {
1240                 er_flags &= ~QR_PREFONLY;
1241         }
1242
1243         if (!strcmp(bstr("readonly"), "yes")) {
1244                 er_flags |= QR_READONLY;
1245         } else {
1246                 er_flags &= ~QR_READONLY;
1247         }
1248
1249         if (!strcmp(bstr("network"), "yes")) {
1250                 er_flags |= QR_NETWORK;
1251         } else {
1252                 er_flags &= ~QR_NETWORK;
1253         }
1254
1255         if (!strcmp(bstr("directory"), "yes")) {
1256                 er_flags |= QR_DIRECTORY;
1257         } else {
1258                 er_flags &= ~QR_DIRECTORY;
1259         }
1260
1261         if (!strcmp(bstr("ulallowed"), "yes")) {
1262                 er_flags |= QR_UPLOAD;
1263         } else {
1264                 er_flags &= ~QR_UPLOAD;
1265         }
1266
1267         if (!strcmp(bstr("dlallowed"), "yes")) {
1268                 er_flags |= QR_DOWNLOAD;
1269         } else {
1270                 er_flags &= ~QR_DOWNLOAD;
1271         }
1272
1273         if (!strcmp(bstr("visdir"), "yes")) {
1274                 er_flags |= QR_VISDIR;
1275         } else {
1276                 er_flags &= ~QR_VISDIR;
1277         }
1278
1279         strcpy(buf, bstr("anon"));
1280
1281         er_flags &= ~(QR_ANONONLY | QR_ANONOPT);
1282         if (!strcmp(buf, "anononly"))
1283                 er_flags |= QR_ANONONLY;
1284         if (!strcmp(buf, "anon2"))
1285                 er_flags |= QR_ANONOPT;
1286
1287         bump = 0;
1288         if (!strcmp(bstr("bump"), "yes"))
1289                 bump = 1;
1290
1291         er_floor = atoi(bstr("er_floor"));
1292
1293         sprintf(buf, "SETR %s|%s|%s|%u|%d|%d",
1294              er_name, er_password, er_dirname, er_flags, bump, er_floor);
1295         serv_puts(buf);
1296         serv_gets(buf);
1297         if (buf[0] != '2') {
1298                 strcpy(WC->ImportantMessage, &buf[4]);
1299                 display_main_menu();
1300                 return;
1301         }
1302         gotoroom(er_name, 0);
1303
1304         if (strlen(er_roomaide) > 0) {
1305                 sprintf(buf, "SETA %s", er_roomaide);
1306                 serv_puts(buf);
1307                 serv_gets(buf);
1308                 if (buf[0] != '2') {
1309                         strcpy(WC->ImportantMessage, &buf[4]);
1310                         display_main_menu();
1311                         return;
1312                 }
1313         }
1314         smart_goto(er_name);
1315 }
1316
1317 /*
1318  * Invite, Kick, and show Who Knows a room
1319  */
1320 void display_whok(void)
1321 {
1322         char buf[SIZ], room[SIZ], username[SIZ];
1323
1324         serv_puts("GETR");
1325         serv_gets(buf);
1326
1327         if (buf[0] != '2') {
1328                 strcpy(WC->ImportantMessage, &buf[4]);
1329                 display_main_menu();
1330                 return;
1331         }
1332         extract(room, &buf[4], 0);
1333
1334         strcpy(username, bstr("username"));
1335
1336         if(!strcmp(bstr("sc"), "Kick")) {
1337                 sprintf(buf, "KICK %s", username);
1338                 serv_puts(buf);
1339                 serv_gets(buf);
1340
1341                 if (buf[0] != '2') {
1342                         strcpy(WC->ImportantMessage, &buf[4]);
1343                 } else {
1344                         sprintf(WC->ImportantMessage,
1345                                 "<B><I>User %s kicked out of room %s.</I></B>\n", 
1346                                 username, room);
1347                 }
1348         } else if(!strcmp(bstr("sc"), "Invite")) {
1349                 sprintf(buf, "INVT %s", username);
1350                 serv_puts(buf);
1351                 serv_gets(buf);
1352
1353                 if (buf[0] != '2') {
1354                         strcpy(WC->ImportantMessage, &buf[4]);
1355                 } else {
1356                         sprintf(WC->ImportantMessage,
1357                                 "<B><I>User %s invited to room %s.</I></B>\n", 
1358                                 username, room);
1359                 }
1360         }
1361         
1362         output_headers(1);
1363         stresc(buf, WC->wc_roomname, 1);
1364         svprintf("BOXTITLE", WCS_STRING, "Access control list for %s", buf);
1365         do_template("beginbox");
1366
1367         wprintf("<TABLE border=0 CELLSPACING=10><TR VALIGN=TOP>"
1368                 "<TD>The users listed below have access to this room.  "
1369                 "To remove a user from the access list, select the user "
1370                 "name from the list and click 'Kick'.<BR><BR>");
1371         
1372         wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/display_whok\">\n");
1373         wprintf("<SELECT NAME=\"username\" SIZE=10>\n");
1374         serv_puts("WHOK");
1375         serv_gets(buf);
1376         if (buf[0] == '1') {
1377                 while (serv_gets(buf), strcmp(buf, "000")) {
1378                         extract(username, buf, 0);
1379                         wprintf("<OPTION>");
1380                         escputs(username);
1381                         wprintf("\n");
1382                 }
1383         }
1384         wprintf("</SELECT><BR>\n");
1385
1386         wprintf("<input type=submit name=sc value=\"Kick\">");
1387         wprintf("</FORM></CENTER>\n");
1388
1389         wprintf("</TD><TD>"
1390                 "To grant another user access to this room, enter the "
1391                 "user name in the box below and click 'Invite'.<BR><BR>");
1392
1393         wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/display_whok\">\n");
1394         wprintf("Invite: ");
1395         wprintf("<input type=text name=username><BR>\n"
1396                 "<input type=hidden name=sc value=\"Invite\">"
1397                 "<input type=submit value=\"Invite\">"
1398                 "</FORM></CENTER>\n");
1399
1400         wprintf("</TD></TR></TABLE>\n");
1401         do_template("endbox");
1402         wDumpContent(1);
1403 }
1404
1405
1406
1407 /*
1408  * display the form for entering a new room
1409  */
1410 void display_entroom(void)
1411 {
1412         int i;
1413         char buf[SIZ];
1414
1415         serv_puts("CRE8 0");
1416         serv_gets(buf);
1417
1418         if (buf[0] != '2') {
1419                 strcpy(WC->ImportantMessage, &buf[4]);
1420                 display_main_menu();
1421                 return;
1422         }
1423         output_headers(3);
1424         svprintf("BOXTITLE", WCS_STRING, "Create a new room");
1425         do_template("beginbox");
1426
1427         wprintf("<FORM METHOD=\"POST\" ACTION=\"/entroom\">\n");
1428
1429         wprintf("<UL><LI>Name of room: ");
1430         wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" MAXLENGTH=\"19\">\n");
1431
1432         wprintf("<LI>Type of room:<UL>\n");
1433
1434         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
1435         wprintf("CHECKED > Public room\n");
1436
1437         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
1438         wprintf("> Private - guess name\n");
1439
1440         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
1441         wprintf("> Private - require password:\n");
1442         wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" MAXLENGTH=\"9\">\n");
1443
1444         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
1445         wprintf("> Private - invitation only\n");
1446
1447         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"personal\" ");
1448         wprintf("> Personal (mailbox for you only)\n");
1449         wprintf("</UL>\n");
1450
1451         wprintf("<LI>Resides on floor: ");
1452         load_floorlist(); 
1453         wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
1454         for (i = 0; i < 128; ++i)
1455                 if (strlen(floorlist[i]) > 0) {
1456                         wprintf("<OPTION ");
1457                         wprintf("VALUE=\"%d\">", i);
1458                         escputs(floorlist[i]);
1459                         wprintf("</OPTION>\n");
1460                 }
1461         wprintf("</SELECT>\n");                
1462         wprintf("</UL>\n");
1463
1464
1465         wprintf("<CENTER>\n");
1466         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1467         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1468         wprintf("</CENTER>\n");
1469         wprintf("</FORM>\n<HR>");
1470         serv_printf("MESG roomaccess");
1471         serv_gets(buf);
1472         if (buf[0] == '1') {
1473                 fmout(NULL, "CENTER");
1474         }
1475         do_template("endbox");
1476         wDumpContent(1);
1477 }
1478
1479
1480
1481 /*
1482  * enter a new room
1483  */
1484 void entroom(void)
1485 {
1486         char buf[SIZ];
1487         char er_name[20];
1488         char er_type[20];
1489         char er_password[10];
1490         int er_floor;
1491         int er_num_type;
1492
1493         if (strcmp(bstr("sc"), "OK")) {
1494                 strcpy(WC->ImportantMessage,
1495                         "Cancelled.  No new room was created.");
1496                 display_main_menu();
1497                 return;
1498         }
1499         strcpy(er_name, bstr("er_name"));
1500         strcpy(er_type, bstr("type"));
1501         strcpy(er_password, bstr("er_password"));
1502         er_floor = atoi(bstr("er_floor"));
1503
1504         er_num_type = 0;
1505         if (!strcmp(er_type, "guessname"))
1506                 er_num_type = 1;
1507         if (!strcmp(er_type, "passworded"))
1508                 er_num_type = 2;
1509         if (!strcmp(er_type, "invonly"))
1510                 er_num_type = 3;
1511         if (!strcmp(er_type, "personal"))
1512                 er_num_type = 4;
1513
1514         sprintf(buf, "CRE8 1|%s|%d|%s|%d", 
1515                 er_name, er_num_type, er_password, er_floor);
1516         serv_puts(buf);
1517         serv_gets(buf);
1518         if (buf[0] != '2') {
1519                 strcpy(WC->ImportantMessage, &buf[4]);
1520                 display_main_menu();
1521                 return;
1522         }
1523         smart_goto(er_name);
1524 }
1525
1526
1527 /*
1528  * display the screen to enter a private room
1529  */
1530 void display_private(char *rname, int req_pass)
1531 {
1532
1533         output_headers(3);
1534
1535         svprintf("BOXTITLE", WCS_STRING, "Go to a hidden room");
1536         do_template("beginbox");
1537
1538         wprintf("<CENTER>\n");
1539         wprintf("<BR>If you know the name of a hidden (guess-name) or\n");
1540         wprintf("passworded room, you can enter that room by typing\n");
1541         wprintf("its name below.  Once you gain access to a private\n");
1542         wprintf("room, it will appear in your regular room listings\n");
1543         wprintf("so you don't have to keep returning here.\n");
1544         wprintf("<BR><BR>");
1545
1546         wprintf("<FORM METHOD=\"GET\" ACTION=\"/goto_private\">\n");
1547
1548         wprintf("<table border=\"0\" cellspacing=\"5\" "
1549                 "cellpadding=\"5\" BGCOLOR=\"#EEEEEE\">\n"
1550                 "<TR><TD>"
1551                 "Enter room name:</TD><TD>"
1552                 "<INPUT TYPE=\"text\" NAME=\"gr_name\" "
1553                 "VALUE=\"%s\" MAXLENGTH=\"19\">\n", rname);
1554
1555         if (req_pass) {
1556                 wprintf("</TD></TR><TR><TD>");
1557                 wprintf("Enter room password:</TD><TD>");
1558                 wprintf("<INPUT TYPE=\"password\" NAME=\"gr_pass\" MAXLENGTH=\"9\">\n");
1559         }
1560         wprintf("</TD></TR></TABLE><BR>\n");
1561
1562         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">"
1563                 "&nbsp;"
1564                 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1565         wprintf("</FORM>\n");
1566         do_template("endbox");
1567         wDumpContent(1);
1568 }
1569
1570 /* 
1571  * goto a private room
1572  */
1573 void goto_private(void)
1574 {
1575         char hold_rm[SIZ];
1576         char buf[SIZ];
1577
1578         if (strcasecmp(bstr("sc"), "OK")) {
1579                 display_main_menu();
1580                 return;
1581         }
1582         strcpy(hold_rm, WC->wc_roomname);
1583         strcpy(buf, "GOTO ");
1584         strcat(buf, bstr("gr_name"));
1585         strcat(buf, "|");
1586         strcat(buf, bstr("gr_pass"));
1587         serv_puts(buf);
1588         serv_gets(buf);
1589
1590         if (buf[0] == '2') {
1591                 smart_goto(bstr("gr_name"));
1592                 return;
1593         }
1594         if (!strncmp(buf, "540", 3)) {
1595                 display_private(bstr("gr_name"), 1);
1596                 return;
1597         }
1598         output_headers(1);
1599         wprintf("%s\n", &buf[4]);
1600         wDumpContent(1);
1601         return;
1602 }
1603
1604
1605 /*
1606  * display the screen to zap a room
1607  */
1608 void display_zap(void)
1609 {
1610         output_headers(1);
1611
1612         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
1613         wprintf("<SPAN CLASS=\"titlebar\">Zap (forget) the current room</SPAN>\n");
1614         wprintf("</TD></TR></TABLE>\n");
1615
1616         wprintf("If you select this option, <em>%s</em> will ", WC->wc_roomname);
1617         wprintf("disappear from your room list.  Is this what you wish ");
1618         wprintf("to do?<BR>\n");
1619
1620         wprintf("<FORM METHOD=\"GET\" ACTION=\"/zap\">\n");
1621         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1622         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1623         wprintf("</FORM>\n");
1624         wDumpContent(1);
1625 }
1626
1627
1628 /* 
1629  * zap a room
1630  */
1631 void zap(void)
1632 {
1633         char buf[SIZ];
1634         char final_destination[SIZ];
1635
1636         /* If the forget-room routine fails for any reason, we fall back
1637          * to the current room; otherwise, we go to the Lobby
1638          */
1639         strcpy(final_destination, WC->wc_roomname);
1640
1641         if (!strcasecmp(bstr("sc"), "OK")) {
1642                 serv_printf("GOTO %s", WC->wc_roomname);
1643                 serv_gets(buf);
1644                 if (buf[0] != '2') {
1645                         /* ExpressMessageCat(&buf[4]); */
1646                 } else {
1647                         serv_puts("FORG");
1648                         serv_gets(buf);
1649                         if (buf[0] != '2') {
1650                                 /* ExpressMessageCat(&buf[4]); */
1651                         } else {
1652                                 strcpy(final_destination, "_BASEROOM_");
1653                         }
1654                 }
1655         }
1656         smart_goto(final_destination);
1657 }
1658
1659
1660
1661
1662 /*
1663  * Confirm deletion of the current room
1664  */
1665 void confirm_delete_room(void)
1666 {
1667         char buf[SIZ];
1668
1669         serv_puts("KILL 0");
1670         serv_gets(buf);
1671         if (buf[0] != '2') {
1672                 strcpy(WC->ImportantMessage, &buf[4]);
1673                 display_main_menu();
1674                 return;
1675         }
1676         output_headers(1);
1677         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
1678         wprintf("<SPAN CLASS=\"titlebar\">Confirm deletion of room</SPAN>\n");
1679         wprintf("</TD></TR></TABLE>\n");
1680
1681         wprintf("<CENTER>");
1682         wprintf("<FORM METHOD=\"GET\" ACTION=\"/delete_room\">\n");
1683
1684         wprintf("Are you sure you want to delete <FONT SIZE=+1>");
1685         escputs(WC->wc_roomname);
1686         wprintf("</FONT>?<BR>\n");
1687
1688         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">");
1689         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1690
1691         wprintf("</FORM></CENTER>\n");
1692         wDumpContent(1);
1693 }
1694
1695
1696 /*
1697  * Delete the current room
1698  */
1699 void delete_room(void)
1700 {
1701         char buf[SIZ];
1702         char sc[SIZ];
1703
1704         strcpy(sc, bstr("sc"));
1705
1706         if (strcasecmp(sc, "Delete")) {
1707                 strcpy(WC->ImportantMessage,
1708                         "Cancelled.  This room was not deleted.");
1709                 display_main_menu();
1710                 return;
1711         }
1712         serv_puts("KILL 1");
1713         serv_gets(buf);
1714         if (buf[0] != '2') {
1715                 strcpy(WC->ImportantMessage, &buf[4]);
1716                 display_main_menu();
1717                 return;
1718         } else {
1719                 smart_goto("_BASEROOM_");
1720         }
1721 }
1722
1723
1724
1725 /*
1726  * Perform changes to a room's network configuration
1727  */
1728 void netedit(void) {
1729         FILE *fp;
1730         char buf[SIZ];
1731         char line[SIZ];
1732
1733         if (strlen(bstr("line"))==0) {
1734                 display_editroom();
1735                 return;
1736         }
1737
1738         strcpy(line, bstr("prefix"));
1739         strcat(line, bstr("line"));
1740         strcat(line, bstr("suffix"));
1741
1742         fp = tmpfile();
1743         if (fp == NULL) {
1744                 display_editroom();
1745                 return;
1746         }
1747
1748         serv_puts("GNET");
1749         serv_gets(buf);
1750         if (buf[0] != '1') {
1751                 fclose(fp);
1752                 display_editroom();
1753                 return;
1754         }
1755
1756         /* This loop works for add *or* remove.  Spiffy, eh? */
1757         while (serv_gets(buf), strcmp(buf, "000")) {
1758                 if (strcasecmp(buf, line)) {
1759                         fprintf(fp, "%s\n", buf);
1760                 }
1761         }
1762
1763         rewind(fp);
1764         serv_puts("SNET");
1765         serv_gets(buf);
1766         if (buf[0] != '4') {
1767                 fclose(fp);
1768                 display_editroom();
1769                 return;
1770         }
1771
1772         while (fgets(buf, sizeof buf, fp) != NULL) {
1773                 buf[strlen(buf)-1] = 0;
1774                 serv_puts(buf);
1775         }
1776
1777         if (!strcasecmp(bstr("cmd"), "add")) {
1778                 serv_puts(line);
1779         }
1780
1781         serv_puts("000");
1782         fclose(fp);
1783         display_editroom();
1784 }
1785
1786
1787
1788 /*
1789  * Convert a room name to a folder-ish-looking name.
1790  */
1791 void room_to_folder(char *folder, char *room, int floor, int is_mailbox)
1792 {
1793         int i;
1794
1795         /*
1796          * For mailboxes, just do it straight...
1797          */
1798         if (is_mailbox) {
1799                 sprintf(folder, "My folders|%s", room);
1800         }
1801
1802         /*
1803          * Otherwise, prefix the floor name as a "public folders" moniker
1804          */
1805         else {
1806                 sprintf(folder, "%s|%s", floorlist[floor], room);
1807         }
1808
1809         /*
1810          * Replace "\" characters with "|" for pseudo-folder-delimiting
1811          */
1812         for (i=0; i<strlen(folder); ++i) {
1813                 if (folder[i] == '\\') folder[i] = '|';
1814         }
1815 }
1816
1817
1818
1819
1820
1821
1822
1823 /*
1824  * Change the view for this room
1825  */
1826 void change_view(void) {
1827         int view;
1828         char buf[SIZ];
1829
1830         view = atol(bstr("view"));
1831
1832         serv_printf("VIEW %d", view);
1833         serv_gets(buf);
1834         smart_goto(WC->wc_roomname);
1835 }
1836
1837
1838 /*
1839  * One big expanded tree list view --- like a folder list
1840  */
1841 void do_folder_view(struct folder *fold, int max_folders, int num_floors) {
1842         char buf[SIZ];
1843         int levels, oldlevels;
1844         int i, t;
1845
1846         do_template("beginbox_nt");
1847         levels = 0;
1848         oldlevels = 0;
1849         for (i=0; i<max_folders; ++i) {
1850
1851                 levels = num_tokens(fold[i].name, '|');
1852                 oldlevels = levels;
1853
1854                 for (t=0; t<levels; ++t) wprintf("&nbsp;&nbsp;&nbsp;");
1855                 if (fold[i].selectable) {
1856                         wprintf("<A HREF=\"/dotgoto?room=");
1857                         urlescputs(fold[i].room);
1858                         wprintf("\">");
1859                 }
1860                 else {
1861                         wprintf("<i>");
1862                 }
1863                 if (fold[i].hasnewmsgs) {
1864                         wprintf("<SPAN CLASS=\"roomlist_new\">");
1865                 }
1866                 else {
1867                         wprintf("<SPAN CLASS=\"roomlist_old\">");
1868                 }
1869                 extract(buf, fold[i].name, levels-1);
1870                 escputs(buf);
1871                 wprintf("</SPAN>");
1872                 if (fold[i].selectable) {
1873                         wprintf("</A>");
1874                 }
1875                 else {
1876                         wprintf("</i>");
1877                 }
1878                 if (!strcasecmp(fold[i].name, "My Folders|Mail")) {
1879                         wprintf(" (INBOX)");
1880                 }
1881                 wprintf("<BR>\n");
1882         }
1883         do_template("endbox");
1884 }
1885
1886 /*
1887  * Boxes and rooms and lists ... oh my!
1888  */
1889 void do_rooms_view(struct folder *fold, int max_folders, int num_floors) {
1890         char buf[SIZ];
1891         char boxtitle[SIZ];
1892         int levels, oldlevels;
1893         int i, t;
1894         int num_boxes = 0;
1895         static int columns = 3;
1896         int boxes_per_column = 0;
1897         int current_column = 0;
1898         int nf;
1899
1900         nf = num_floors;
1901         while (nf % columns != 0) ++nf;
1902         boxes_per_column = (nf / columns);
1903         if (boxes_per_column < 1) boxes_per_column = 1;
1904
1905         /* Outer table (for columnization) */
1906         wprintf("<TABLE BORDER=0 WIDTH=100%% CELLPADDING=5>"
1907                 "<TR><TD VALIGN=TOP>");
1908
1909         levels = 0;
1910         oldlevels = 0;
1911         for (i=0; i<max_folders; ++i) {
1912
1913                 levels = num_tokens(fold[i].name, '|');
1914
1915                 if ((levels == 1) && (oldlevels == 2)) {
1916
1917                         /* End inner box */
1918                         do_template("endbox");
1919
1920                         ++num_boxes;
1921                         if ((num_boxes % boxes_per_column) == boxes_per_column) {
1922                                 ++current_column;
1923                                 if (current_column < columns) {
1924                                         wprintf("</TD><TD VALIGN=TOP>\n");
1925                                 }
1926                         }
1927                 }
1928
1929                 if (levels == 1) {
1930
1931                         /* Begin inner box */
1932                         extract(buf, fold[i].name, levels-1);
1933                         stresc(boxtitle, buf, 1);
1934                         svprintf("BOXTITLE", WCS_STRING, boxtitle);
1935                         do_template("beginbox");
1936
1937                 }
1938
1939                 oldlevels = levels;
1940
1941                 if (levels > 1) {
1942                         wprintf("&nbsp;");
1943                         if (levels>2) for (t=0; t<(levels-2); ++t) wprintf("&nbsp;&nbsp;&nbsp;");
1944                         if (fold[i].selectable) {
1945                                 wprintf("<A HREF=\"/dotgoto?room=");
1946                                 urlescputs(fold[i].room);
1947                                 wprintf("\">");
1948                         }
1949                         else {
1950                                 wprintf("<i>");
1951                         }
1952                         if (fold[i].hasnewmsgs) {
1953                                 wprintf("<SPAN CLASS=\"roomlist_new\">");
1954                         }
1955                         else {
1956                                 wprintf("<SPAN CLASS=\"roomlist_old\">");
1957                         }
1958                         extract(buf, fold[i].name, levels-1);
1959                         escputs(buf);
1960                         wprintf("</SPAN>");
1961                         if (fold[i].selectable) {
1962                                 wprintf("</A>");
1963                         }
1964                         else {
1965                                 wprintf("</i>");
1966                         }
1967                         if (!strcasecmp(fold[i].name, "My Folders|Mail")) {
1968                                 wprintf(" (INBOX)");
1969                         }
1970                         wprintf("<BR>\n");
1971                 }
1972         }
1973         /* End the final inner box */
1974         do_template("endbox");
1975
1976         wprintf("</TD></TR></TABLE>\n");
1977 }
1978
1979
1980 /*
1981  * Show the room list.  (only should get called by
1982  * knrooms() because that's where output_headers() is called from)
1983  */
1984
1985 void list_all_rooms_by_floor(char *viewpref) {
1986         char buf[SIZ];
1987         int swap = 0;
1988         struct folder *fold = NULL;
1989         struct folder ftmp;
1990         int max_folders = 0;
1991         int alloc_folders = 0;
1992         int i, j;
1993         int ra_flags = 0;
1994         int flags = 0;
1995         int num_floors = 1;     /* add an extra one for private folders */
1996
1997         /* Start with the mailboxes */
1998         max_folders = 1;
1999         alloc_folders = 1;
2000         fold = malloc(sizeof(struct folder));
2001         memset(fold, 0, sizeof(struct folder));
2002         strcpy(fold[0].name, "My folders");
2003         fold[0].is_mailbox = 1;
2004
2005         /* Then add floors */
2006         serv_puts("LFLR");
2007         serv_gets(buf);
2008         if (buf[0]=='1') while(serv_gets(buf), strcmp(buf, "000")) {
2009                 if (max_folders >= alloc_folders) {
2010                         alloc_folders = max_folders + 100;
2011                         fold = realloc(fold,
2012                                 alloc_folders * sizeof(struct folder));
2013                 }
2014                 memset(&fold[max_folders], 0, sizeof(struct folder));
2015                 extract(fold[max_folders].name, buf, 1);
2016                 ++max_folders;
2017                 ++num_floors;
2018         }
2019
2020         /* Now add rooms */
2021         serv_puts("LKRA");
2022         serv_gets(buf);
2023         if (buf[0]=='1') while(serv_gets(buf), strcmp(buf, "000")) {
2024                 if (max_folders >= alloc_folders) {
2025                         alloc_folders = max_folders + 100;
2026                         fold = realloc(fold,
2027                                 alloc_folders * sizeof(struct folder));
2028                 }
2029                 memset(&fold[max_folders], 0, sizeof(struct folder));
2030                 extract(fold[max_folders].room, buf, 0);
2031                 ra_flags = extract_int(buf, 5);
2032                 flags = extract_int(buf, 1);
2033                 fold[max_folders].floor = extract_int(buf, 2);
2034                 fold[max_folders].hasnewmsgs =
2035                         ((ra_flags & UA_HASNEWMSGS) ? 1 : 0 );
2036                 if (flags & QR_MAILBOX) {
2037                         fold[max_folders].is_mailbox = 1;
2038                 }
2039                 room_to_folder(fold[max_folders].name,
2040                                 fold[max_folders].room,
2041                                 fold[max_folders].floor,
2042                                 fold[max_folders].is_mailbox);
2043                 fold[max_folders].selectable = 1;
2044                 ++max_folders;
2045         }
2046
2047         /* Bubble-sort the folder list */
2048         for (i=0; i<max_folders; ++i) {
2049                 for (j=0; j<(max_folders-1)-i; ++j) {
2050                         if (fold[j].is_mailbox == fold[j+1].is_mailbox) {
2051                                 swap = strcasecmp(fold[j].name, fold[j+1].name);
2052                         }
2053                         else {
2054                                 if ( (fold[j+1].is_mailbox)
2055                                    && (!fold[j].is_mailbox)) {
2056                                         swap = 1;
2057                                 }
2058                                 else {
2059                                         swap = 0;
2060                                 }
2061                         }
2062                         if (swap > 0) {
2063                                 memcpy(&ftmp, &fold[j], sizeof(struct folder));
2064                                 memcpy(&fold[j], &fold[j+1],
2065                                                         sizeof(struct folder));
2066                                 memcpy(&fold[j+1], &ftmp,
2067                                                         sizeof(struct folder));
2068                         }
2069                 }
2070         }
2071
2072         if (!strcasecmp(viewpref, "folders")) {
2073                 do_folder_view(fold, max_folders, num_floors);
2074         }
2075         else {
2076                 do_rooms_view(fold, max_folders, num_floors);
2077         }
2078
2079         free(fold);
2080         wDumpContent(1);
2081 }
2082
2083
2084 /* Do either a known rooms list or a folders list, depending on the
2085  * user's preference
2086  */
2087 void knrooms() {
2088         char listviewpref[SIZ];
2089
2090         output_headers(3);
2091         load_floorlist();
2092
2093         /* Determine whether the user is trying to change views */
2094         if (bstr("view") != NULL) {
2095                 if (strlen(bstr("view")) > 0) {
2096                         set_preference("roomlistview", bstr("view"));
2097                 }
2098         }
2099
2100         get_preference("roomlistview", listviewpref);
2101
2102         if ( (strcasecmp(listviewpref, "folders"))
2103            && (strcasecmp(listviewpref, "table")) ) {
2104                 strcpy(listviewpref, "rooms");
2105         }
2106
2107         /* title bar */
2108         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#000077\"><TR><TD>"
2109                 "<SPAN CLASS=\"titlebar\">"
2110         );
2111         if (!strcasecmp(listviewpref, "rooms")) {
2112                 wprintf("Room list");
2113         }
2114         if (!strcasecmp(listviewpref, "folders")) {
2115                 wprintf("Folder list");
2116         }
2117         if (!strcasecmp(listviewpref, "table")) {
2118                 wprintf("Room list");
2119         }
2120         wprintf("</SPAN></TD>\n");
2121
2122
2123         /* offer the ability to switch views */
2124         wprintf("<TD><FORM NAME=\"roomlistomatic\">\n"
2125                 "<SELECT NAME=\"newview\" SIZE=\"1\" "
2126                 "OnChange=\"location.href=roomlistomatic.newview.options"
2127                 "[selectedIndex].value\">\n");
2128
2129         wprintf("<OPTION %s VALUE=\"/knrooms&view=rooms\">"
2130                 "View as room list"
2131                 "</OPTION>\n",
2132                 ( !strcasecmp(listviewpref, "rooms") ? "SELECTED" : "" )
2133         );
2134
2135         wprintf("<OPTION %s VALUE=\"/knrooms&view=folders\">"
2136                 "View as folder list"
2137                 "</OPTION>\n",
2138                 ( !strcasecmp(listviewpref, "folders") ? "SELECTED" : "" )
2139         );
2140
2141         wprintf("<OPTION %s VALUE=\"/knrooms&view=table\">"
2142                 "Classic table view"
2143                 "</OPTION>\n",
2144                 ( !strcasecmp(listviewpref, "table") ? "SELECTED" : "" )
2145         );
2146
2147         wprintf("</SELECT></FORM></TD><TD>\n");
2148         offer_start_page();
2149         wprintf("</TD></TR></TABLE>\n");
2150
2151         /* Display the room list in the user's preferred format */
2152         if (!strcasecmp(listviewpref, "table")) {
2153                 tabular_room_list();
2154         }
2155         else {
2156                 list_all_rooms_by_floor(listviewpref);
2157         }
2158 }