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