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