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