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