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