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