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