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