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