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