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