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