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