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