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