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