48497c9f6885f87bdfaa568380a284837b2425f4
[citadel.git] / webcit / roomops.c
1 /*
2  * $Id$
3  * Lots of different room-related operations.
4  */
5
6 #include "webcit.h"
7 #include "webserver.h"
8 #define MAX_FLOORS 128
9
10 char floorlist[MAX_FLOORS][SIZ];        /* list of our floor names */
11
12 char *viewdefs[9];                      /* the different kinds of available views */
13
14 /* See GetFloorListHash and GetRoomListHash for info on these.
15  * Basically we pull LFLR/LKRA etc. and set up a room HashList with these keys.
16  */
17
18 #define FLOOR_PARAM_LEN 3
19 const ConstStr FLOOR_PARAM_NAMES[] = {{HKEY("ID")},
20                                       {HKEY("NAME")}, 
21                                       {HKEY("ROOMS")}};
22
23 #define ROOM_PARAM_LEN 8
24 const ConstStr ROOM_PARAM_NAMES[] = {{HKEY("NAME")},
25                                      {HKEY("FLAG")},
26                                      {HKEY("FLOOR")},
27                                      {HKEY("LISTORDER")},
28                                      {HKEY("ACL")},
29                                      {HKEY("CURVIEW")},
30                                      {HKEY("DEFVIEW")},
31                                      {HKEY("LASTCHANGE")}};
32
33
34 void display_whok(void);
35
36 /*
37  * Initialize the viewdefs with localized strings
38  */
39 void initialize_viewdefs(void) {
40         viewdefs[0] = _("Bulletin Board");
41         viewdefs[1] = _("Mail Folder");
42         viewdefs[2] = _("Address Book");
43         viewdefs[3] = _("Calendar");
44         viewdefs[4] = _("Task List");
45         viewdefs[5] = _("Notes List");
46         viewdefs[6] = _("Wiki");
47         viewdefs[7] = _("Calendar List");
48         viewdefs[8] = _("Journal");
49 }
50
51 /*
52  * Determine which views are allowed as the default for creating a new room.
53  */
54 int is_view_allowed_as_default(int which_view)
55 {
56         switch(which_view) {
57         case VIEW_BBS:          return(1);
58         case VIEW_MAILBOX:      return(1);
59         case VIEW_ADDRESSBOOK:  return(1);
60         case VIEW_CALENDAR:     return(1);
61         case VIEW_TASKS:        return(1);
62         case VIEW_NOTES:        return(1);
63
64 #ifdef TECH_PREVIEW
65         case VIEW_WIKI:         return(1);
66 #else /* TECH_PREVIEW */
67         case VIEW_WIKI:         return(0);      /* because it isn't finished yet */
68 #endif /* TECH_PREVIEW */
69
70         case VIEW_CALBRIEF:     return(0);
71         case VIEW_JOURNAL:      return(0);
72         default:                return(0);      /* should never get here */
73         }
74 }
75
76
77 /*
78  * load the list of floors
79  */
80 void load_floorlist(StrBuf *Buf)
81 {
82         int a;
83         int Done = 0;
84
85         for (a = 0; a < MAX_FLOORS; ++a)
86                 floorlist[a][0] = 0;
87
88         serv_puts("LFLR");
89         StrBuf_ServGetln(Buf);
90         if (GetServerStatus(Buf, NULL) != 1) {
91                 strcpy(floorlist[0], "Main Floor");
92                 return;
93         }
94         while (!Done && (StrBuf_ServGetln(Buf)>=0)) {
95                 if ( (StrLength(Buf)==3) && 
96                      !strcmp(ChrPtr(Buf), "000")) {
97                         Done = 1;
98                         break;
99                 }
100                 extract_token(floorlist[StrBufExtract_int(Buf, 0, '|')], ChrPtr(Buf), 1, '|', sizeof floorlist[0]);
101         }
102 }
103
104
105 /*
106  * Free a session's march list
107  */
108 void free_march_list(wcsession *wcf)
109 {
110         struct march *mptr;
111
112         while (wcf->march != NULL) {
113                 mptr = wcf->march->next;
114                 free(wcf->march);
115                 wcf->march = mptr;
116         }
117
118 }
119
120
121
122 /*
123  * remove a room from the march list
124  */
125 void remove_march(const StrBuf *aaa)
126 {
127         struct march *mptr, *mptr2;
128
129         if (WC->march == NULL)
130                 return;
131
132         if (!strcasecmp(WC->march->march_name, ChrPtr(aaa))) {
133                 mptr = WC->march->next;
134                 free(WC->march);
135                 WC->march = mptr;
136                 return;
137         }
138         mptr2 = WC->march;
139         for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
140                 if (!strcasecmp(mptr->march_name, ChrPtr(aaa))) {
141                         mptr2->next = mptr->next;
142                         free(mptr);
143                         mptr = mptr2;
144                 } else {
145                         mptr2 = mptr;
146                 }
147         }
148 }
149
150
151
152
153 /*
154  * display rooms in tree structure
155  */
156 void room_tree_list(struct roomlisting *rp)
157 {
158         char rmname[64];
159         int f;
160
161         if (rp == NULL) {
162                 return;
163         }
164
165         room_tree_list(rp->lnext);
166
167         strcpy(rmname, rp->rlname);
168         f = rp->rlflags;
169
170         wprintf("<a href=\"dotgoto?room=");
171         urlescputs(rmname);
172         wprintf("\"");
173         wprintf(">");
174         escputs1(rmname, 1, 1);
175         if ((f & QR_DIRECTORY) && (f & QR_NETWORK))
176                 wprintf("}");
177         else if (f & QR_DIRECTORY)
178                 wprintf("]");
179         else if (f & QR_NETWORK)
180                 wprintf(")");
181         else
182                 wprintf("&gt;");
183         wprintf("</a><tt> </tt>\n");
184
185         room_tree_list(rp->rnext);
186         free(rp);
187 }
188
189
190 /* 
191  * Room ordering stuff (compare first by floor, then by order)
192  */
193 int rordercmp(struct roomlisting *r1, struct roomlisting *r2)
194 {
195         if ((r1 == NULL) && (r2 == NULL))
196                 return (0);
197         if (r1 == NULL)
198                 return (-1);
199         if (r2 == NULL)
200                 return (1);
201         if (r1->rlfloor < r2->rlfloor)
202                 return (-1);
203         if (r1->rlfloor > r2->rlfloor)
204                 return (1);
205         if (r1->rlorder < r2->rlorder)
206                 return (-1);
207         if (r1->rlorder > r2->rlorder)
208                 return (1);
209         return (0);
210 }
211
212
213 /*
214  * Common code for all room listings
215  */
216 void listrms(char *variety)
217 {
218         char buf[SIZ];
219         int num_rooms = 0;
220
221         struct roomlisting *rl = NULL;
222         struct roomlisting *rp;
223         struct roomlisting *rs;
224
225         /* Ask the server for a room list */
226         serv_puts(variety);
227         serv_getln(buf, sizeof buf);
228         if (buf[0] != '1') {
229                 wprintf("&nbsp;");
230                 return;
231         }
232
233         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
234                 ++num_rooms;
235                 rp = malloc(sizeof(struct roomlisting));
236                 extract_token(rp->rlname, buf, 0, '|', sizeof rp->rlname);
237                 rp->rlflags = extract_int(buf, 1);
238                 rp->rlfloor = extract_int(buf, 2);
239                 rp->rlorder = extract_int(buf, 3);
240                 rp->lnext = NULL;
241                 rp->rnext = NULL;
242
243                 rs = rl;
244                 if (rl == NULL) {
245                         rl = rp;
246                 } else
247                         while (rp != NULL) {
248                                 if (rordercmp(rp, rs) < 0) {
249                                         if (rs->lnext == NULL) {
250                                                 rs->lnext = rp;
251                                                 rp = NULL;
252                                         } else {
253                                                 rs = rs->lnext;
254                                         }
255                                 } else {
256                                         if (rs->rnext == NULL) {
257                                                 rs->rnext = rp;
258                                                 rp = NULL;
259                                         } else {
260                                                 rs = rs->rnext;
261                                         }
262                                 }
263                         }
264         }
265
266         room_tree_list(rl);
267
268         /*
269          * If no rooms were listed, print an nbsp to make the cell
270          * borders show up anyway.
271          */
272         if (num_rooms == 0) wprintf("&nbsp;");
273 }
274
275
276 /*
277  * list all forgotten rooms
278  */
279 void zapped_list(void)
280 {
281         WCTemplputParams SubTP;
282         StrBuf *Buf;
283
284         output_headers(1, 1, 1, 0, 0, 0);
285         memset(&SubTP, 0, sizeof(WCTemplputParams));
286         Buf = NewStrBufPlain(_("Zapped (forgotten) rooms"), -1);
287         SubTP.Filter.ContextType = CTX_STRBUF;
288         SubTP.Context = Buf;
289         DoTemplate(HKEY("beginbox"), NULL, &SubTP);
290
291         FreeStrBuf(&Buf);
292
293         listrms("LZRM -1");
294
295         wprintf("<br /><br />\n");
296         wprintf(_("Click on any room to un-zap it and goto that room.\n"));
297         do_template("endbox", NULL);
298         wDumpContent(1);
299 }
300
301
302 /*
303  * read this room's info file (set v to 1 for verbose mode)
304  */
305 void readinfo(StrBuf *Target, WCTemplputParams *TP)
306 {
307         char buf[256];
308         char briefinfo[128];
309         char fullinfo[8192];
310         int fullinfo_len = 0;
311
312         serv_puts("RINF");
313         serv_getln(buf, sizeof buf);
314         if (buf[0] == '1') {
315
316                 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
317                         if (fullinfo_len < (sizeof fullinfo - sizeof buf)) {
318                                 strcpy(&fullinfo[fullinfo_len], buf);
319                                 fullinfo_len += strlen(buf);
320                         }
321                 }
322
323                 safestrncpy(briefinfo, fullinfo, sizeof briefinfo);
324                 strcpy(&briefinfo[50], "...");
325
326                 wprintf("<div class=\"infos\" "
327                         "onclick=\"javascript:Effect.Appear('room_infos', { duration: 0.5 });\" "
328                         ">"
329                 );
330                 escputs(briefinfo);
331                 wprintf("</div><div id=\"room_infos\" style=\"display:none;\">");
332                 wprintf("<img class=\"close_infos\" "
333                         "onclick=\"javascript:Effect.Fade('room_infos', { duration: 0.5 });\" "
334                         "src=\"static/closewindow.gif\" alt=\"%s\"  width=\"16\" height=\"16\">",
335                         _("Close window")
336                 );
337                 escputs(fullinfo);
338                 wprintf("</div>");
339         }
340         else {
341                 wprintf("&nbsp;");
342         }
343 }
344
345
346
347
348 /*
349  * Display room banner icon.  
350  * The server doesn't actually need the room name, but we supply it in
351  * order to keep the browser from using a cached icon from another room.
352  */
353 void embed_room_graphic(StrBuf *Target, WCTemplputParams *TP)
354 {
355         char buf[SIZ];
356
357         serv_puts("OIMG _roompic_");
358         serv_getln(buf, sizeof buf);
359         if (buf[0] == '2') {
360                 wprintf("<img height=\"64px\" src=\"image?name=_roompic_&room=");
361                 urlescputs(ChrPtr(WC->wc_roomname));
362                 wprintf("\">");
363                 serv_puts("CLOS");
364                 serv_getln(buf, sizeof buf);
365         }
366         else if (WC->wc_view == VIEW_ADDRESSBOOK) {
367                 wprintf("<img class=\"roompic\" alt=\"\" src=\""
368                         "static/viewcontacts_48x.gif"
369                         "\" >"
370                         );
371         }
372         else if ( (WC->wc_view == VIEW_CALENDAR) || (WC->wc_view == VIEW_CALBRIEF) ) {
373                 wprintf("<img class=\"roompic\" alt=\"\" src=\""
374                         "static/calarea_48x.gif"
375                         "\" width=\"48\" height=\"48\">"
376                         );
377         }
378         else if (WC->wc_view == VIEW_TASKS) {
379                 wprintf("<img class=\"roompic\" alt=\"\" src=\""
380                         "static/taskmanag_48x.gif"
381                         "\" width=\"48\" height=\"48\">"
382                         );
383         }
384         else if (WC->wc_view == VIEW_NOTES) {
385                 wprintf("<img class=\"roompic\" alt=\"\" src=\""
386                         "static/storenotes_48x.gif"
387                         "\" width=\"48\" height=\"48\">"
388                         );
389         }
390         else if (WC->wc_view == VIEW_MAILBOX) {
391                 wprintf("<img class=\"roompic\" alt=\"\" src=\""
392                         "static/privatemess_48x.gif"
393                         "\" width=\"48\" height=\"48\">"
394                         );
395         }
396         else {
397                 wprintf("<img class=\"roompic\" alt=\"\" src=\""
398                         "static/chatrooms_48x.gif"
399                         "\" width=\"48\" height=\"48\">"
400                         );
401         }
402
403 }
404
405
406
407 /*
408  * Display the current view and offer an option to change it
409  */
410 void embed_view_o_matic(StrBuf *Target, WCTemplputParams *TP)
411 {
412         int i;
413
414         wprintf("<form name=\"viewomatic\" action=\"changeview\">\n");
415         wprintf("\t<div style=\"display: inline;\">\n\t<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
416         wprintf("<label for=\"view_name\">");
417         wprintf(_("View as:"));
418         wprintf("</label> "
419                 "<select name=\"newview\" size=\"1\" "
420                 "id=\"view_name\" class=\"selectbox\" "
421                 "OnChange=\"location.href=viewomatic.newview.options"
422                 "[selectedIndex].value\">\n");
423
424         for (i=0; i<(sizeof viewdefs / sizeof (char *)); ++i) {
425                 /*
426                  * Only offer the views that make sense, given the default
427                  * view for the room.  For example, don't offer a Calendar
428                  * view in a non-Calendar room.
429                  */
430                 if (
431                         (i == WC->wc_view)
432                         ||      (i == WC->wc_default_view)                      /* default */
433                         ||      ( (i == 0) && (WC->wc_default_view == 1) )      /* mail or bulletin */
434                         ||      ( (i == 1) && (WC->wc_default_view == 0) )      /* mail or bulletin */
435                         /* ||   ( (i == 7) && (WC->wc_default_view == 3) )      (calendar list temporarily disabled) */
436                         ) {
437
438                         wprintf("<option %s value=\"changeview?view=%d\">",
439                                 ((i == WC->wc_view) ? "selected" : ""),
440                                 i );
441                         escputs(viewdefs[i]);
442                         wprintf("</option>\n");
443                 }
444         }
445         wprintf("</select></div></form>\n");
446 }
447
448
449 /*
450  * Display a search box
451  */
452 void embed_search_o_matic(StrBuf *Target, WCTemplputParams *TP)
453 {
454         wprintf("<form name=\"searchomatic\" action=\"do_search\">\n");
455         wprintf("<div style=\"display: inline;\"><input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
456         wprintf("<label for=\"srchquery\">");
457         wprintf(_("Search: "));
458         wprintf("</label><input ");
459         wprintf("%s", WC->serv_info->serv_fulltext_enabled ? "" : "disabled ");
460         wprintf("type=\"text\" name=\"query\" id=\"srchquery\" size=\"15\" maxlength=\"128\" class=\"inputbox\">\n"
461                 );
462         wprintf("</div></form>\n");
463 }
464
465
466 /*
467  * Embed the room banner
468  *
469  * got                  The information returned from a GOTO server command
470  * navbar_style         Determines which navigation buttons to display
471  *
472  */
473
474 void embed_room_banner(char *got, int navbar_style) {
475         wcsession *WCC = WC;
476         char buf[256];
477         char buf2[1024];
478         char with_files[256];
479         int file_count=0;
480         
481         /*
482          * We need to have the information returned by a GOTO server command.
483          * If it isn't supplied, we fake it by issuing our own GOTO.
484          */
485         if (got == NULL) {
486                 memset(buf, '0', 20);
487                 buf[20] = '\0';
488                 serv_printf("GOTO %s", ChrPtr(WC->wc_roomname));
489                 serv_getln(buf, sizeof buf);
490                 got = buf;
491         }
492
493         /* The browser needs some information for its own use */
494         wprintf("<script type=\"text/javascript\">      \n"
495                 "       room_is_trash = %d;             \n"
496                 "</script>\n",
497                 WC->wc_is_trash
498         );
499
500         /*
501          * If the user happens to select the "make this my start page" link,
502          * we want it to remember the URL as a "/dotskip" one instead of
503          * a "skip" or "gotonext" or something like that.
504          */
505         if (WCC->Hdr->this_page == NULL) {
506                 WCC->Hdr->this_page = NewStrBuf();
507         }
508         StrBufPrintf(WCC->Hdr->this_page, 
509                      "dotskip?room=%s",
510                      ChrPtr(WC->wc_roomname)
511         );
512
513         /* Check for new mail. */
514         WC->new_mail = extract_int(&got[4], 9);
515         WC->wc_view = extract_int(&got[4], 11);
516
517         /* Is this a directory room and does it contain files and how many? */
518         if ((WC->room_flags & QR_DIRECTORY) && (WC->room_flags & QR_VISDIR))
519         {
520                 serv_puts("RDIR");
521                 serv_getln(buf2, sizeof buf2);
522                 if (buf2[0] == '1') while (serv_getln(buf2, sizeof buf2), strcmp(buf2, "000"))
523                                             file_count++;
524                 snprintf (with_files, sizeof with_files, 
525                           "; <a href=\"do_template?template=files\"> %d %s </a>", 
526                           file_count, 
527                           ((file_count>1) || (file_count == 0)  ? _("files") : _("file")));
528         }
529         else
530                 strcpy (with_files, "");
531         
532         svprintf(HKEY("NUMMSGS"), WCS_STRING,
533                  _("%d new of %d messages%s"),
534                  extract_int(&got[4], 1),
535                  extract_int(&got[4], 2),
536                  with_files
537                 );
538         svcallback("ROOMPIC", embed_room_graphic);
539         svcallback("ROOMINFO", readinfo);
540         svcallback("VIEWOMATIC", embed_view_o_matic); 
541         svcallback("SEARCHOMATIC", embed_search_o_matic);
542         svcallback("START", offer_start_page); 
543  
544         do_template("roombanner", NULL);
545         /* roombanner contains this for mobile */
546         if (navbar_style != navbar_none && !WC->is_mobile) { 
547
548                 wprintf("<div id=\"navbar\"><ul>");
549
550                 if (navbar_style == navbar_default) wprintf(
551                         "<li class=\"ungoto\">"
552                         "<a href=\"ungoto\">"
553                         "<img src=\"static/ungoto2_24x.gif\" alt=\"\" width=\"24\" height=\"24\">"
554                         "<span class=\"navbar_link\">%s</span></A>"
555                         "</li>\n", _("Ungoto")
556                         );
557
558                 if ( (navbar_style == navbar_default) && (WC->wc_view == VIEW_BBS) ) {
559                         wprintf(
560                                 "<li class=\"newmess\">"
561                                 "<a href=\"readnew\">"
562                                 "<img src=\"static/newmess2_24x.gif\" alt=\"\" width=\"24\" height=\"24\">"
563                                 "<span class=\"navbar_link\">%s</span></A>"
564                                 "</li>\n", _("Read new messages")
565                                 );
566                 }
567
568                 if (navbar_style == navbar_default) {
569                         switch(WC->wc_view) {
570                         case VIEW_ADDRESSBOOK:
571                                 wprintf(
572                                         "<li class=\"viewcontacts\">"
573                                         "<a href=\"readfwd\">"
574                                         "<img src=\"static/viewcontacts_24x.gif\" "
575                                         "alt=\"\" width=\"24\" height=\"24\">"
576                                         "<span class=\"navbar_link\">"
577                                         "%s"
578                                         "</span></a></li>\n", _("View contacts")
579                                         );
580                                 break;
581                         case VIEW_CALENDAR:
582                                 wprintf(
583                                         "<li class=\"staskday\">"
584                                         "<a href=\"readfwd?calview=day\">"
585                                         "<img src=\"static/taskday2_24x.gif\" "
586                                         "alt=\"\" width=\"24\" height=\"24\">"
587                                         "<span class=\"navbar_link\">"
588                                         "%s"
589                                         "</span></a></li>\n", _("Day view")
590                                         );
591                                 wprintf(
592                                         "<li class=\"monthview\">"
593                                         "<a href=\"readfwd?calview=month\">"
594                                         "<img src=\"static/monthview2_24x.gif\" "
595                                         "alt=\"\" width=\"24\" height=\"24\">"
596                                         "<span class=\"navbar_link\">"
597                                         "%s"
598                                         "</span></a></li>\n", _("Month view")
599                                         );
600                                 break;
601                         case VIEW_CALBRIEF:
602                                 wprintf(
603                                         "<li class=\"monthview\">"
604                                         "<a href=\"readfwd?calview=month\">"
605                                         "<img src=\"static/monthview2_24x.gif\" "
606                                         "alt=\"\" width=\"24\" height=\"24\">"
607                                         "<span class=\"navbar_link\">"
608                                         "%s"
609                                         "</span></a></li>\n", _("Calendar list")
610                                         );
611                                 break;
612                         case VIEW_TASKS:
613                                 wprintf(
614                                         "<li class=\"taskmanag\">"
615                                         "<a href=\"readfwd\">"
616                                         "<img src=\"static/taskmanag_24x.gif\" "
617                                         "alt=\"\" width=\"24\" height=\"24\">"
618                                         "<span class=\"navbar_link\">"
619                                         "%s"
620                                         "</span></a></li>\n", _("View tasks")
621                                         );
622                                 break;
623                         case VIEW_NOTES:
624                                 wprintf(
625                                         "<li class=\"viewnotes\">"
626                                         "<a href=\"readfwd\">"
627                                         "<img src=\"static/viewnotes_24x.gif\" "
628                                         "alt=\"\" width=\"24\" height=\"24\">"
629                                         "<span class=\"navbar_link\">"
630                                         "%s"
631                                         "</span></a></li>\n", _("View notes")
632                                         );
633                                 break;
634                         case VIEW_MAILBOX:
635                                 wprintf(
636                                         "<li class=\"readallmess\">"
637                                         "<a id=\"m_refresh\" href=\"readfwd\">"
638                                         "<img src=\"static/readallmess3_24x.gif\" "
639                                         "alt=\"\" width=\"24\" height=\"24\">"
640                                         "<span class=\"navbar_link\">"
641                                         "%s"
642                                         "</span></a></li>\n", _("Refresh message list")
643                                         );
644                                 break;
645                         case VIEW_WIKI:
646                                 wprintf(
647                                         "<li class=\"readallmess\">"
648                                         "<a href=\"readfwd\">"
649                                         "<img src=\"static/readallmess3_24x.gif\" "
650                                         "alt=\"\" width=\"24\" height=\"24\">"
651                                         "<span class=\"navbar_link\">"
652                                         "%s"
653                                         "</span></a></li>\n", _("Wiki home")
654                                         );
655                                 break;
656                         default:
657                                 wprintf(
658                                         "<li class=\"readallmess\">"
659                                         "<a href=\"readfwd\">"
660                                         "<img src=\"static/readallmess3_24x.gif\" "
661                                         "alt=\"\" width=\"24\" height=\"24\">"
662                                         "<span class=\"navbar_link\">"
663                                         "%s"
664                                         "</span></a></li>\n", _("Read all messages")
665                                         );
666                                 break;
667                         }
668                 }
669
670                 if (navbar_style == navbar_default) {
671                         switch(WC->wc_view) {
672                         case VIEW_ADDRESSBOOK:
673                                 wprintf(
674                                         "<li class=\"addnewcontact\">"
675                                         "<a href=\"display_enter\">"
676                                         "<img src=\"static/addnewcontact_24x.gif\" "
677                                         "alt=\"\" width=\"24\" height=\"24\">"
678                                         "<span class=\"navbar_link\">"
679                                         "%s"
680                                         "</span></a></li>\n", _("Add new contact")
681                                         );
682                                 break;
683                         case VIEW_CALENDAR:
684                         case VIEW_CALBRIEF:
685                                 wprintf("<li class=\"addevent\"><a href=\"display_enter");
686                                 if (havebstr("year" )) wprintf("?year=%s", bstr("year"));
687                                 if (havebstr("month")) wprintf("?month=%s", bstr("month"));
688                                 if (havebstr("day"  )) wprintf("?day=%s", bstr("day"));
689                                 wprintf("\">"
690                                         "<img  src=\"static/addevent_24x.gif\" "
691                                         "alt=\"\" width=\"24\" height=\"24\">"
692                                         "<span class=\"navbar_link\">"
693                                         "%s"
694                                         "</span></a></li>\n", _("Add new event")
695                                         );
696                                 break;
697                         case VIEW_TASKS:
698                                 wprintf(
699                                         "<li class=\"newmess\">"
700                                         "<a href=\"display_enter\">"
701                                         "<img  src=\"static/newmess3_24x.gif\" "
702                                         "alt=\"\" width=\"24\" height=\"24\">"
703                                         "<span class=\"navbar_link\">"
704                                         "%s"
705                                         "</span></a></li>\n", _("Add new task")
706                                         );
707                                 break;
708                         case VIEW_NOTES:
709                                 wprintf(
710                                         "<li class=\"enternewnote\">"
711                                         "<a href=\"add_new_note\">"
712                                         "<img  src=\"static/enternewnote_24x.gif\" "
713                                         "alt=\"\" width=\"24\" height=\"24\">"
714                                         "<span class=\"navbar_link\">"
715                                         "%s"
716                                         "</span></a></li>\n", _("Add new note")
717                                         );
718                                 break;
719                         case VIEW_WIKI:
720                                 safestrncpy(buf, bstr("page"), sizeof buf);
721                                 str_wiki_index(buf);
722                                 wprintf(
723                                         "<li class=\"newmess\">"
724                                         "<a href=\"display_enter?wikipage=%s\">"
725                                         "<img  src=\"static/newmess3_24x.gif\" "
726                                         "alt=\"\" width=\"24\" height=\"24\">"
727                                         "<span class=\"navbar_link\">"
728                                         "%s"
729                                         "</span></a></li>\n", buf, _("Edit this page")
730                                         );
731                                 break;
732                         case VIEW_MAILBOX:
733                                 wprintf(
734                                         "<li class=\"newmess\">"
735                                         "<a href=\"display_enter\">"
736                                         "<img  src=\"static/newmess3_24x.gif\" "
737                                         "alt=\"\" width=\"24\" height=\"24\">"
738                                         "<span class=\"navbar_link\">"
739                                         "%s"
740                                         "</span></a></li>\n", _("Write mail")
741                                         );
742                                 wprintf(
743                                         "<li class=\"newmess\">"
744                                         "<a href=\"javascript:deleteAllSelectedMessages();\">"
745                                         "<img  src=\"static/delete.gif\" "
746                                         "alt=\"\" width=\"24\" height=\"24\"><span class=\"navbar_link\">"
747                                         "%s"
748                                         "</span></a></li>\n", _("Delete")
749                                         );
750                                 break;
751                         default:
752                                 wprintf(
753                                         "<li class=\"newmess\">"
754                                         "<a href=\"display_enter\">"
755                                         "<img  src=\"static/newmess3_24x.gif\" "
756                                         "alt=\"\" width=\"24\" height=\"24\">"
757                                         "<span class=\"navbar_link\">"
758                                         "%s"
759                                         "</span></a></li>\n", _("Enter a message")
760                                         );
761                                 break;
762                         }
763                 }
764
765                 if (navbar_style == navbar_default) wprintf(
766                         "<li class=\"skipthisroom\">"
767                         "<a href=\"skip\" "
768                         "title=\"%s\">"
769                         "<img  src=\"static/skipthisroom_24x.gif\" alt=\"\" "
770                         "width=\"24\" height=\"24\">"
771                         "<span class=\"navbar_link\">%s</span></a>"
772                         "</li>\n",
773                         _("Leave all messages marked as unread, go to next room with unread messages"),
774                         _("Skip this room")
775                         );
776
777                 if (navbar_style == navbar_default) wprintf(
778                         "<li class=\"markngo\">"
779                         "<a href=\"gotonext\" "
780                         "title=\"%s\">"
781                         "<img  src=\"static/markngo_24x.gif\" alt=\"\" "
782                         "width=\"24\" height=\"24\">"
783                         "<span class=\"navbar_link\">%s</span></a>"
784                         "</li>\n",
785                         _("Mark all messages as read, go to next room with unread messages"),
786                         _("Goto next room")
787                         );
788
789                 wprintf("</ul></div>\n");
790         }
791
792 }
793
794
795 /*
796  * back end routine to take the session to a new room
797  */
798 long gotoroom(const StrBuf *gname)
799 {
800         StrBuf *Buf;
801         static long ls = (-1L);
802         long err = 0;
803
804         /* store ungoto information */
805         strcpy(WC->ugname, ChrPtr(WC->wc_roomname));
806         WC->uglsn = ls;
807         Buf = NewStrBuf();
808
809         /* move to the new room */
810         serv_printf("GOTO %s", ChrPtr(gname));
811         StrBuf_ServGetln(Buf);
812         if  (GetServerStatus(Buf, &err) != 2) {
813                 serv_puts("GOTO _BASEROOM_");
814                 StrBuf_ServGetln(Buf);
815                 /* 
816                  * well, we know that this is the fallback case, 
817                  * but we're interested that the first command 
818                  * didn't work out in first place.
819                  */
820                 if (GetServerStatus(Buf, NULL) != 2) {
821                         FreeStrBuf(&Buf);
822                         return err;
823                 }
824         }
825
826         if (WC->wc_roomname == NULL)
827                 WC->wc_roomname = NewStrBuf();
828         else
829                 FlushStrBuf(WC->wc_roomname);
830
831         StrBufExtract_token(WC->wc_roomname, Buf, 0, '|');
832         StrBufCutLeft(WC->wc_roomname, 4);
833         WC->room_flags = StrBufExtract_int(Buf, 4, '|');
834         /* highest_msg_read = extract_int(&buf[4],6);
835            maxmsgnum = extract_int(&buf[4],5);
836         */
837         WC->is_mailbox = StrBufExtract_int(Buf, 7, '|');   
838         ls = StrBufExtract_long(Buf, 6, '|');
839         WC->wc_floor = StrBufExtract_int(Buf, 10, '|');
840         WC->wc_view = StrBufExtract_int(Buf, 11, '|');
841         WC->wc_default_view = StrBufExtract_int(Buf, 12, '|');
842         WC->wc_is_trash = StrBufExtract_int(Buf, 13, '|');
843         WC->room_flags2 = StrBufExtract_int(Buf, 14, '|');
844
845         if (WC->is_aide)
846                 WC->is_room_aide = WC->is_aide;
847         else
848                 WC->is_room_aide = (char) StrBufExtract_int(Buf, 8, '|');
849
850         remove_march(WC->wc_roomname);
851         if (!strcasecmp(ChrPtr(gname), "_BASEROOM_"))
852                 remove_march(gname);
853         FreeStrBuf(&Buf);
854
855         return err;
856 }
857
858
859 /**
860  * \brief Locate the room on the march list which we most want to go to.  
861  * Each room
862  * is measured given a "weight" of preference based on various factors.
863  * \param desired_floor the room number on the citadel server
864  * \return the roomname
865  */
866 char *pop_march(int desired_floor)
867 {
868         static char TheRoom[128];
869         int TheFloor = 0;
870         int TheOrder = 32767;
871         int TheWeight = 0;
872         int weight;
873         struct march *mptr = NULL;
874
875         strcpy(TheRoom, "_BASEROOM_");
876         if (WC->march == NULL)
877                 return (TheRoom);
878
879         for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
880                 weight = 0;
881                 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
882                         weight = weight + 10000;
883                 if (mptr->march_floor == desired_floor)
884                         weight = weight + 5000;
885
886                 weight = weight + ((128 - (mptr->march_floor)) * 128);
887                 weight = weight + (128 - (mptr->march_order));
888
889                 if (weight > TheWeight) {
890                         TheWeight = weight;
891                         strcpy(TheRoom, mptr->march_name);
892                         TheFloor = mptr->march_floor;
893                         TheOrder = mptr->march_order;
894                 }
895         }
896         return (TheRoom);
897 }
898
899
900
901 /*
902  * Goto next room having unread messages.
903  *
904  * We want to skip over rooms that the user has already been to, and take the
905  * user back to the lobby when done.  The room we end up in is placed in
906  * newroom - which is set to 0 (the lobby) initially.
907  * We start the search in the current room rather than the beginning to prevent
908  * two or more concurrent users from dragging each other back to the same room.
909  */
910 void gotonext(void)
911 {
912         char buf[256];
913         struct march *mptr = NULL;
914         struct march *mptr2 = NULL;
915         char room_name[128];
916         StrBuf *next_room;
917         int ELoop = 0;
918
919         /*
920          * First check to see if the march-mode list is already allocated.
921          * If it is, pop the first room off the list and go there.
922          */
923         if (havebstr("startmsg")) {
924                  readloop(readnew);
925                  return;
926         }
927
928         if (WC->march == NULL) {
929                 serv_puts("LKRN");
930                 serv_getln(buf, sizeof buf);
931                 if (buf[0] == '1')
932                         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
933                                 if (IsEmptyStr(buf)) {
934                                         if (ELoop > 10000)
935                                                 return;
936                                         if (ELoop % 100 == 0)
937                                                 sleeeeeeeeeep(1);
938                                         ELoop ++;
939                                         continue;                                       
940                                 }
941                                 extract_token(room_name, buf, 0, '|', sizeof room_name);
942                                 if (strcasecmp(room_name, ChrPtr(WC->wc_roomname))) {
943                                         mptr = (struct march *) malloc(sizeof(struct march));
944                                         mptr->next = NULL;
945                                         safestrncpy(mptr->march_name, room_name, sizeof mptr->march_name);
946                                         mptr->march_floor = extract_int(buf, 2);
947                                         mptr->march_order = extract_int(buf, 3);
948                                         if (WC->march == NULL) 
949                                                 WC->march = mptr;
950                                         else 
951                                                 mptr2->next = mptr;
952                                         mptr2 = mptr;
953                                 }
954                                 buf[0] = '\0';
955                         }
956                 /*
957                  * add _BASEROOM_ to the end of the march list, so the user will end up
958                  * in the system base room (usually the Lobby>) at the end of the loop
959                  */
960                 mptr = (struct march *) malloc(sizeof(struct march));
961                 mptr->next = NULL;
962                 mptr->march_order = 0;
963                 mptr->march_floor = 0;
964                 strcpy(mptr->march_name, "_BASEROOM_");
965                 if (WC->march == NULL) {
966                         WC->march = mptr;
967                 } else {
968                         mptr2 = WC->march;
969                         while (mptr2->next != NULL)
970                                 mptr2 = mptr2->next;
971                         mptr2->next = mptr;
972                 }
973                 /*
974                  * ...and remove the room we're currently in, so a <G>oto doesn't make us
975                  * walk around in circles
976                  */
977                 remove_march(WC->wc_roomname);
978         }
979         if (WC->march != NULL) {
980                 next_room = NewStrBufPlain(pop_march(-1), -1);/*TODO: migrate march to strbuf */
981         } else {
982                 next_room = NewStrBufPlain(HKEY("_BASEROOM_"));
983         }
984
985
986         smart_goto(next_room);
987         FreeStrBuf(&next_room);
988 }
989
990
991 /*
992  * goto next room
993  */
994 void smart_goto(const StrBuf *next_room) {
995         gotoroom(next_room);
996         readloop(readnew);
997 }
998
999
1000
1001 /*
1002  * mark all messages in current room as having been read
1003  */
1004 void slrp_highest(void)
1005 {
1006         char buf[256];
1007
1008         serv_puts("SLRP HIGHEST");
1009         serv_getln(buf, sizeof buf);
1010 }
1011
1012
1013 /*
1014  * un-goto the previous room
1015  */
1016 void ungoto(void)
1017 {
1018         StrBuf *Buf;
1019
1020         if (havebstr("startmsg")) {
1021                 readloop(readnew);
1022                 return;
1023         }
1024
1025         if (!strcmp(WC->ugname, "")) {
1026                 smart_goto(WC->wc_roomname);
1027                 return;
1028         }
1029         serv_printf("GOTO %s", WC->ugname);
1030         Buf = NewStrBuf();
1031         StrBuf_ServGetln(Buf);
1032         if (GetServerStatus(Buf, NULL) != 2) {
1033                 smart_goto(WC->wc_roomname);
1034                 FreeStrBuf(&Buf);
1035                 return;
1036         }
1037         if (WC->uglsn >= 0L) {
1038                 serv_printf("SLRP %ld", WC->uglsn);
1039                 StrBuf_ServGetln(Buf);
1040         }
1041         FlushStrBuf(Buf);
1042         StrBufAppendBufPlain(Buf, WC->ugname, -1, 0);
1043         strcpy(WC->ugname, "");
1044         smart_goto(Buf);
1045         FreeStrBuf(&Buf);
1046 }
1047
1048 typedef struct __room_states {
1049         char password[SIZ];
1050         char dirname[SIZ];
1051         char name[SIZ];
1052         int flags;
1053         int floor;
1054         int order;
1055         int view;
1056         int flags2;
1057 } room_states;
1058
1059
1060
1061
1062 /*
1063  * Set/clear/read the "self-service list subscribe" flag for a room
1064  * 
1065  * set newval to 0 to clear, 1 to set, any other value to leave unchanged.
1066  * returns the new value.
1067  */
1068
1069 int self_service(int newval) {
1070         int current_value = 0;
1071         char buf[SIZ];
1072         
1073         char name[SIZ];
1074         char password[SIZ];
1075         char dirname[SIZ];
1076         int flags, floor, order, view, flags2;
1077
1078         serv_puts("GETR");
1079         serv_getln(buf, sizeof buf);
1080         if (buf[0] != '2') return(0);
1081
1082         extract_token(name, &buf[4], 0, '|', sizeof name);
1083         extract_token(password, &buf[4], 1, '|', sizeof password);
1084         extract_token(dirname, &buf[4], 2, '|', sizeof dirname);
1085         flags = extract_int(&buf[4], 3);
1086         floor = extract_int(&buf[4], 4);
1087         order = extract_int(&buf[4], 5);
1088         view = extract_int(&buf[4], 6);
1089         flags2 = extract_int(&buf[4], 7);
1090
1091         if (flags2 & QR2_SELFLIST) {
1092                 current_value = 1;
1093         }
1094         else {
1095                 current_value = 0;
1096         }
1097
1098         if (newval == 1) {
1099                 flags2 = flags2 | QR2_SELFLIST;
1100         }
1101         else if (newval == 0) {
1102                 flags2 = flags2 & ~QR2_SELFLIST;
1103         }
1104         else {
1105                 return(current_value);
1106         }
1107
1108         if (newval != current_value) {
1109                 serv_printf("SETR %s|%s|%s|%d|0|%d|%d|%d|%d",
1110                             name, password, dirname, flags,
1111                             floor, order, view, flags2);
1112                 serv_getln(buf, sizeof buf);
1113         }
1114
1115         return(newval);
1116
1117 }
1118
1119 int is_selflist(room_states *RoomFlags)
1120 {
1121         return ((RoomFlags->flags2 & QR2_SELFLIST) != 0);
1122 }
1123
1124 int is_publiclist(room_states *RoomFlags)
1125 {
1126         return ((RoomFlags->flags2 & QR2_SMTP_PUBLIC) != 0);
1127 }
1128
1129 int is_moderatedlist(room_states *RoomFlags)
1130 {
1131         return ((RoomFlags->flags2 & QR2_MODERATED) != 0);
1132 }
1133
1134 /*
1135  * Set/clear/read the "self-service list subscribe" flag for a room
1136  * 
1137  * set newval to 0 to clear, 1 to set, any other value to leave unchanged.
1138  * returns the new value.
1139  */
1140
1141 int get_roomflags(room_states *RoomOps) 
1142 {
1143         char buf[SIZ];
1144         
1145         serv_puts("GETR");
1146         serv_getln(buf, sizeof buf);
1147         if (buf[0] != '2') return(0);
1148
1149         extract_token(RoomOps->name, &buf[4], 0, '|', sizeof RoomOps->name);
1150         extract_token(RoomOps->password, &buf[4], 1, '|', sizeof RoomOps->password);
1151         extract_token(RoomOps->dirname, &buf[4], 2, '|', sizeof RoomOps->dirname);
1152         RoomOps->flags = extract_int(&buf[4], 3);
1153         RoomOps->floor = extract_int(&buf[4], 4);
1154         RoomOps->order = extract_int(&buf[4], 5);
1155         RoomOps->view = extract_int(&buf[4], 6);
1156         RoomOps->flags2 = extract_int(&buf[4], 7);
1157         return (1);
1158 }
1159
1160 int set_roomflags(room_states *RoomOps)
1161 {
1162         char buf[SIZ];
1163
1164         serv_printf("SETR %s|%s|%s|%d|0|%d|%d|%d|%d",
1165                     RoomOps->name, 
1166                     RoomOps->password, 
1167                     RoomOps->dirname, 
1168                     RoomOps->flags,
1169                     RoomOps->floor, 
1170                     RoomOps->order, 
1171                     RoomOps->view, 
1172                     RoomOps->flags2);
1173         serv_getln(buf, sizeof buf);
1174         return (1);
1175 }
1176
1177
1178
1179
1180
1181
1182 /*
1183  * display the form for editing a room
1184  */
1185 void display_editroom(void)
1186 {
1187         StrBuf *Buf;
1188         char buf[SIZ];
1189         char cmd[1024];
1190         char node[256];
1191         char remote_room[128];
1192         char recp[1024];
1193         char er_name[128];
1194         char er_password[10];
1195         char er_dirname[15];
1196         char er_roomaide[26];
1197         unsigned er_flags;
1198         unsigned er_flags2;
1199         int er_floor;
1200         int i, j;
1201         char *tab;
1202         char *shared_with;
1203         char *not_shared_with;
1204         int roompolicy = 0;
1205         int roomvalue = 0;
1206         int floorpolicy = 0;
1207         int floorvalue = 0;
1208         char pop3_host[128];
1209         char pop3_user[32];
1210         int bg = 0;
1211
1212         tab = bstr("tab");
1213         if (IsEmptyStr(tab)) tab = "admin";
1214
1215         Buf = NewStrBuf();
1216         load_floorlist(Buf);
1217         FreeStrBuf(&Buf);
1218         output_headers(1, 1, 1, 0, 0, 0);
1219
1220         wprintf("<div class=\"fix_scrollbar_bug\">");
1221
1222         wprintf("<br />\n");
1223
1224         /* print the tabbed dialog */
1225         wprintf("<div align=\"center\">");
1226         wprintf("<table id=\"AdminTabs\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"
1227                 "<tr align=\"center\" style=\"cursor:pointer\"><td>&nbsp;</td>"
1228                 );
1229
1230         wprintf("<td class=\"");
1231         if (!strcmp(tab, "admin")) {
1232                 wprintf(" tab_cell_label\">");
1233                 wprintf(_("Administration"));
1234         }
1235         else {
1236                 wprintf("< tab_cell_edit\"><a href=\"display_editroom?tab=admin\">");
1237                 wprintf(_("Administration"));
1238                 wprintf("</a>");
1239         }
1240         wprintf("</td>\n");
1241         wprintf("<td>&nbsp;</td>\n");
1242
1243         if ( (WC->axlevel >= 6) || (WC->is_room_aide) ) {
1244
1245                 wprintf("<td class=\"");
1246                 if (!strcmp(tab, "config")) {
1247                         wprintf(" tab_cell_label\">");
1248                         wprintf(_("Configuration"));
1249                 }
1250                 else {
1251                         wprintf(" tab_cell_edit\"><a href=\"display_editroom?tab=config\">");
1252                         wprintf(_("Configuration"));
1253                         wprintf("</a>");
1254                 }
1255                 wprintf("</td>\n");
1256                 wprintf("<td>&nbsp;</td>\n");
1257
1258                 wprintf("<td class=\"");
1259                 if (!strcmp(tab, "expire")) {
1260                         wprintf(" tab_cell_label\">");
1261                         wprintf(_("Message expire policy"));
1262                 }
1263                 else {
1264                         wprintf(" tab_cell_edit\"><a href=\"display_editroom?tab=expire\">");
1265                         wprintf(_("Message expire policy"));
1266                         wprintf("</a>");
1267                 }
1268                 wprintf("</td>\n");
1269                 wprintf("<td>&nbsp;</td>\n");
1270         
1271                 wprintf("<td class=\"");
1272                 if (!strcmp(tab, "access")) {
1273                         wprintf(" tab_cell_label\">");
1274                         wprintf(_("Access controls"));
1275                 }
1276                 else {
1277                         wprintf(" tab_cell_edit\"><a href=\"display_editroom?tab=access\">");
1278                         wprintf(_("Access controls"));
1279                         wprintf("</a>");
1280                 }
1281                 wprintf("</td>\n");
1282                 wprintf("<td>&nbsp;</td>\n");
1283
1284                 wprintf("<td class=\"");
1285                 if (!strcmp(tab, "sharing")) {
1286                         wprintf(" tab_cell_label\">");
1287                         wprintf(_("Sharing"));
1288                 }
1289                 else {
1290                         wprintf(" tab_cell_edit\"><a href=\"display_editroom?tab=sharing\">");
1291                         wprintf(_("Sharing"));
1292                         wprintf("</a>");
1293                 }
1294                 wprintf("</td>\n");
1295                 wprintf("<td>&nbsp;</td>\n");
1296
1297                 wprintf("<td class=\"");
1298                 if (!strcmp(tab, "listserv")) {
1299                         wprintf(" tab_cell_label\">");
1300                         wprintf(_("Mailing list service"));
1301                 }
1302                 else {
1303                         wprintf("< tab_cell_edit\"><a href=\"display_editroom?tab=listserv\">");
1304                         wprintf(_("Mailing list service"));
1305                         wprintf("</a>");
1306                 }
1307                 wprintf("</td>\n");
1308                 wprintf("<td>&nbsp;</td>\n");
1309
1310         }
1311
1312         wprintf("<td class=\"");
1313         if (!strcmp(tab, "feeds")) {
1314                 wprintf(" tab_cell_label\">");
1315                 wprintf(_("Remote retrieval"));
1316         }
1317         else {
1318                 wprintf("< tab_cell_edit\"><a href=\"display_editroom?tab=feeds\">");
1319                 wprintf(_("Remote retrieval"));
1320                 wprintf("</a>");
1321         }
1322         wprintf("</td>\n");
1323         wprintf("<td>&nbsp;</td>\n");
1324
1325         wprintf("</tr></table>\n");
1326         wprintf("</div>\n");
1327         /* end tabbed dialog */ 
1328
1329         wprintf("<script type=\"text/javascript\">"
1330                 " Nifty(\"table#AdminTabs td\", \"small transparent top\");"
1331                 "</script>"
1332                 );
1333
1334         /* begin content of whatever tab is open now */
1335
1336         if (!strcmp(tab, "admin")) {
1337                 wprintf("<div class=\"tabcontent\">");
1338                 wprintf("<ul>"
1339                         "<li><a href=\"delete_room\" "
1340                         "onClick=\"return confirm('");
1341                 wprintf(_("Are you sure you want to delete this room?"));
1342                 wprintf("');\">\n");
1343                 wprintf(_("Delete this room"));
1344                 wprintf("</a>\n"
1345                         "<li><a href=\"display_editroompic?which_room=");
1346                 urlescputs(ChrPtr(WC->wc_roomname));
1347                 wprintf("\">\n");
1348                 wprintf(_("Set or change the icon for this room's banner"));
1349                 wprintf("</a>\n"
1350                         "<li><a href=\"display_editinfo\">\n");
1351                 wprintf(_("Edit this room's Info file"));
1352                 wprintf("</a>\n"
1353                         "</ul>");
1354                 wprintf("</div>");
1355         }
1356
1357         if (!strcmp(tab, "config")) {
1358                 wprintf("<div class=\"tabcontent\">");
1359                 serv_puts("GETR");
1360                 serv_getln(buf, sizeof buf);
1361
1362                 if (!strncmp(buf, "550", 3)) {
1363                         wprintf("<br><br><div align=center>%s</div><br><br>\n",
1364                                 _("Higher access is required to access this function.")
1365                                 );
1366                 }
1367                 else if (buf[0] != '2') {
1368                         wprintf("<br><br><div align=center>%s</div><br><br>\n", &buf[4]);
1369                 }
1370                 else {
1371                         extract_token(er_name, &buf[4], 0, '|', sizeof er_name);
1372                         extract_token(er_password, &buf[4], 1, '|', sizeof er_password);
1373                         extract_token(er_dirname, &buf[4], 2, '|', sizeof er_dirname);
1374                         er_flags = extract_int(&buf[4], 3);
1375                         er_floor = extract_int(&buf[4], 4);
1376                         er_flags2 = extract_int(&buf[4], 7);
1377         
1378                         wprintf("<form method=\"POST\" action=\"editroom\">\n");
1379                         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1380                 
1381                         wprintf("<ul><li>");
1382                         wprintf(_("Name of room: "));
1383                         wprintf("<input type=\"text\" NAME=\"er_name\" VALUE=\"%s\" MAXLENGTH=\"%d\">\n",
1384                                 er_name,
1385                                 (sizeof(er_name)-1)
1386                                 );
1387                 
1388                         wprintf("<li>");
1389                         wprintf(_("Resides on floor: "));
1390                         wprintf("<select NAME=\"er_floor\" SIZE=\"1\"");
1391                         if (er_flags & QR_MAILBOX)
1392                                 wprintf("disabled >\n");
1393                         for (i = 0; i < 128; ++i)
1394                                 if (!IsEmptyStr(floorlist[i])) {
1395                                         wprintf("<OPTION ");
1396                                         if (i == er_floor )
1397                                                 wprintf("SELECTED ");
1398                                         wprintf("VALUE=\"%d\">", i);
1399                                         escputs(floorlist[i]);
1400                                         wprintf("</OPTION>\n");
1401                                 }
1402                         wprintf("</select>\n");
1403
1404                         wprintf("<li>");
1405                         wprintf(_("Type of room:"));
1406                         wprintf("<ul>\n");
1407         
1408                         wprintf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"public\" ");
1409                         if ((er_flags & (QR_PRIVATE + QR_MAILBOX)) == 0)
1410                                 wprintf("CHECKED ");
1411                         wprintf("OnChange=\""
1412                                 "       if (this.form.type[0].checked == true) {        "
1413                                 "               this.form.er_floor.disabled = false;    "
1414                                 "       }                                               "
1415                                 "\"> ");
1416                         wprintf(_("Public (automatically appears to everyone)"));
1417                         wprintf("\n");
1418         
1419                         wprintf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"hidden\" ");
1420                         if ((er_flags & QR_PRIVATE) &&
1421                             (er_flags & QR_GUESSNAME))
1422                                 wprintf("CHECKED ");
1423                         wprintf(" OnChange=\""
1424                                 "       if (this.form.type[1].checked == true) {        "
1425                                 "               this.form.er_floor.disabled = false;    "
1426                                 "       }                                               "
1427                                 "\"> ");
1428                         wprintf(_("Private - hidden (accessible to anyone who knows its name)"));
1429                 
1430                         wprintf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
1431                         if ((er_flags & QR_PRIVATE) &&
1432                             (er_flags & QR_PASSWORDED))
1433                                 wprintf("CHECKED ");
1434                         wprintf(" OnChange=\""
1435                                 "       if (this.form.type[2].checked == true) {        "
1436                                 "               this.form.er_floor.disabled = false;    "
1437                                 "       }                                               "
1438                                 "\"> ");
1439                         wprintf(_("Private - require password: "));
1440                         wprintf("\n<input type=\"text\" NAME=\"er_password\" VALUE=\"%s\" MAXLENGTH=\"9\">\n",
1441                                 er_password);
1442                 
1443                         wprintf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
1444                         if ((er_flags & QR_PRIVATE)
1445                             && ((er_flags & QR_GUESSNAME) == 0)
1446                             && ((er_flags & QR_PASSWORDED) == 0))
1447                                 wprintf("CHECKED ");
1448                         wprintf(" OnChange=\""
1449                                 "       if (this.form.type[3].checked == true) {        "
1450                                 "               this.form.er_floor.disabled = false;    "
1451                                 "       }                                               "
1452                                 "\"> ");
1453                         wprintf(_("Private - invitation only"));
1454                 
1455                         wprintf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"personal\" ");
1456                         if (er_flags & QR_MAILBOX)
1457                                 wprintf("CHECKED ");
1458                         wprintf (" OnChange=\""
1459                                  "      if (this.form.type[4].checked == true) {        "
1460                                  "              this.form.er_floor.disabled = true;     "
1461                                  "      }                                               "
1462                                  "\"> ");
1463                         wprintf(_("Personal (mailbox for you only)"));
1464                         
1465                         wprintf("\n<li><input type=\"checkbox\" NAME=\"bump\" VALUE=\"yes\" ");
1466                         wprintf("> ");
1467                         wprintf(_("If private, cause current users to forget room"));
1468                 
1469                         wprintf("\n</ul>\n");
1470                 
1471                         wprintf("<li><input type=\"checkbox\" NAME=\"prefonly\" VALUE=\"yes\" ");
1472                         if (er_flags & QR_PREFONLY)
1473                                 wprintf("CHECKED ");
1474                         wprintf("> ");
1475                         wprintf(_("Preferred users only"));
1476                 
1477                         wprintf("\n<li><input type=\"checkbox\" NAME=\"readonly\" VALUE=\"yes\" ");
1478                         if (er_flags & QR_READONLY)
1479                                 wprintf("CHECKED ");
1480                         wprintf("> ");
1481                         wprintf(_("Read-only room"));
1482                 
1483                         wprintf("\n<li><input type=\"checkbox\" NAME=\"collabdel\" VALUE=\"yes\" ");
1484                         if (er_flags2 & QR2_COLLABDEL)
1485                                 wprintf("CHECKED ");
1486                         wprintf("> ");
1487                         wprintf(_("All users allowed to post may also delete messages"));
1488                 
1489                         /** directory stuff */
1490                         wprintf("\n<li><input type=\"checkbox\" NAME=\"directory\" VALUE=\"yes\" ");
1491                         if (er_flags & QR_DIRECTORY)
1492                                 wprintf("CHECKED ");
1493                         wprintf("> ");
1494                         wprintf(_("File directory room"));
1495         
1496                         wprintf("\n<ul><li>");
1497                         wprintf(_("Directory name: "));
1498                         wprintf("<input type=\"text\" NAME=\"er_dirname\" VALUE=\"%s\" MAXLENGTH=\"14\">\n",
1499                                 er_dirname);
1500         
1501                         wprintf("<li><input type=\"checkbox\" NAME=\"ulallowed\" VALUE=\"yes\" ");
1502                         if (er_flags & QR_UPLOAD)
1503                                 wprintf("CHECKED ");
1504                         wprintf("> ");
1505                         wprintf(_("Uploading allowed"));
1506                 
1507                         wprintf("\n<li><input type=\"checkbox\" NAME=\"dlallowed\" VALUE=\"yes\" ");
1508                         if (er_flags & QR_DOWNLOAD)
1509                                 wprintf("CHECKED ");
1510                         wprintf("> ");
1511                         wprintf(_("Downloading allowed"));
1512                 
1513                         wprintf("\n<li><input type=\"checkbox\" NAME=\"visdir\" VALUE=\"yes\" ");
1514                         if (er_flags & QR_VISDIR)
1515                                 wprintf("CHECKED ");
1516                         wprintf("> ");
1517                         wprintf(_("Visible directory"));
1518                         wprintf("</ul>\n");
1519                 
1520                         /** end of directory stuff */
1521         
1522                         wprintf("<li><input type=\"checkbox\" NAME=\"network\" VALUE=\"yes\" ");
1523                         if (er_flags & QR_NETWORK)
1524                                 wprintf("CHECKED ");
1525                         wprintf("> ");
1526                         wprintf(_("Network shared room"));
1527         
1528                         wprintf("\n<li><input type=\"checkbox\" NAME=\"permanent\" VALUE=\"yes\" ");
1529                         if (er_flags & QR_PERMANENT)
1530                                 wprintf("CHECKED ");
1531                         wprintf("> ");
1532                         wprintf(_("Permanent (does not auto-purge)"));
1533         
1534                         wprintf("\n<li><input type=\"checkbox\" NAME=\"subjectreq\" VALUE=\"yes\" ");
1535                         if (er_flags2 & QR2_SUBJECTREQ)
1536                                 wprintf("CHECKED ");
1537                         wprintf("> ");
1538                         wprintf(_("Subject Required (Force users to specify a message subject)"));
1539         
1540                         /** start of anon options */
1541                 
1542                         wprintf("\n<li>");
1543                         wprintf(_("Anonymous messages"));
1544                         wprintf("<ul>\n");
1545                 
1546                         wprintf("<li><input type=\"radio\" NAME=\"anon\" VALUE=\"no\" ");
1547                         if (((er_flags & QR_ANONONLY) == 0)
1548                             && ((er_flags & QR_ANONOPT) == 0))
1549                                 wprintf("CHECKED ");
1550                         wprintf("> ");
1551                         wprintf(_("No anonymous messages"));
1552         
1553                         wprintf("\n<li><input type=\"radio\" NAME=\"anon\" VALUE=\"anononly\" ");
1554                         if (er_flags & QR_ANONONLY)
1555                                 wprintf("CHECKED ");
1556                         wprintf("> ");
1557                         wprintf(_("All messages are anonymous"));
1558                 
1559                         wprintf("\n<li><input type=\"radio\" NAME=\"anon\" VALUE=\"anon2\" ");
1560                         if (er_flags & QR_ANONOPT)
1561                                 wprintf("CHECKED ");
1562                         wprintf("> ");
1563                         wprintf(_("Prompt user when entering messages"));
1564                         wprintf("</ul>\n");
1565                 
1566                         /* end of anon options */
1567                 
1568                         wprintf("<li>");
1569                         wprintf(_("Room aide: "));
1570                         serv_puts("GETA");
1571                         serv_getln(buf, sizeof buf);
1572                         if (buf[0] != '2') {
1573                                 wprintf("<em>%s</em>\n", &buf[4]);
1574                         } else {
1575                                 extract_token(er_roomaide, &buf[4], 0, '|', sizeof er_roomaide);
1576                                 wprintf("<input type=\"text\" NAME=\"er_roomaide\" VALUE=\"%s\" MAXLENGTH=\"25\">\n", er_roomaide);
1577                         }
1578                 
1579                         wprintf("</ul><CENTER>\n");
1580                         wprintf("<input type=\"hidden\" NAME=\"tab\" VALUE=\"config\">\n"
1581                                 "<input type=\"submit\" NAME=\"ok_button\" VALUE=\"%s\">"
1582                                 "&nbsp;"
1583                                 "<input type=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">"
1584                                 "</CENTER>\n",
1585                                 _("Save changes"),
1586                                 _("Cancel")
1587                                 );
1588                 }
1589                 wprintf("</div>");
1590         }
1591
1592
1593         /* Sharing the room with other Citadel nodes... */
1594         if (!strcmp(tab, "sharing")) {
1595                 wprintf("<div class=\"tabcontent\">");
1596
1597                 shared_with = strdup("");
1598                 not_shared_with = strdup("");
1599
1600                 /** Learn the current configuration */
1601                 serv_puts("CONF getsys|application/x-citadel-ignet-config");
1602                 serv_getln(buf, sizeof buf);
1603                 if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1604                                 extract_token(node, buf, 0, '|', sizeof node);
1605                                 not_shared_with = realloc(not_shared_with,
1606                                                           strlen(not_shared_with) + 32);
1607                                 strcat(not_shared_with, node);
1608                                 strcat(not_shared_with, "\n");
1609                         }
1610
1611                 serv_puts("GNET");
1612                 serv_getln(buf, sizeof buf);
1613                 if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1614                                 extract_token(cmd, buf, 0, '|', sizeof cmd);
1615                                 extract_token(node, buf, 1, '|', sizeof node);
1616                                 extract_token(remote_room, buf, 2, '|', sizeof remote_room);
1617                                 if (!strcasecmp(cmd, "ignet_push_share")) {
1618                                         shared_with = realloc(shared_with,
1619                                                               strlen(shared_with) + 32);
1620                                         strcat(shared_with, node);
1621                                         if (!IsEmptyStr(remote_room)) {
1622                                                 strcat(shared_with, "|");
1623                                                 strcat(shared_with, remote_room);
1624                                         }
1625                                         strcat(shared_with, "\n");
1626                                 }
1627                         }
1628
1629                 for (i=0; i<num_tokens(shared_with, '\n'); ++i) {
1630                         extract_token(buf, shared_with, i, '\n', sizeof buf);
1631                         extract_token(node, buf, 0, '|', sizeof node);
1632                         for (j=0; j<num_tokens(not_shared_with, '\n'); ++j) {
1633                                 extract_token(cmd, not_shared_with, j, '\n', sizeof cmd);
1634                                 if (!strcasecmp(node, cmd)) {
1635                                         remove_token(not_shared_with, j, '\n');
1636                                 }
1637                         }
1638                 }
1639
1640                 /* Display the stuff */
1641                 wprintf("<CENTER><br />"
1642                         "<table border=1 cellpadding=5><tr>"
1643                         "<td><B><I>");
1644                 wprintf(_("Shared with"));
1645                 wprintf("</I></B></td>"
1646                         "<td><B><I>");
1647                 wprintf(_("Not shared with"));
1648                 wprintf("</I></B></td></tr>\n"
1649                         "<tr><td VALIGN=TOP>\n");
1650
1651                 wprintf("<table border=0 cellpadding=5><tr class=\"tab_cell\"><td>");
1652                 wprintf(_("Remote node name"));
1653                 wprintf("</td><td>");
1654                 wprintf(_("Remote room name"));
1655                 wprintf("</td><td>");
1656                 wprintf(_("Actions"));
1657                 wprintf("</td></tr>\n");
1658
1659                 for (i=0; i<num_tokens(shared_with, '\n'); ++i) {
1660                         extract_token(buf, shared_with, i, '\n', sizeof buf);
1661                         extract_token(node, buf, 0, '|', sizeof node);
1662                         extract_token(remote_room, buf, 1, '|', sizeof remote_room);
1663                         if (!IsEmptyStr(node)) {
1664                                 wprintf("<form method=\"POST\" action=\"netedit\">");
1665                                 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1666                                 wprintf("<tr><td>%s</td>\n", node);
1667
1668                                 wprintf("<td>");
1669                                 if (!IsEmptyStr(remote_room)) {
1670                                         escputs(remote_room);
1671                                 }
1672                                 wprintf("</td>");
1673
1674                                 wprintf("<td>");
1675                 
1676                                 wprintf("<input type=\"hidden\" NAME=\"line\" "
1677                                         "VALUE=\"ignet_push_share|");
1678                                 urlescputs(node);
1679                                 if (!IsEmptyStr(remote_room)) {
1680                                         wprintf("|");
1681                                         urlescputs(remote_room);
1682                                 }
1683                                 wprintf("\">");
1684                                 wprintf("<input type=\"hidden\" NAME=\"tab\" VALUE=\"sharing\">\n");
1685                                 wprintf("<input type=\"hidden\" NAME=\"cmd\" VALUE=\"remove\">\n");
1686                                 wprintf("<input type=\"submit\" "
1687                                         "NAME=\"unshare_button\" VALUE=\"%s\">", _("Unshare"));
1688                                 wprintf("</td></tr></form>\n");
1689                         }
1690                 }
1691
1692                 wprintf("</table>\n");
1693                 wprintf("</td><td VALIGN=TOP>\n");
1694                 wprintf("<table border=0 cellpadding=5><tr class=\"tab_cell\"><td>");
1695                 wprintf(_("Remote node name"));
1696                 wprintf("</td><td>");
1697                 wprintf(_("Remote room name"));
1698                 wprintf("</td><td>");
1699                 wprintf(_("Actions"));
1700                 wprintf("</td></tr>\n");
1701
1702                 for (i=0; i<num_tokens(not_shared_with, '\n'); ++i) {
1703                         extract_token(node, not_shared_with, i, '\n', sizeof node);
1704                         if (!IsEmptyStr(node)) {
1705                                 wprintf("<form method=\"POST\" action=\"netedit\">");
1706                                 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1707                                 wprintf("<tr><td>");
1708                                 escputs(node);
1709                                 wprintf("</td><td>"
1710                                         "<input type=\"INPUT\" "
1711                                         "NAME=\"suffix\" "
1712                                         "MAXLENGTH=128>"
1713                                         "</td><td>");
1714                                 wprintf("<input type=\"hidden\" "
1715                                         "NAME=\"line\" "
1716                                         "VALUE=\"ignet_push_share|");
1717                                 urlescputs(node);
1718                                 wprintf("|\">");
1719                                 wprintf("<input type=\"hidden\" NAME=\"tab\" "
1720                                         "VALUE=\"sharing\">\n");
1721                                 wprintf("<input type=\"hidden\" NAME=\"cmd\" "
1722                                         "VALUE=\"add\">\n");
1723                                 wprintf("<input type=\"submit\" "
1724                                         "NAME=\"add_button\" VALUE=\"%s\">", _("Share"));
1725                                 wprintf("</td></tr></form>\n");
1726                         }
1727                 }
1728
1729                 wprintf("</table>\n");
1730                 wprintf("</td></tr>"
1731                         "</table></CENTER><br />\n"
1732                         "<I><B>%s</B><ul><li>", _("Notes:"));
1733                 wprintf(_("When sharing a room, "
1734                           "it must be shared from both ends.  Adding a node to "
1735                           "the 'shared' list sends messages out, but in order to"
1736                           " receive messages, the other nodes must be configured"
1737                           " to send messages out to your system as well. "
1738                           "<li>If the remote room name is blank, it is assumed "
1739                           "that the room name is identical on the remote node."
1740                           "<li>If the remote room name is different, the remote "
1741                           "node must also configure the name of the room here."
1742                           "</ul></I><br />\n"
1743                                 ));
1744
1745                 wprintf("</div>");
1746         }
1747
1748         /* Mailing list management */
1749         if (!strcmp(tab, "listserv")) {
1750                 room_states RoomFlags;
1751                 wprintf("<div class=\"tabcontent\">");
1752
1753                 wprintf("<br /><center>"
1754                         "<table BORDER=0 WIDTH=100%% CELLPADDING=5>"
1755                         "<tr><td VALIGN=TOP>");
1756
1757                 wprintf(_("<i>The contents of this room are being "
1758                           "mailed <b>as individual messages</b> "
1759                           "to the following list recipients:"
1760                           "</i><br /><br />\n"));
1761
1762                 serv_puts("GNET");
1763                 serv_getln(buf, sizeof buf);
1764                 if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1765                                 extract_token(cmd, buf, 0, '|', sizeof cmd);
1766                                 if (!strcasecmp(cmd, "listrecp")) {
1767                                         extract_token(recp, buf, 1, '|', sizeof recp);
1768                         
1769                                         escputs(recp);
1770                                         wprintf(" <a href=\"netedit?cmd=remove&tab=listserv&line=listrecp|");
1771                                         urlescputs(recp);
1772                                         wprintf("\">");
1773                                         wprintf(_("(remove)"));
1774                                         wprintf("</A><br />");
1775                                 }
1776                         }
1777                 wprintf("<br /><form method=\"POST\" action=\"netedit\">\n"
1778                         "<input type=\"hidden\" NAME=\"tab\" VALUE=\"listserv\">\n"
1779                         "<input type=\"hidden\" NAME=\"prefix\" VALUE=\"listrecp|\">\n");
1780                 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1781                 wprintf("<input type=\"text\" id=\"add_as_listrecp\" NAME=\"line\">\n");
1782                 wprintf("<input type=\"submit\" NAME=\"add_button\" VALUE=\"%s\">", _("Add"));
1783                 wprintf("</form>\n");
1784
1785                 wprintf("</td><td VALIGN=TOP>\n");
1786                 
1787                 wprintf(_("<i>The contents of this room are being "
1788                           "mailed <b>in digest form</b> "
1789                           "to the following list recipients:"
1790                           "</i><br /><br />\n"));
1791
1792                 serv_puts("GNET");
1793                 serv_getln(buf, sizeof buf);
1794                 if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1795                                 extract_token(cmd, buf, 0, '|', sizeof cmd);
1796                                 if (!strcasecmp(cmd, "digestrecp")) {
1797                                         extract_token(recp, buf, 1, '|', sizeof recp);
1798                         
1799                                         escputs(recp);
1800                                         wprintf(" <a href=\"netedit?cmd=remove&tab=listserv&line="
1801                                                 "digestrecp|");
1802                                         urlescputs(recp);
1803                                         wprintf("\">");
1804                                         wprintf(_("(remove)"));
1805                                         wprintf("</A><br />");
1806                                 }
1807                         }
1808                 wprintf("<br /><form method=\"POST\" action=\"netedit\">\n"
1809                         "<input type=\"hidden\" NAME=\"tab\" VALUE=\"listserv\">\n"
1810                         "<input type=\"hidden\" NAME=\"prefix\" VALUE=\"digestrecp|\">\n");
1811                 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1812                 wprintf("<input type=\"text\" id=\"add_as_digestrecp\" NAME=\"line\">\n");
1813                 wprintf("<input type=\"submit\" NAME=\"add_button\" VALUE=\"%s\">", _("Add"));
1814                 wprintf("</form>\n");
1815                 
1816                 wprintf("</td></tr></table>\n");
1817
1818                 /** Pop open an address book -- begin **/
1819                 wprintf("<div align=right>"
1820                         "<a href=\"javascript:PopOpenAddressBook('add_as_listrecp|%s|add_as_digestrecp|%s');\" "
1821                         "title=\"%s\">"
1822                         "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
1823                         "&nbsp;%s</a>"
1824                         "</div>",
1825                         _("List"),
1826                         _("Digest"),
1827                         _("Add recipients from Contacts or other address books"),
1828                         _("Add recipients from Contacts or other address books")
1829                         );
1830                 /* Pop open an address book -- end **/
1831
1832                 wprintf("<br />\n<form method=\"GET\" action=\"toggle_self_service\">\n");
1833
1834                 get_roomflags (&RoomFlags);
1835                 
1836                 /* Self Service subscription? */
1837                 wprintf("<table><tr><td>\n");
1838                 wprintf(_("Allow self-service subscribe/unsubscribe requests."));
1839                 wprintf("</td><td><input type=\"checkbox\" name=\"QR2_SelfList\" value=\"yes\" %s></td></tr>\n"
1840                         " <tr><td colspan=\"2\">\n",
1841                         (is_selflist(&RoomFlags))?"checked":"");
1842                 wprintf(_("The URL for subscribe/unsubscribe is: "));
1843                 wprintf("<TT>%s://%s/listsub</TT></td></tr>\n",
1844                         (is_https ? "https" : "http"),
1845                         ChrPtr(WC->Hdr->HR.http_host));
1846                 /* Public posting? */
1847                 wprintf("<tr><td>");
1848                 wprintf(_("Allow non-subscribers to mail to this room."));
1849                 wprintf("</td><td><input type=\"checkbox\" name=\"QR2_SubsOnly\" value=\"yes\" %s></td></tr>\n",
1850                         (is_publiclist(&RoomFlags))?"checked":"");
1851                 
1852                 /* Moderated List? */
1853                 wprintf("<tr><td>");
1854                 wprintf(_("Room post publication needs Aide permission."));
1855                 wprintf("</td><td><input type=\"checkbox\" name=\"QR2_Moderated\" value=\"yes\" %s></td></tr>\n",
1856                         (is_moderatedlist(&RoomFlags))?"checked":"");
1857
1858
1859                 wprintf("<tr><td colspan=\"2\" align=\"center\">"
1860                         "<input type=\"submit\" NAME=\"add_button\" VALUE=\"%s\"></td></tr>", _("Save changes"));
1861                 wprintf("</table></form>");
1862                         
1863
1864                 wprintf("</CENTER>\n");
1865                 wprintf("</div>");
1866         }
1867
1868
1869         /* Configuration of The Dreaded Auto-Purger */
1870         if (!strcmp(tab, "expire")) {
1871                 wprintf("<div class=\"tabcontent\">");
1872
1873                 serv_puts("GPEX room");
1874                 serv_getln(buf, sizeof buf);
1875                 if (!strncmp(buf, "550", 3)) {
1876                         wprintf("<br><br><div align=center>%s</div><br><br>\n",
1877                                 _("Higher access is required to access this function.")
1878                                 );
1879                 }
1880                 else if (buf[0] != '2') {
1881                         wprintf("<br><br><div align=center>%s</div><br><br>\n", &buf[4]);
1882                 }
1883                 else {
1884                         roompolicy = extract_int(&buf[4], 0);
1885                         roomvalue = extract_int(&buf[4], 1);
1886                 
1887                         serv_puts("GPEX floor");
1888                         serv_getln(buf, sizeof buf);
1889                         if (buf[0] == '2') {
1890                                 floorpolicy = extract_int(&buf[4], 0);
1891                                 floorvalue = extract_int(&buf[4], 1);
1892                         }
1893                         
1894                         wprintf("<br /><form method=\"POST\" action=\"set_room_policy\">\n");
1895                         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1896                         wprintf("<table border=0 cellspacing=5>\n");
1897                         wprintf("<tr><td>");
1898                         wprintf(_("Message expire policy for this room"));
1899                         wprintf("<br />(");
1900                         escputs(ChrPtr(WC->wc_roomname));
1901                         wprintf(")</td><td>");
1902                         wprintf("<input type=\"radio\" NAME=\"roompolicy\" VALUE=\"0\" %s>",
1903                                 ((roompolicy == 0) ? "CHECKED" : "") );
1904                         wprintf(_("Use the default policy for this floor"));
1905                         wprintf("<br />\n");
1906                         wprintf("<input type=\"radio\" NAME=\"roompolicy\" VALUE=\"1\" %s>",
1907                                 ((roompolicy == 1) ? "CHECKED" : "") );
1908                         wprintf(_("Never automatically expire messages"));
1909                         wprintf("<br />\n");
1910                         wprintf("<input type=\"radio\" NAME=\"roompolicy\" VALUE=\"2\" %s>",
1911                                 ((roompolicy == 2) ? "CHECKED" : "") );
1912                         wprintf(_("Expire by message count"));
1913                         wprintf("<br />\n");
1914                         wprintf("<input type=\"radio\" NAME=\"roompolicy\" VALUE=\"3\" %s>",
1915                                 ((roompolicy == 3) ? "CHECKED" : "") );
1916                         wprintf(_("Expire by message age"));
1917                         wprintf("<br />");
1918                         wprintf(_("Number of messages or days: "));
1919                         wprintf("<input type=\"text\" NAME=\"roomvalue\" MAXLENGTH=\"5\" VALUE=\"%d\">", roomvalue);
1920                         wprintf("</td></tr>\n");
1921         
1922                         if (WC->axlevel >= 6) {
1923                                 wprintf("<tr><td COLSPAN=2><hr /></td></tr>\n");
1924                                 wprintf("<tr><td>");
1925                                 wprintf(_("Message expire policy for this floor"));
1926                                 wprintf("<br />(");
1927                                 escputs(floorlist[WC->wc_floor]);
1928                                 wprintf(")</td><td>");
1929                                 wprintf("<input type=\"radio\" NAME=\"floorpolicy\" VALUE=\"0\" %s>",
1930                                         ((floorpolicy == 0) ? "CHECKED" : "") );
1931                                 wprintf(_("Use the system default"));
1932                                 wprintf("<br />\n");
1933                                 wprintf("<input type=\"radio\" NAME=\"floorpolicy\" VALUE=\"1\" %s>",
1934                                         ((floorpolicy == 1) ? "CHECKED" : "") );
1935                                 wprintf(_("Never automatically expire messages"));
1936                                 wprintf("<br />\n");
1937                                 wprintf("<input type=\"radio\" NAME=\"floorpolicy\" VALUE=\"2\" %s>",
1938                                         ((floorpolicy == 2) ? "CHECKED" : "") );
1939                                 wprintf(_("Expire by message count"));
1940                                 wprintf("<br />\n");
1941                                 wprintf("<input type=\"radio\" NAME=\"floorpolicy\" VALUE=\"3\" %s>",
1942                                         ((floorpolicy == 3) ? "CHECKED" : "") );
1943                                 wprintf(_("Expire by message age"));
1944                                 wprintf("<br />");
1945                                 wprintf(_("Number of messages or days: "));
1946                                 wprintf("<input type=\"text\" NAME=\"floorvalue\" MAXLENGTH=\"5\" VALUE=\"%d\">",
1947                                         floorvalue);
1948                         }
1949         
1950                         wprintf("<CENTER>\n");
1951                         wprintf("<tr><td COLSPAN=2><hr /><CENTER>\n");
1952                         wprintf("<input type=\"submit\" NAME=\"ok_button\" VALUE=\"%s\">", _("Save changes"));
1953                         wprintf("&nbsp;");
1954                         wprintf("<input type=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
1955                         wprintf("</CENTER></td><tr>\n");
1956         
1957                         wprintf("</table>\n"
1958                                 "<input type=\"hidden\" NAME=\"tab\" VALUE=\"expire\">\n"
1959                                 "</form>\n"
1960                                 );
1961                 }
1962
1963                 wprintf("</div>");
1964         }
1965
1966         /* Access controls */
1967         if (!strcmp(tab, "access")) {
1968                 wprintf("<div class=\"tabcontent\">");
1969                 display_whok();
1970                 wprintf("</div>");
1971         }
1972
1973         /* Fetch messages from remote locations */
1974         if (!strcmp(tab, "feeds")) {
1975                 wprintf("<div class=\"tabcontent\">");
1976
1977                 wprintf("<i>");
1978                 wprintf(_("Retrieve messages from these remote POP3 accounts and store them in this room:"));
1979                 wprintf("</i><br />\n");
1980
1981                 wprintf("<table class=\"altern\" border=0 cellpadding=5>"
1982                         "<tr class=\"even\"><th>");
1983                 wprintf(_("Remote host"));
1984                 wprintf("</th><th>");
1985                 wprintf(_("User name"));
1986                 wprintf("</th><th>");
1987                 wprintf(_("Password"));
1988                 wprintf("</th><th>");
1989                 wprintf(_("Keep messages on server?"));
1990                 wprintf("</th><th>");
1991                 wprintf(_("Interval"));
1992                 wprintf("</th><th> </th></tr>");
1993
1994                 serv_puts("GNET");
1995                 serv_getln(buf, sizeof buf);
1996                 bg = 1;
1997                 if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1998                                 extract_token(cmd, buf, 0, '|', sizeof cmd);
1999                                 if (!strcasecmp(cmd, "pop3client")) {
2000                                         safestrncpy(recp, &buf[11], sizeof recp);
2001
2002                                         bg = 1 - bg;
2003                                         wprintf("<tr class=\"%s\">",
2004                                                 (bg ? "even" : "odd")
2005                                                 );
2006
2007                                         wprintf("<td>");
2008                                         extract_token(pop3_host, buf, 1, '|', sizeof pop3_host);
2009                                         escputs(pop3_host);
2010                                         wprintf("</td>");
2011
2012                                         wprintf("<td>");
2013                                         extract_token(pop3_user, buf, 2, '|', sizeof pop3_user);
2014                                         escputs(pop3_user);
2015                                         wprintf("</td>");
2016
2017                                         wprintf("<td>*****</td>");              /* Don't show the password */
2018
2019                                         wprintf("<td>%s</td>", extract_int(buf, 4) ? _("Yes") : _("No"));
2020
2021                                         wprintf("<td>%ld</td>", extract_long(buf, 5));  /* Fetching interval */
2022                         
2023                                         wprintf("<td class=\"button_link\">");
2024                                         wprintf(" <a href=\"netedit?cmd=remove&tab=feeds&line=pop3client|");
2025                                         urlescputs(recp);
2026                                         wprintf("\">");
2027                                         wprintf(_("(remove)"));
2028                                         wprintf("</a></td>");
2029                         
2030                                         wprintf("</tr>");
2031                                 }
2032                         }
2033
2034                 wprintf("<form method=\"POST\" action=\"netedit\">\n"
2035                         "<tr>"
2036                         "<input type=\"hidden\" name=\"tab\" value=\"feeds\">"
2037                         "<input type=\"hidden\" name=\"prefix\" value=\"pop3client|\">\n");
2038                 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
2039                 wprintf("<td>");
2040                 wprintf("<input type=\"text\" id=\"add_as_pop3host\" NAME=\"line_pop3host\">\n");
2041                 wprintf("</td>");
2042                 wprintf("<td>");
2043                 wprintf("<input type=\"text\" id=\"add_as_pop3user\" NAME=\"line_pop3user\">\n");
2044                 wprintf("</td>");
2045                 wprintf("<td>");
2046                 wprintf("<input type=\"password\" id=\"add_as_pop3pass\" NAME=\"line_pop3pass\">\n");
2047                 wprintf("</td>");
2048                 wprintf("<td>");
2049                 wprintf("<input type=\"checkbox\" id=\"add_as_pop3keep\" NAME=\"line_pop3keep\" VALUE=\"1\">");
2050                 wprintf("</td>");
2051                 wprintf("<td>");
2052                 wprintf("<input type=\"text\" id=\"add_as_pop3int\" NAME=\"line_pop3int\" MAXLENGTH=\"5\">");
2053                 wprintf("</td>");
2054                 wprintf("<td>");
2055                 wprintf("<input type=\"submit\" NAME=\"add_button\" VALUE=\"%s\">", _("Add"));
2056                 wprintf("</td></tr>");
2057                 wprintf("</form></table>\n");
2058
2059                 wprintf("<hr>\n");
2060
2061                 wprintf("<i>");
2062                 wprintf(_("Fetch the following RSS feeds and store them in this room:"));
2063                 wprintf("</i><br />\n");
2064
2065                 wprintf("<table class=\"altern\" border=0 cellpadding=5>"
2066                         "<tr class=\"even\"><th>");
2067                 wprintf("<img src=\"static/rss_16x.png\" width=\"16\" height=\"16\" alt=\" \"> ");
2068                 wprintf(_("Feed URL"));
2069                 wprintf("</th><th>");
2070                 wprintf("</th></tr>");
2071
2072                 serv_puts("GNET");
2073                 serv_getln(buf, sizeof buf);
2074                 bg = 1;
2075                 if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2076                                 extract_token(cmd, buf, 0, '|', sizeof cmd);
2077                                 if (!strcasecmp(cmd, "rssclient")) {
2078                                         safestrncpy(recp, &buf[10], sizeof recp);
2079
2080                                         bg = 1 - bg;
2081                                         wprintf("<tr class=\"%s\">",
2082                                                 (bg ? "even" : "odd")
2083                                                 );
2084
2085                                         wprintf("<td>");
2086                                         extract_token(pop3_host, buf, 1, '|', sizeof pop3_host);
2087                                         escputs(pop3_host);
2088                                         wprintf("</td>");
2089
2090                                         wprintf("<td class=\"button_link\">");
2091                                         wprintf(" <a href=\"netedit?cmd=remove&tab=feeds&line=rssclient|");
2092                                         urlescputs(recp);
2093                                         wprintf("\">");
2094                                         wprintf(_("(remove)"));
2095                                         wprintf("</a></td>");
2096                         
2097                                         wprintf("</tr>");
2098                                 }
2099                         }
2100
2101                 wprintf("<form method=\"POST\" action=\"netedit\">\n"
2102                         "<tr>"
2103                         "<input type=\"hidden\" name=\"tab\" value=\"feeds\">"
2104                         "<input type=\"hidden\" name=\"prefix\" value=\"rssclient|\">\n");
2105                 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
2106                 wprintf("<td>");
2107                 wprintf("<input type=\"text\" id=\"add_as_pop3host\" size=\"72\" "
2108                         "maxlength=\"256\" name=\"line_pop3host\">\n");
2109                 wprintf("</td>");
2110                 wprintf("<td>");
2111                 wprintf("<input type=\"submit\" name=\"add_button\" value=\"%s\">", _("Add"));
2112                 wprintf("</td></tr>");
2113                 wprintf("</form></table>\n");
2114
2115                 wprintf("</div>");
2116         }
2117
2118
2119         /* end content of whatever tab is open now */
2120         wprintf("</div>\n");
2121
2122         address_book_popup();
2123         wDumpContent(1);
2124 }
2125
2126
2127 /* 
2128  * Toggle self-service list subscription
2129  */
2130 void toggle_self_service(void) {
2131         room_states RoomFlags;
2132
2133         get_roomflags (&RoomFlags);
2134
2135         if (yesbstr("QR2_SelfList")) 
2136                 RoomFlags.flags2 = RoomFlags.flags2 | QR2_SELFLIST;
2137         else 
2138                 RoomFlags.flags2 = RoomFlags.flags2 & ~QR2_SELFLIST;
2139
2140         if (yesbstr("QR2_SMTP_PUBLIC")) 
2141                 RoomFlags.flags2 = RoomFlags.flags2 | QR2_SMTP_PUBLIC;
2142         else
2143                 RoomFlags.flags2 = RoomFlags.flags2 & ~QR2_SMTP_PUBLIC;
2144
2145         if (yesbstr("QR2_Moderated")) 
2146                 RoomFlags.flags2 = RoomFlags.flags2 | QR2_MODERATED;
2147         else
2148                 RoomFlags.flags2 = RoomFlags.flags2 & ~QR2_MODERATED;
2149         if (yesbstr("QR2_SubsOnly")) 
2150                 RoomFlags.flags2 = RoomFlags.flags2 | QR2_SMTP_PUBLIC;
2151         else
2152                 RoomFlags.flags2 = RoomFlags.flags2 & ~QR2_SMTP_PUBLIC;
2153
2154         set_roomflags (&RoomFlags);
2155         
2156         display_editroom();
2157 }
2158
2159
2160
2161 /*
2162  * save new parameters for a room
2163  */
2164 void editroom(void)
2165 {
2166         const StrBuf *Ptr;
2167         StrBuf *Buf;
2168         StrBuf *er_name;
2169         StrBuf *er_password;
2170         StrBuf *er_dirname;
2171         StrBuf *er_roomaide;
2172         int er_floor;
2173         unsigned er_flags;
2174         int er_listingorder;
2175         int er_defaultview;
2176         unsigned er_flags2;
2177         int bump;
2178
2179
2180         if (!havebstr("ok_button")) {
2181                 strcpy(WC->ImportantMessage,
2182                        _("Cancelled.  Changes were not saved."));
2183                 display_editroom();
2184                 return;
2185         }
2186         serv_puts("GETR");
2187         Buf = NewStrBuf();
2188         StrBuf_ServGetln(Buf);
2189         if (GetServerStatus(Buf, NULL) != 2) {
2190                 StrBufCutLeft(Buf, 4);
2191                 strcpy(WC->ImportantMessage, ChrPtr(Buf));
2192                 display_editroom();
2193                 FreeStrBuf(&Buf);
2194                 return;
2195         }
2196
2197         er_name = NewStrBuf();
2198         er_password = NewStrBuf();
2199         er_dirname = NewStrBuf();
2200         er_roomaide = NewStrBuf();
2201
2202         StrBufCutLeft(Buf, 4);
2203         StrBufExtract_token(er_name, Buf, 0, '|');
2204         StrBufExtract_token(er_password, Buf, 1, '|');
2205         StrBufExtract_token(er_dirname, Buf, 2, '|');
2206         er_flags = StrBufExtract_int(Buf, 3, '|');
2207         er_listingorder = StrBufExtract_int(Buf, 5, '|');
2208         er_defaultview = StrBufExtract_int(Buf, 6, '|');
2209         er_flags2 = StrBufExtract_int(Buf, 7, '|');
2210
2211         er_roomaide = NewStrBufDup(sbstr("er_roomaide"));
2212         if (StrLength(er_roomaide) == 0) {
2213                 serv_puts("GETA");
2214                 StrBuf_ServGetln(Buf);
2215                 if (GetServerStatus(Buf, NULL) != 2) {
2216                         FlushStrBuf(er_roomaide);
2217                 } else {
2218                         StrBufCutLeft(Buf, 4);
2219                         StrBufExtract_token(er_roomaide, Buf, 0, '|');
2220                 }
2221         }
2222         Ptr = sbstr("er_name");
2223         if (StrLength(Ptr) > 0) {
2224                 FlushStrBuf(er_name);
2225                 StrBufAppendBuf(er_name, Ptr, 0);
2226         }
2227
2228         Ptr = sbstr("er_password");
2229         if (StrLength(Ptr) > 0) {
2230                 FlushStrBuf(er_password);
2231                 StrBufAppendBuf(er_password, Ptr, 0);
2232         }
2233                 
2234
2235         Ptr = sbstr("er_dirname");
2236         if (StrLength(Ptr) > 0) { /* todo: cut 15 */
2237                 FlushStrBuf(er_dirname);
2238                 StrBufAppendBuf(er_dirname, Ptr, 0);
2239         }
2240
2241
2242         Ptr = sbstr("type");
2243         er_flags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
2244
2245         if (!strcmp(ChrPtr(Ptr), "invonly")) {
2246                 er_flags |= (QR_PRIVATE);
2247         }
2248         if (!strcmp(ChrPtr(Ptr), "hidden")) {
2249                 er_flags |= (QR_PRIVATE | QR_GUESSNAME);
2250         }
2251         if (!strcmp(ChrPtr(Ptr), "passworded")) {
2252                 er_flags |= (QR_PRIVATE | QR_PASSWORDED);
2253         }
2254         if (!strcmp(ChrPtr(Ptr), "personal")) {
2255                 er_flags |= QR_MAILBOX;
2256         } else {
2257                 er_flags &= ~QR_MAILBOX;
2258         }
2259         
2260         if (yesbstr("prefonly")) {
2261                 er_flags |= QR_PREFONLY;
2262         } else {
2263                 er_flags &= ~QR_PREFONLY;
2264         }
2265
2266         if (yesbstr("readonly")) {
2267                 er_flags |= QR_READONLY;
2268         } else {
2269                 er_flags &= ~QR_READONLY;
2270         }
2271
2272         
2273         if (yesbstr("collabdel")) {
2274                 er_flags2 |= QR2_COLLABDEL;
2275         } else {
2276                 er_flags2 &= ~QR2_COLLABDEL;
2277         }
2278
2279         if (yesbstr("permanent")) {
2280                 er_flags |= QR_PERMANENT;
2281         } else {
2282                 er_flags &= ~QR_PERMANENT;
2283         }
2284
2285         if (yesbstr("subjectreq")) {
2286                 er_flags2 |= QR2_SUBJECTREQ;
2287         } else {
2288                 er_flags2 &= ~QR2_SUBJECTREQ;
2289         }
2290
2291         if (yesbstr("network")) {
2292                 er_flags |= QR_NETWORK;
2293         } else {
2294                 er_flags &= ~QR_NETWORK;
2295         }
2296
2297         if (yesbstr("directory")) {
2298                 er_flags |= QR_DIRECTORY;
2299         } else {
2300                 er_flags &= ~QR_DIRECTORY;
2301         }
2302
2303         if (yesbstr("ulallowed")) {
2304                 er_flags |= QR_UPLOAD;
2305         } else {
2306                 er_flags &= ~QR_UPLOAD;
2307         }
2308
2309         if (yesbstr("dlallowed")) {
2310                 er_flags |= QR_DOWNLOAD;
2311         } else {
2312                 er_flags &= ~QR_DOWNLOAD;
2313         }
2314
2315         if (yesbstr("visdir")) {
2316                 er_flags |= QR_VISDIR;
2317         } else {
2318                 er_flags &= ~QR_VISDIR;
2319         }
2320
2321         Ptr = sbstr("anon");
2322
2323         er_flags &= ~(QR_ANONONLY | QR_ANONOPT);
2324         if (!strcmp(ChrPtr(Ptr), "anononly"))
2325                 er_flags |= QR_ANONONLY;
2326         if (!strcmp(ChrPtr(Ptr), "anon2"))
2327                 er_flags |= QR_ANONOPT;
2328
2329         bump = yesbstr("bump");
2330
2331         er_floor = ibstr("er_floor");
2332
2333         StrBufPrintf(Buf, "SETR %s|%s|%s|%u|%d|%d|%d|%d|%u",
2334                      ChrPtr(er_name), 
2335                      ChrPtr(er_password), 
2336                      ChrPtr(er_dirname), 
2337                      er_flags, 
2338                      bump, 
2339                      er_floor,
2340                      er_listingorder, 
2341                      er_defaultview, 
2342                      er_flags2);
2343         serv_putbuf(Buf);
2344         StrBuf_ServGetln(Buf);
2345         if (GetServerStatus(Buf, NULL) != 2) {
2346                 strcpy(WC->ImportantMessage, &ChrPtr(Buf)[4]);
2347                 display_editroom();
2348                 FreeStrBuf(&Buf);
2349                 FreeStrBuf(&er_name);
2350                 FreeStrBuf(&er_password);
2351                 FreeStrBuf(&er_dirname);
2352                 FreeStrBuf(&er_roomaide);
2353                 return;
2354         }
2355         gotoroom(er_name);
2356
2357         if (StrLength(er_roomaide) > 0) {
2358                 serv_printf("SETA %s", ChrPtr(er_roomaide));
2359                 StrBuf_ServGetln(Buf);
2360                 if (GetServerStatus(Buf, NULL) != 2) {
2361                         strcpy(WC->ImportantMessage, &ChrPtr(Buf)[4]);
2362                         display_main_menu();
2363                         FreeStrBuf(&Buf);
2364                         FreeStrBuf(&er_name);
2365                         FreeStrBuf(&er_password);
2366                         FreeStrBuf(&er_dirname);
2367                         FreeStrBuf(&er_roomaide);
2368                         return;
2369                 }
2370         }
2371         gotoroom(er_name);
2372         strcpy(WC->ImportantMessage, _("Your changes have been saved."));
2373         display_editroom();
2374         FreeStrBuf(&Buf);
2375         FreeStrBuf(&er_name);
2376         FreeStrBuf(&er_password);
2377         FreeStrBuf(&er_dirname);
2378         FreeStrBuf(&er_roomaide);
2379         return;
2380 }
2381
2382
2383 /*
2384  * Display form for Invite, Kick, and show Who Knows a room
2385  */
2386 void do_invt_kick(void) {
2387         char buf[SIZ], room[SIZ], username[SIZ];
2388
2389         serv_puts("GETR");
2390         serv_getln(buf, sizeof buf);
2391
2392         if (buf[0] != '2') {
2393                 escputs(&buf[4]);
2394                 return;
2395         }
2396         extract_token(room, &buf[4], 0, '|', sizeof room);
2397
2398         strcpy(username, bstr("username"));
2399
2400         if (havebstr("kick_button")) {
2401                 sprintf(buf, "KICK %s", username);
2402                 serv_puts(buf);
2403                 serv_getln(buf, sizeof buf);
2404
2405                 if (buf[0] != '2') {
2406                         strcpy(WC->ImportantMessage, &buf[4]);
2407                 } else {
2408                         sprintf(WC->ImportantMessage,
2409                                 _("<B><I>User %s kicked out of room %s.</I></B>\n"), 
2410                                 username, room);
2411                 }
2412         }
2413
2414         if (havebstr("invite_button")) {
2415                 sprintf(buf, "INVT %s", username);
2416                 serv_puts(buf);
2417                 serv_getln(buf, sizeof buf);
2418
2419                 if (buf[0] != '2') {
2420                         strcpy(WC->ImportantMessage, &buf[4]);
2421                 } else {
2422                         sprintf(WC->ImportantMessage,
2423                                 _("<B><I>User %s invited to room %s.</I></B>\n"), 
2424                                 username, room);
2425                 }
2426         }
2427
2428         display_editroom();
2429 }
2430
2431
2432
2433 /*
2434  * Display form for Invite, Kick, and show Who Knows a room
2435  */
2436 void display_whok(void)
2437 {
2438         char buf[SIZ], room[SIZ], username[SIZ];
2439
2440         serv_puts("GETR");
2441         serv_getln(buf, sizeof buf);
2442
2443         if (buf[0] != '2') {
2444                 escputs(&buf[4]);
2445                 return;
2446         }
2447         extract_token(room, &buf[4], 0, '|', sizeof room);
2448
2449         
2450         wprintf("<table border=0 CELLSPACING=10><tr VALIGN=TOP><td>");
2451         wprintf(_("The users listed below have access to this room.  "
2452                   "To remove a user from the access list, select the user "
2453                   "name from the list and click 'Kick'."));
2454         wprintf("<br /><br />");
2455         
2456         wprintf("<CENTER><form method=\"POST\" action=\"do_invt_kick\">\n");
2457         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
2458         wprintf("<input type=\"hidden\" NAME=\"tab\" VALUE=\"access\">\n");
2459         wprintf("<select NAME=\"username\" SIZE=\"10\" style=\"width:100%%\">\n");
2460         serv_puts("WHOK");
2461         serv_getln(buf, sizeof buf);
2462         if (buf[0] == '1') {
2463                 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2464                         extract_token(username, buf, 0, '|', sizeof username);
2465                         wprintf("<OPTION>");
2466                         escputs(username);
2467                         wprintf("\n");
2468                 }
2469         }
2470         wprintf("</select><br />\n");
2471
2472         wprintf("<input type=\"submit\" name=\"kick_button\" value=\"%s\">", _("Kick"));
2473         wprintf("</form></CENTER>\n");
2474
2475         wprintf("</td><td>");
2476         wprintf(_("To grant another user access to this room, enter the "
2477                   "user name in the box below and click 'Invite'."));
2478         wprintf("<br /><br />");
2479
2480         wprintf("<CENTER><form method=\"POST\" action=\"do_invt_kick\">\n");
2481         wprintf("<input type=\"hidden\" NAME=\"tab\" VALUE=\"access\">\n");
2482         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
2483         wprintf(_("Invite:"));
2484         wprintf(" ");
2485         wprintf("<input type=\"text\" name=\"username\" id=\"username_id\" style=\"width:100%%\"><br />\n"
2486                 "<input type=\"hidden\" name=\"invite_button\" value=\"Invite\">"
2487                 "<input type=\"submit\" value=\"%s\">"
2488                 "</form></CENTER>\n", _("Invite"));
2489         /* Pop open an address book -- begin **/
2490         wprintf(
2491                 "<a href=\"javascript:PopOpenAddressBook('username_id|%s');\" "
2492                 "title=\"%s\">"
2493                 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
2494                 "&nbsp;%s</a>",
2495                 _("User"), 
2496                 _("Users"), _("Users")
2497                 );
2498         /* Pop open an address book -- end **/
2499
2500         wprintf("</td></tr></table>\n");
2501         address_book_popup();
2502         wDumpContent(1);
2503 }
2504
2505
2506
2507 /*
2508  * display the form for entering a new room
2509  */
2510 void display_entroom(void)
2511 {
2512         StrBuf *Buf;
2513         int i;
2514         char buf[SIZ];
2515
2516         Buf = NewStrBuf();
2517         serv_puts("CRE8 0");
2518         serv_getln(buf, sizeof buf);
2519
2520         if (buf[0] != '2') {
2521                 strcpy(WC->ImportantMessage, &buf[4]);
2522                 display_main_menu();
2523                 FreeStrBuf(&Buf);
2524                 return;
2525         }
2526
2527         output_headers(1, 1, 1, 0, 0, 0);
2528
2529         svprintf(HKEY("BOXTITLE"), WCS_STRING, _("Create a new room"));
2530         do_template("beginbox", NULL);
2531
2532         wprintf("<form name=\"create_room_form\" method=\"POST\" action=\"entroom\">\n");
2533         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
2534
2535         wprintf("<table class=\"altern\"> ");
2536
2537         wprintf("<tr class=\"even\"><td>");
2538         wprintf(_("Name of room: "));
2539         wprintf("</td><td>");
2540         wprintf("<input type=\"text\" NAME=\"er_name\" MAXLENGTH=\"127\">\n");
2541         wprintf("</td></tr>");
2542
2543         wprintf("<tr class=\"odd\"><td>");
2544         wprintf(_("Resides on floor: "));
2545         wprintf("</td><td>");
2546         load_floorlist(Buf); 
2547         wprintf("<select name=\"er_floor\" size=\"1\">\n");
2548         for (i = 0; i < 128; ++i)
2549                 if (!IsEmptyStr(floorlist[i])) {
2550                         wprintf("<option ");
2551                         wprintf("value=\"%d\">", i);
2552                         escputs(floorlist[i]);
2553                         wprintf("</option>\n");
2554                 }
2555         wprintf("</select>\n");
2556         wprintf("</td></tr>");
2557
2558         /*
2559          * Our clever little snippet of JavaScript automatically selects
2560          * a public room if the view is set to Bulletin Board or wiki, and
2561          * it selects a mailbox room otherwise.  The user can override this,
2562          * of course.  We also disable the floor selector for mailboxes.
2563          */
2564         wprintf("<tr class=\"even\"><td>");
2565         wprintf(_("Default view for room: "));
2566         wprintf("</td><td>");
2567         wprintf("<select name=\"er_view\" size=\"1\" OnChange=\""
2568                 "       if ( (this.form.er_view.value == 0)             "
2569                 "          || (this.form.er_view.value == 6) ) {        "
2570                 "               this.form.type[0].checked=true;         "
2571                 "               this.form.er_floor.disabled = false;    "
2572                 "       }                                               "
2573                 "       else {                                          "
2574                 "               this.form.type[4].checked=true;         "
2575                 "               this.form.er_floor.disabled = true;     "
2576                 "       }                                               "
2577                 "\">\n");
2578         for (i=0; i<(sizeof viewdefs / sizeof (char *)); ++i) {
2579                 if (is_view_allowed_as_default(i)) {
2580                         wprintf("<option %s value=\"%d\">",
2581                                 ((i == 0) ? "selected" : ""), i );
2582                         escputs(viewdefs[i]);
2583                         wprintf("</option>\n");
2584                 }
2585         }
2586         wprintf("</select>\n");
2587         wprintf("</td></tr>");
2588
2589         wprintf("<tr class=\"even\"><td>");
2590         wprintf(_("Type of room:"));
2591         wprintf("</td><td>");
2592         wprintf("<ul class=\"adminlist\">\n");
2593
2594         wprintf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"public\" ");
2595         wprintf("CHECKED OnChange=\""
2596                 "       if (this.form.type[0].checked == true) {        "
2597                 "               this.form.er_floor.disabled = false;    "
2598                 "       }                                               "
2599                 "\"> ");
2600         wprintf(_("Public (automatically appears to everyone)"));
2601         wprintf("</li>");
2602
2603         wprintf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"hidden\" OnChange=\""
2604                 "       if (this.form.type[1].checked == true) {        "
2605                 "               this.form.er_floor.disabled = false;    "
2606                 "       }                                               "
2607                 "\"> ");
2608         wprintf(_("Private - hidden (accessible to anyone who knows its name)"));
2609         wprintf("</li>");
2610
2611         wprintf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"passworded\" OnChange=\""
2612                 "       if (this.form.type[2].checked == true) {        "
2613                 "               this.form.er_floor.disabled = false;    "
2614                 "       }                                               "
2615                 "\"> ");
2616         wprintf(_("Private - require password: "));
2617         wprintf("<input type=\"text\" NAME=\"er_password\" MAXLENGTH=\"9\">\n");
2618         wprintf("</li>");
2619
2620         wprintf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"invonly\" OnChange=\""
2621                 "       if (this.form.type[3].checked == true) {        "
2622                 "               this.form.er_floor.disabled = false;    "
2623                 "       }                                               "
2624                 "\"> ");
2625         wprintf(_("Private - invitation only"));
2626         wprintf("</li>");
2627
2628         wprintf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"personal\" "
2629                 "OnChange=\""
2630                 "       if (this.form.type[4].checked == true) {        "
2631                 "               this.form.er_floor.disabled = true;     "
2632                 "       }                                               "
2633                 "\"> ");
2634         wprintf(_("Personal (mailbox for you only)"));
2635         wprintf("</li>");
2636
2637         wprintf("\n</ul>\n");
2638         wprintf("</td></tr></table>\n");
2639
2640         wprintf("<div class=\"buttons\">\n");
2641         wprintf("<input type=\"submit\" name=\"ok_button\" value=\"%s\">", _("Create new room"));
2642         wprintf("&nbsp;");
2643         wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">", _("Cancel"));
2644         wprintf("</div>\n");
2645         wprintf("</form>\n<hr />");
2646         serv_printf("MESG roomaccess");
2647         serv_getln(buf, sizeof buf);
2648         if (buf[0] == '1') {
2649                 fmout("LEFT");
2650         }
2651
2652         do_template("endbox", NULL);
2653
2654         wDumpContent(1);
2655         FreeStrBuf(&Buf);
2656 }
2657
2658
2659
2660
2661 /*
2662  * support function for entroom() -- sets the default view 
2663  */
2664 void er_set_default_view(int newview) {
2665
2666         char buf[SIZ];
2667
2668         char rm_name[SIZ];
2669         char rm_pass[SIZ];
2670         char rm_dir[SIZ];
2671         int rm_bits1;
2672         int rm_floor;
2673         int rm_listorder;
2674         int rm_bits2;
2675
2676         serv_puts("GETR");
2677         serv_getln(buf, sizeof buf);
2678         if (buf[0] != '2') return;
2679
2680         extract_token(rm_name, &buf[4], 0, '|', sizeof rm_name);
2681         extract_token(rm_pass, &buf[4], 1, '|', sizeof rm_pass);
2682         extract_token(rm_dir, &buf[4], 2, '|', sizeof rm_dir);
2683         rm_bits1 = extract_int(&buf[4], 3);
2684         rm_floor = extract_int(&buf[4], 4);
2685         rm_listorder = extract_int(&buf[4], 5);
2686         rm_bits2 = extract_int(&buf[4], 7);
2687
2688         serv_printf("SETR %s|%s|%s|%d|0|%d|%d|%d|%d",
2689                     rm_name, rm_pass, rm_dir, rm_bits1, rm_floor,
2690                     rm_listorder, newview, rm_bits2
2691                 );
2692         serv_getln(buf, sizeof buf);
2693 }
2694
2695
2696
2697 /*
2698  * Create a new room
2699  */
2700 void entroom(void)
2701 {
2702         char buf[SIZ];
2703         const StrBuf *er_name;
2704         const StrBuf *er_type;
2705         const StrBuf *er_password;
2706         int er_floor;
2707         int er_num_type;
2708         int er_view;
2709
2710         if (!havebstr("ok_button")) {
2711                 strcpy(WC->ImportantMessage,
2712                        _("Cancelled.  No new room was created."));
2713                 display_main_menu();
2714                 return;
2715         }
2716         er_name = sbstr("er_name");
2717         er_type = sbstr("type");
2718         er_password = sbstr("er_password");
2719         er_floor = ibstr("er_floor");
2720         er_view = ibstr("er_view");
2721
2722         er_num_type = 0;
2723         if (!strcmp(ChrPtr(er_type), "hidden"))
2724                 er_num_type = 1;
2725         else if (!strcmp(ChrPtr(er_type), "passworded"))
2726                 er_num_type = 2;
2727         else if (!strcmp(ChrPtr(er_type), "invonly"))
2728                 er_num_type = 3;
2729         else if (!strcmp(ChrPtr(er_type), "personal"))
2730                 er_num_type = 4;
2731
2732         serv_printf("CRE8 1|%s|%d|%s|%d|%d|%d", 
2733                     ChrPtr(er_name), 
2734                     er_num_type, 
2735                     ChrPtr(er_password), 
2736                     er_floor, 
2737                     0, 
2738                     er_view);
2739
2740         serv_getln(buf, sizeof buf);
2741         if (buf[0] != '2') {
2742                 strcpy(WC->ImportantMessage, &buf[4]);
2743                 display_main_menu();
2744                 return;
2745         }
2746         /** TODO: Room created, now udate the left hand icon bar for this user */
2747         burn_folder_cache(0);   /* burn the old folder cache */
2748         
2749         
2750         gotoroom(er_name);
2751         do_change_view(er_view);                /* Now go there */
2752 }
2753
2754
2755 /**
2756  * \brief display the screen to enter a private room
2757  */
2758 void display_private(char *rname, int req_pass)
2759 {
2760         WCTemplputParams SubTP;
2761         StrBuf *Buf;
2762         output_headers(1, 1, 1, 0, 0, 0);
2763
2764         Buf = NewStrBufPlain(_("Go to a hidden room"), -1);
2765         memset(&SubTP, 0, sizeof(WCTemplputParams));
2766         SubTP.Filter.ContextType = CTX_STRBUF;
2767         SubTP.Context = Buf;
2768         DoTemplate(HKEY("beginbox"), NULL, &SubTP);
2769
2770         FreeStrBuf(&Buf);
2771
2772         wprintf("<p>");
2773         wprintf(_("If you know the name of a hidden (guess-name) or "
2774                   "passworded room, you can enter that room by typing "
2775                   "its name below.  Once you gain access to a private "
2776                   "room, it will appear in your regular room listings "
2777                   "so you don't have to keep returning here."));
2778         wprintf("</p>");
2779
2780         wprintf("<form method=\"post\" action=\"goto_private\">\n");
2781         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
2782
2783         wprintf("<table class=\"altern\"> "
2784                 "<tr class=\"even\"><td>");
2785         wprintf(_("Enter room name:"));
2786         wprintf("</td><td>"
2787                 "<input type=\"text\" name=\"gr_name\" "
2788                 "value=\"%s\" maxlength=\"128\">\n", rname);
2789
2790         if (req_pass) {
2791                 wprintf("</td></tr><tr class=\"odd\"><td>");
2792                 wprintf(_("Enter room password:"));
2793                 wprintf("</td><td>");
2794                 wprintf("<input type=\"password\" name=\"gr_pass\" maxlength=\"9\">\n");
2795         }
2796         wprintf("</td></tr></table>\n");
2797
2798         wprintf("<div class=\"buttons\">\n");
2799         wprintf("<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
2800                 "&nbsp;"
2801                 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">",
2802                 _("Go there"),
2803                 _("Cancel")
2804                 );
2805         wprintf("</div></form>\n");
2806
2807         do_template("endbox", NULL);
2808
2809         wDumpContent(1);
2810 }
2811
2812 /**
2813  * \brief goto a private room
2814  */
2815 void goto_private(void)
2816 {
2817         char hold_rm[SIZ];
2818         char buf[SIZ];
2819
2820         if (!havebstr("ok_button")) {
2821                 display_main_menu();
2822                 return;
2823         }
2824         strcpy(hold_rm, ChrPtr(WC->wc_roomname));
2825         serv_printf("GOTO %s|%s",
2826                     bstr("gr_name"),
2827                     bstr("gr_pass"));
2828         serv_getln(buf, sizeof buf);
2829
2830         if (buf[0] == '2') {
2831                 smart_goto(sbstr("gr_name"));
2832                 return;
2833         }
2834         if (!strncmp(buf, "540", 3)) {
2835                 display_private(bstr("gr_name"), 1);
2836                 return;
2837         }
2838         output_headers(1, 1, 1, 0, 0, 0);
2839         wprintf("%s\n", &buf[4]);
2840         wDumpContent(1);
2841         return;
2842 }
2843
2844
2845 /**
2846  * \brief display the screen to zap a room
2847  */
2848 void display_zap(void)
2849 {
2850         output_headers(1, 1, 2, 0, 0, 0);
2851
2852         wprintf("<div id=\"banner\">\n");
2853         wprintf("<h1>");
2854         wprintf(_("Zap (forget/unsubscribe) the current room"));
2855         wprintf("</h1>\n");
2856         wprintf("</div>\n");
2857
2858         wprintf("<div id=\"content\" class=\"service\">\n");
2859
2860         wprintf(_("If you select this option, <em>%s</em> will "
2861                   "disappear from your room list.  Is this what you wish "
2862                   "to do?<br />\n"), ChrPtr(WC->wc_roomname));
2863
2864         wprintf("<form method=\"POST\" action=\"zap\">\n");
2865         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
2866         wprintf("<input type=\"submit\" NAME=\"ok_button\" VALUE=\"%s\">", _("Zap this room"));
2867         wprintf("&nbsp;");
2868         wprintf("<input type=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
2869         wprintf("</form>\n");
2870         wDumpContent(1);
2871 }
2872
2873
2874 /**
2875  * \brief zap a room
2876  */
2877 void zap(void)
2878 {
2879         char buf[SIZ];
2880         StrBuf *final_destination;
2881
2882         /**
2883          * If the forget-room routine fails for any reason, we fall back
2884          * to the current room; otherwise, we go to the Lobby
2885          */
2886         final_destination = NewStrBufDup(WC->wc_roomname);
2887
2888         if (havebstr("ok_button")) {
2889                 serv_printf("GOTO %s", ChrPtr(WC->wc_roomname));
2890                 serv_getln(buf, sizeof buf);
2891                 if (buf[0] == '2') {
2892                         serv_puts("FORG");
2893                         serv_getln(buf, sizeof buf);
2894                         if (buf[0] == '2') {
2895                                 FlushStrBuf(final_destination);
2896                                 StrBufAppendBufPlain(final_destination, HKEY("_BASEROOM_"), 0);
2897                         }
2898                 }
2899         }
2900         smart_goto(final_destination);
2901         FreeStrBuf(&final_destination);
2902 }
2903
2904
2905
2906 /**
2907  * \brief Delete the current room
2908  */
2909 void delete_room(void)
2910 {
2911         char buf[SIZ];
2912
2913         
2914         serv_puts("KILL 1");
2915         serv_getln(buf, sizeof buf);
2916         burn_folder_cache(0);   /* Burn the cahce of known rooms to update the icon bar */
2917         if (buf[0] != '2') {
2918                 strcpy(WC->ImportantMessage, &buf[4]);
2919                 display_main_menu();
2920                 return;
2921         } else {
2922                 StrBuf *Buf;
2923                 
2924                 Buf = NewStrBufPlain(HKEY("_BASEROOM_"));
2925                 smart_goto(Buf);
2926                 FreeStrBuf(&Buf);
2927         }
2928 }
2929
2930
2931
2932 /**
2933  * \brief Perform changes to a room's network configuration
2934  */
2935 void netedit(void) {
2936         FILE *fp;
2937         char buf[SIZ];
2938         char line[SIZ];
2939         char cmpa0[SIZ];
2940         char cmpa1[SIZ];
2941         char cmpb0[SIZ];
2942         char cmpb1[SIZ];
2943         int i, num_addrs;
2944         /*/ TODO: do line dynamic! */
2945         if (havebstr("line_pop3host")) {
2946                 strcpy(line, bstr("prefix"));
2947                 strcat(line, bstr("line_pop3host"));
2948                 strcat(line, "|");
2949                 strcat(line, bstr("line_pop3user"));
2950                 strcat(line, "|");
2951                 strcat(line, bstr("line_pop3pass"));
2952                 strcat(line, "|");
2953                 strcat(line, ibstr("line_pop3keep") ? "1" : "0" );
2954                 strcat(line, "|");
2955                 sprintf(&line[strlen(line)],"%ld", lbstr("line_pop3int"));
2956                 strcat(line, bstr("suffix"));
2957         }
2958         else if (havebstr("line")) {
2959                 strcpy(line, bstr("prefix"));
2960                 strcat(line, bstr("line"));
2961                 strcat(line, bstr("suffix"));
2962         }
2963         else {
2964                 display_editroom();
2965                 return;
2966         }
2967
2968
2969         fp = tmpfile();
2970         if (fp == NULL) {
2971                 display_editroom();
2972                 return;
2973         }
2974
2975         serv_puts("GNET");
2976         serv_getln(buf, sizeof buf);
2977         if (buf[0] != '1') {
2978                 fclose(fp);
2979                 display_editroom();
2980                 return;
2981         }
2982
2983         /** This loop works for add *or* remove.  Spiffy, eh? */
2984         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2985                 extract_token(cmpa0, buf, 0, '|', sizeof cmpa0);
2986                 extract_token(cmpa1, buf, 1, '|', sizeof cmpa1);
2987                 extract_token(cmpb0, line, 0, '|', sizeof cmpb0);
2988                 extract_token(cmpb1, line, 1, '|', sizeof cmpb1);
2989                 if ( (strcasecmp(cmpa0, cmpb0)) 
2990                      || (strcasecmp(cmpa1, cmpb1)) ) {
2991                         fprintf(fp, "%s\n", buf);
2992                 }
2993         }
2994
2995         rewind(fp);
2996         serv_puts("SNET");
2997         serv_getln(buf, sizeof buf);
2998         if (buf[0] != '4') {
2999                 fclose(fp);
3000                 display_editroom();
3001                 return;
3002         }
3003
3004         while (fgets(buf, sizeof buf, fp) != NULL) {
3005                 buf[strlen(buf)-1] = 0;
3006                 serv_puts(buf);
3007         }
3008
3009         if (havebstr("add_button")) {
3010                 num_addrs = num_tokens(bstr("line"), ',');
3011                 if (num_addrs < 2) {
3012                         /* just adding one node or address */
3013                         serv_puts(line);
3014                 }
3015                 else {
3016                         /* adding multiple addresses separated by commas */
3017                         for (i=0; i<num_addrs; ++i) {
3018                                 strcpy(line, bstr("prefix"));
3019                                 extract_token(buf, bstr("line"), i, ',', sizeof buf);
3020                                 striplt(buf);
3021                                 strcat(line, buf);
3022                                 strcat(line, bstr("suffix"));
3023                                 serv_puts(line);
3024                         }
3025                 }
3026         }
3027
3028         serv_puts("000");
3029         fclose(fp);
3030         display_editroom();
3031 }
3032
3033
3034
3035 /**
3036  * \brief Convert a room name to a folder-ish-looking name.
3037  * \param folder the folderish name
3038  * \param room the room name
3039  * \param floor the floor name
3040  * \param is_mailbox is it a mailbox?
3041  */
3042 void room_to_folder(char *folder, char *room, int floor, int is_mailbox)
3043 {
3044         int i, len;
3045
3046         /**
3047          * For mailboxes, just do it straight...
3048          */
3049         if (is_mailbox) {
3050                 sprintf(folder, "My folders|%s", room);
3051         }
3052
3053         /**
3054          * Otherwise, prefix the floor name as a "public folders" moniker
3055          */
3056         else {
3057                 if (floor > MAX_FLOORS) {
3058                         wc_backtrace ();
3059                         sprintf(folder, "%%%%%%|%s", room);
3060                 }
3061                 else {
3062                         sprintf(folder, "%s|%s", floorlist[floor], room);
3063                 }
3064         }
3065
3066         /**
3067          * Replace "\" characters with "|" for pseudo-folder-delimiting
3068          */
3069         len = strlen (folder);
3070         for (i=0; i<len; ++i) {
3071                 if (folder[i] == '\\') folder[i] = '|';
3072         }
3073 }
3074
3075
3076
3077
3078 /**
3079  * \brief Back end for change_view()
3080  * \param newview set newview???
3081  */
3082 void do_change_view(int newview) {
3083         char buf[SIZ];
3084
3085         serv_printf("VIEW %d", newview);
3086         serv_getln(buf, sizeof buf);
3087         WC->wc_view = newview;
3088         smart_goto(WC->wc_roomname);
3089 }
3090
3091
3092
3093 /**
3094  * \brief Change the view for this room
3095  */
3096 void change_view(void) {
3097         int view;
3098
3099         view = lbstr("view");
3100         do_change_view(view);
3101 }
3102
3103
3104 /**
3105  * \brief One big expanded tree list view --- like a folder list
3106  * \param fold the folder to view
3107  * \param max_folders how many folders???
3108  * \param num_floors hom many floors???
3109  */
3110 void do_folder_view(struct folder *fold, int max_folders, int num_floors) {
3111         char buf[SIZ];
3112         int levels;
3113         int i;
3114         int has_subfolders = 0;
3115         int *parents;
3116
3117         parents = malloc(max_folders * sizeof(int));
3118
3119         /** BEGIN TREE MENU */
3120         wprintf("<div id=\"roomlist_div\">Loading folder list...</div>\n");
3121
3122         /** include NanoTree */
3123         wprintf("<script type=\"text/javascript\" src=\"static/nanotree.js\"></script>\n");
3124
3125         /** initialize NanoTree */
3126         wprintf("<script type=\"text/javascript\">                      \n"
3127                 "       showRootNode = false;                           \n"
3128                 "       sortNodes = false;                              \n"
3129                 "       dragable = false;                               \n"
3130                 "                                                       \n"
3131                 "       function standardClick(treeNode) {              \n"
3132                 "       }                                               \n"
3133                 "                                                       \n"
3134                 "       var closedGif = 'static/folder_closed.gif';     \n"
3135                 "       var openGif = 'static/folder_open.gif';         \n"
3136                 "                                                       \n"
3137                 "       rootNode = new TreeNode(1, 'root node - hide'); \n"
3138                 );
3139
3140         levels = 0;
3141         for (i=0; i<max_folders; ++i) {
3142
3143                 has_subfolders = 0;
3144                 if ((i+1) < max_folders) {
3145                         int len;
3146                         len = strlen(fold[i].name);
3147                         if ( (!strncasecmp(fold[i].name, fold[i+1].name, len))
3148                              && (fold[i+1].name[len] == '|') ) {
3149                                 has_subfolders = 1;
3150                         }
3151                 }
3152
3153                 levels = num_tokens(fold[i].name, '|');
3154                 parents[levels] = i;
3155
3156                 wprintf("var node%d = new TreeNode(%d, '", i, i);
3157
3158                 if (fold[i].selectable) {
3159                         wprintf("<a href=\"dotgoto?room=");
3160                         urlescputs(fold[i].room);
3161                         wprintf("\">");
3162                 }
3163
3164                 if (levels == 1) {
3165                         wprintf("<span class=\"roomlist_floor\">");
3166                 }
3167                 else if (fold[i].hasnewmsgs) {
3168                         wprintf("<span class=\"roomlist_new\">");
3169                 }
3170                 else {
3171                         wprintf("<span class=\"roomlist_old\">");
3172                 }
3173                 extract_token(buf, fold[i].name, levels-1, '|', sizeof buf);
3174                 escputs(buf);
3175                 wprintf("</span>");
3176
3177                 wprintf("</a>', ");
3178                 if (has_subfolders) {
3179                         wprintf("new Array(closedGif, openGif)");
3180                 }
3181                 else if (fold[i].view == VIEW_ADDRESSBOOK) {
3182                         wprintf("'static/viewcontacts_16x.gif'");
3183                 }
3184                 else if (fold[i].view == VIEW_CALENDAR) {
3185                         wprintf("'static/calarea_16x.gif'");
3186                 }
3187                 else if (fold[i].view == VIEW_CALBRIEF) {
3188                         wprintf("'static/calarea_16x.gif'");
3189                 }
3190                 else if (fold[i].view == VIEW_TASKS) {
3191                         wprintf("'static/taskmanag_16x.gif'");
3192                 }
3193                 else if (fold[i].view == VIEW_NOTES) {
3194                         wprintf("'static/storenotes_16x.gif'");
3195                 }
3196                 else if (fold[i].view == VIEW_MAILBOX) {
3197                         wprintf("'static/privatemess_16x.gif'");
3198                 }
3199                 else {
3200                         wprintf("'static/chatrooms_16x.gif'");
3201                 }
3202                 wprintf(", '");
3203                 urlescputs(fold[i].name);
3204                 wprintf("');\n");
3205
3206                 if (levels < 2) {
3207                         wprintf("rootNode.addChild(node%d);\n", i);
3208                 }
3209                 else {
3210                         wprintf("node%d.addChild(node%d);\n", parents[levels-1], i);
3211                 }
3212         }
3213
3214         wprintf("container = document.getElementById('roomlist_div');   \n"
3215                 "showTree('');  \n"
3216                 "</script>\n"
3217                 );
3218
3219         free(parents);
3220         /** END TREE MENU */
3221 }
3222
3223 /**
3224  * \brief Boxes and rooms and lists ... oh my!
3225  * \param fold the folder to view
3226  * \param max_folders how many folders???
3227  * \param num_floors hom many floors???
3228  */
3229 void do_rooms_view(struct folder *fold, int max_folders, int num_floors) {
3230         char buf[256];
3231         char floor_name[256];
3232         char old_floor_name[256];
3233         int levels, oldlevels;
3234         int i, t;
3235         int num_boxes = 0;
3236         static int columns = 3;
3237         int boxes_per_column = 0;
3238         int current_column = 0;
3239         int nf;
3240
3241         strcpy(floor_name, "");
3242         strcpy(old_floor_name, "");
3243
3244         nf = num_floors;
3245         while (nf % columns != 0) ++nf;
3246         boxes_per_column = (nf / columns);
3247         if (boxes_per_column < 1) boxes_per_column = 1;
3248
3249         /** Outer table (for columnization) */
3250         wprintf("<table BORDER=0 WIDTH=96%% CELLPADDING=5>"
3251                 "<tr><td valign=top>");
3252
3253         levels = 0;
3254         oldlevels = 0;
3255         for (i=0; i<max_folders; ++i) {
3256
3257                 levels = num_tokens(fold[i].name, '|');
3258                 extract_token(floor_name, fold[i].name, 0,
3259                               '|', sizeof floor_name);
3260
3261                 if ( (strcasecmp(floor_name, old_floor_name))
3262                      && (!IsEmptyStr(old_floor_name)) ) {
3263                         /* End inner box */
3264                         do_template("endbox", NULL);
3265                         wprintf("<br>");
3266
3267                         ++num_boxes;
3268                         if ((num_boxes % boxes_per_column) == 0) {
3269                                 ++current_column;
3270                                 if (current_column < columns) {
3271                                         wprintf("</td><td valign=top>\n");
3272                                 }
3273                         }
3274                 }
3275                 strcpy(old_floor_name, floor_name);
3276
3277                 if (levels == 1) {
3278                         StrBuf *Buf;
3279                         WCTemplputParams SubTP;
3280
3281                         Buf = NewStrBufPlain(floor_name, -1);
3282                         memset(&SubTP, 0, sizeof(WCTemplputParams));
3283                         SubTP.Filter.ContextType = CTX_STRBUF;
3284                         SubTP.Context = Buf;
3285                         DoTemplate(HKEY("beginbox"), NULL, &SubTP);
3286                         
3287                         FreeStrBuf(&Buf);
3288                 }
3289
3290                 oldlevels = levels;
3291
3292                 if (levels > 1) {
3293                         wprintf("&nbsp;");
3294                         if (levels>2) for (t=0; t<(levels-2); ++t) wprintf("&nbsp;&nbsp;&nbsp;");
3295                         if (fold[i].selectable) {
3296                                 wprintf("<a href=\"dotgoto?room=");
3297                                 urlescputs(fold[i].room);
3298                                 wprintf("\">");
3299                         }
3300                         else {
3301                                 wprintf("<i>");
3302                         }
3303                         if (fold[i].hasnewmsgs) {
3304                                 wprintf("<span class=\"roomlist_new\">");
3305                         }
3306                         else {
3307                                 wprintf("<span class=\"roomlist_old\">");
3308                         }
3309                         extract_token(buf, fold[i].name, levels-1, '|', sizeof buf);
3310                         escputs(buf);
3311                         wprintf("</span>");
3312                         if (fold[i].selectable) {
3313                                 wprintf("</A>");
3314                         }
3315                         else {
3316                                 wprintf("</i>");
3317                         }
3318                         if (!strcasecmp(fold[i].name, "My Folders|Mail")) {
3319                                 wprintf(" (INBOX)");
3320                         }
3321                         wprintf("<br />\n");
3322                 }
3323         }
3324         /** End the final inner box */
3325         do_template("endbox", NULL);
3326
3327         wprintf("</td></tr></table>\n");
3328 }
3329
3330 /**
3331  * \brief print a floor div???
3332  * \param which_floordiv name of the floordiv???
3333  */
3334 void set_floordiv_expanded(void) {
3335         wcsession *WCC = WC;
3336         StrBuf *FloorDiv;
3337         
3338         FloorDiv = NewStrBuf();
3339         StrBufExtract_token(FloorDiv, WCC->Hdr->HR.ReqLine, 0, '/');
3340         set_preference("floordiv_expanded", FloorDiv, 1);
3341         WCC->floordiv_expanded = FloorDiv;
3342 }
3343
3344 /**
3345  * \brief view the iconbar
3346  * \param fold the folder to view
3347  * \param max_folders how many folders???
3348  * \param num_floors hom many floors???
3349  */
3350 void do_iconbar_view(struct folder *fold, int max_folders, int num_floors) {
3351         char buf[256];
3352         char floor_name[256];
3353         char old_floor_name[256];
3354         char floordivtitle[256];
3355         char floordiv_id[32];
3356         int levels, oldlevels;
3357         int i, t;
3358         char *icon = NULL;
3359
3360         strcpy(floor_name, "");
3361         strcpy(old_floor_name, "");
3362
3363         levels = 0;
3364         oldlevels = 0;
3365         for (i=0; i<max_folders; ++i) {
3366
3367                 levels = num_tokens(fold[i].name, '|');
3368                 extract_token(floor_name, fold[i].name, 0,
3369                               '|', sizeof floor_name);
3370
3371                 if ( (strcasecmp(floor_name, old_floor_name))
3372                      && (!IsEmptyStr(old_floor_name)) ) {
3373                         /** End inner box */
3374                         wprintf("<br>\n");
3375                         wprintf("</div>\n");    /** floordiv */
3376                 }
3377                 strcpy(old_floor_name, floor_name);
3378
3379                 if (levels == 1) {
3380                         /** Begin floor */
3381                         stresc(floordivtitle, 256, floor_name, 0, 0);
3382                         sprintf(floordiv_id, "floordiv%d", i);
3383                         wprintf("<span class=\"ib_roomlist_floor\" "
3384                                 "onClick=\"expand_floor('%s')\">"
3385                                 "%s</span><br>\n", floordiv_id, floordivtitle);
3386                         wprintf("<div id=\"%s\" style=\"display:%s\">",
3387                                 floordiv_id,
3388                                 (!strcasecmp(floordiv_id, ChrPtr(WC->floordiv_expanded)) ? "block" : "none")
3389                                 );
3390                 }
3391
3392                 oldlevels = levels;
3393
3394                 if (levels > 1) {
3395                         wprintf("<div id=\"roomdiv%d\">", i);
3396                         wprintf("&nbsp;");
3397                         if (levels>2) for (t=0; t<(levels-2); ++t) wprintf("&nbsp;");
3398
3399                         /** choose the icon */
3400                         if (fold[i].view == VIEW_ADDRESSBOOK) {
3401                                 icon = "viewcontacts_16x.gif" ;
3402                         }
3403                         else if (fold[i].view == VIEW_CALENDAR) {
3404                                 icon = "calarea_16x.gif" ;
3405                         }
3406                         else if (fold[i].view == VIEW_CALBRIEF) {
3407                                 icon = "calarea_16x.gif" ;
3408                         }
3409                         else if (fold[i].view == VIEW_TASKS) {
3410                                 icon = "taskmanag_16x.gif" ;
3411                         }
3412                         else if (fold[i].view == VIEW_NOTES) {
3413                                 icon = "storenotes_16x.gif" ;
3414                         }
3415                         else if (fold[i].view == VIEW_MAILBOX) {
3416                                 icon = "privatemess_16x.gif" ;
3417                         }
3418                         else {
3419                                 icon = "chatrooms_16x.gif" ;
3420                         }
3421
3422                         if (fold[i].selectable) {
3423                                 wprintf("<a href=\"dotgoto?room=");
3424                                 urlescputs(fold[i].room);
3425                                 wprintf("\">");
3426                                 wprintf("<img  border=0 src=\"static/%s\" alt=\"\"> ", icon);
3427                         }
3428                         else {
3429                                 wprintf("<i>");
3430                         }
3431                         if (fold[i].hasnewmsgs) {
3432                                 wprintf("<span class=\"ib_roomlist_new\">");
3433                         }
3434                         else {
3435                                 wprintf("<span class=\"ib_roomlist_old\">");
3436                         }
3437                         extract_token(buf, fold[i].name, levels-1, '|', sizeof buf);
3438                         escputs(buf);
3439                         if (!strcasecmp(fold[i].name, "My Folders|Mail")) {
3440                                 wprintf(" (INBOX)");
3441                         }
3442                         wprintf("</span>");
3443                         if (fold[i].selectable) {
3444                                 wprintf("</A>");
3445                         }
3446                         else {
3447                                 wprintf("</i>");
3448                         }
3449                         wprintf("<br />");
3450                         wprintf("</div>\n");    /** roomdiv */
3451                 }
3452         }
3453         wprintf("</div>\n");    /** floordiv */
3454
3455
3456 }
3457
3458
3459
3460 /**
3461  * \brief Burn the cached folder list.  
3462  * \param age How old the cahce needs to be before we burn it.
3463  */
3464
3465 void burn_folder_cache(time_t age)
3466 {
3467         /** If our cached folder list is very old, burn it. */
3468         if (WC->cache_fold != NULL) {
3469                 if ((time(NULL) - WC->cache_timestamp) > age) {
3470                         free(WC->cache_fold);
3471                         WC->cache_fold = NULL;
3472                 }
3473         }
3474 }
3475
3476
3477
3478
3479 /**
3480  * \brief Show the room list.  
3481  * (only should get called by
3482  * knrooms() because that's where output_headers() is called from)
3483  * \param viewpref the view preferences???
3484  */
3485
3486 void list_all_rooms_by_floor(const char *viewpref) {
3487         StrBuf *Buf;
3488         char buf[SIZ];
3489         int swap = 0;
3490         struct folder *fold = NULL;
3491         struct folder ftmp;
3492         int max_folders = 0;
3493         int alloc_folders = 0;
3494         int *floor_mapping;
3495         int IDMax;
3496         int i, j;
3497         int ShowEmptyFloors;
3498         int ra_flags = 0;
3499         int flags = 0;
3500         int num_floors = 1;     /** add an extra one for private folders */
3501         char buf3[SIZ];
3502         
3503         /** If our cached folder list is very old, burn it. */
3504         burn_folder_cache(300);
3505         
3506         /** Can we do the iconbar roomlist from cache? */
3507         if ((WC->cache_fold != NULL) && (!strcasecmp(viewpref, "iconbar"))) {
3508                 do_iconbar_view(WC->cache_fold, WC->cache_max_folders, WC->cache_num_floors);
3509                 return;
3510         }
3511         Buf = NewStrBuf();
3512
3513         /** Grab the floor table so we know how to build the list... */
3514         load_floorlist(Buf);
3515         FreeStrBuf(&Buf);
3516         /** Start with the mailboxes */
3517         max_folders = 1;
3518         alloc_folders = 1;
3519         fold = malloc(sizeof(struct folder));
3520         memset(fold, 0, sizeof(struct folder));
3521         strcpy(fold[0].name, "My folders");
3522         fold[0].is_mailbox = 1;
3523
3524         /** Then add floors */
3525         serv_puts("LFLR");
3526         serv_getln(buf, sizeof buf);
3527         if (buf[0]=='1') while(serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3528                         if (max_folders >= alloc_folders) {
3529                                 alloc_folders = max_folders + 100;
3530                                 fold = realloc(fold,
3531                                                alloc_folders * sizeof(struct folder));
3532                         }
3533                         memset(&fold[max_folders], 0, sizeof(struct folder));
3534                         extract_token(fold[max_folders].name, buf, 1, '|', sizeof fold[max_folders].name);
3535                         extract_token(buf3, buf, 0, '|', SIZ);
3536                         fold[max_folders].floor = atol (buf3);
3537                         ++max_folders;
3538                         ++num_floors;
3539                 }
3540         IDMax = 0;
3541         for (i=0; i<num_floors; i++)
3542                 if (IDMax < fold[i].floor)
3543                         IDMax = fold[i].floor;
3544         floor_mapping = malloc (sizeof (int) * (IDMax + 1));
3545         memset (floor_mapping, 0, sizeof (int) * (IDMax + 1));
3546         for (i=0; i<num_floors; i++)
3547                 floor_mapping[fold[i].floor]=i;
3548         
3549         /** refresh the messages index for this room */
3550 /* TODO serv_puts("GOTO ");
3551    while (serv_getln(buf, sizeof buf), strcmp(buf, "000")); */
3552         /** Now add rooms */
3553         serv_puts("LKRA");
3554         serv_getln(buf, sizeof buf);
3555         if (buf[0]=='1') while(serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3556                         if (max_folders >= alloc_folders) {
3557                                 alloc_folders = max_folders + 100;
3558                                 fold = realloc(fold,
3559                                                alloc_folders * sizeof(struct folder));
3560                         }
3561                         memset(&fold[max_folders], 0, sizeof(struct folder));
3562                         extract_token(fold[max_folders].room, buf, 0, '|', sizeof fold[max_folders].room);
3563                         ra_flags = extract_int(buf, 5);
3564                         flags = extract_int(buf, 1);
3565                         fold[max_folders].floor = extract_int(buf, 2);
3566                         fold[max_folders].hasnewmsgs =
3567                                 ((ra_flags & UA_HASNEWMSGS) ? 1 : 0 );
3568                         if (flags & QR_MAILBOX) {
3569                                 fold[max_folders].is_mailbox = 1;
3570                         }
3571                         fold[max_folders].view = extract_int(buf, 6);
3572                         room_to_folder(fold[max_folders].name,
3573                                        fold[max_folders].room,
3574                                        fold[max_folders].floor,
3575                                        fold[max_folders].is_mailbox);
3576                         fold[max_folders].selectable = 1;
3577                         /* Increase the room count for the associtaed floor */
3578                         if (fold[max_folders].is_mailbox) {
3579                                 fold[0].num_rooms++;
3580                         }
3581                         else {
3582                                 i = floor_mapping[fold[max_folders].floor];
3583                                 fold[i].num_rooms++;
3584                         }
3585                         ++max_folders;
3586                 }
3587         
3588         /*
3589          * Remove any floors that don't have rooms
3590          */
3591         get_pref_yesno("emptyfloors", &ShowEmptyFloors, 0);
3592         if (ShowEmptyFloors)
3593         {
3594                 for (i=0; i<num_floors; i++)
3595                 {
3596                         if (fold[i].num_rooms == 0) {
3597                                 for (j=i; j<max_folders; j++) {
3598                                         memcpy(&fold[j], &fold[j+1], sizeof(struct folder));
3599                                 }
3600                                 max_folders--;
3601                                 num_floors--;
3602                                 i--;
3603                         }
3604                 }
3605         }
3606         
3607         /** Bubble-sort the folder list */
3608         for (i=0; i<max_folders; ++i) {
3609                 for (j=0; j<(max_folders-1)-i; ++j) {
3610                         if (fold[j].is_mailbox == fold[j+1].is_mailbox) {
3611                                 swap = strcasecmp(fold[j].name, fold[j+1].name);
3612                         }
3613                         else {
3614                                 if ( (fold[j+1].is_mailbox)
3615                                      && (!fold[j].is_mailbox)) {
3616                                         swap = 1;
3617                                 }
3618                                 else {
3619                                         swap = 0;
3620                                 }
3621                         }
3622                         if (swap > 0) {
3623                                 memcpy(&ftmp, &fold[j], sizeof(struct folder));
3624                                 memcpy(&fold[j], &fold[j+1],
3625                                        sizeof(struct folder));
3626                                 memcpy(&fold[j+1], &ftmp,
3627                                        sizeof(struct folder));
3628                         }
3629                 }
3630         }
3631
3632
3633         if (!strcasecmp(viewpref, "folders")) {
3634                 do_folder_view(fold, max_folders, num_floors);
3635         }
3636         else if (!strcasecmp(viewpref, "hackish_view")) {
3637                 for (i=0; i<max_folders; ++i) {
3638                         escputs(fold[i].name);
3639                         wprintf("<br />\n");
3640                 }
3641         }
3642         else if (!strcasecmp(viewpref, "iconbar")) {
3643                 do_iconbar_view(fold, max_folders, num_floors);
3644         }
3645         else {
3646                 do_rooms_view(fold, max_folders, num_floors);
3647         }
3648
3649         /* Don't free the folder list ... cache it for future use! */
3650         if (WC->cache_fold != NULL) {
3651                 free(WC->cache_fold);
3652         }
3653         WC->cache_fold = fold;
3654         WC->cache_max_folders = max_folders;
3655         WC->cache_num_floors = num_floors;
3656         WC->cache_timestamp = time(NULL);
3657         free(floor_mapping);
3658 }
3659
3660
3661 /**
3662  * \brief Do either a known rooms list or a folders list, depending on the
3663  * user's preference
3664  */
3665 void knrooms(void)
3666 {
3667         StrBuf *ListView = NULL;
3668
3669         output_headers(1, 1, 2, 0, 0, 0);
3670
3671         /** Determine whether the user is trying to change views */
3672         if (havebstr("view")) {
3673                 ListView = NewStrBufPlain(bstr("view"), -1);
3674                 set_preference("roomlistview", ListView, 1);
3675         }
3676         /** Sanitize the input so its safe */
3677         if(!get_preference("roomlistview", &ListView) ||
3678            ((strcasecmp(ChrPtr(ListView), "folders") != 0) &&
3679             (strcasecmp(ChrPtr(ListView), "table") != 0))) 
3680         {
3681                 if (ListView == NULL) {
3682                         ListView = NewStrBufPlain("rooms", sizeof("rooms") - 1);
3683                         set_preference("roomlistview", ListView, 0);
3684                 }
3685                 else {
3686                         StrBufPrintf(ListView, "rooms");
3687                         save_preferences();
3688                 }
3689         }
3690
3691         /** title bar */
3692         wprintf("<div id=\"banner\">\n");
3693         wprintf("<div class=\"room_banner\" id=\"room_banner\">");
3694         wprintf("<h1>");
3695         if (!strcasecmp(ChrPtr(ListView), "rooms")) {
3696                 wprintf(_("Room list"));
3697         }
3698         else if (!strcasecmp(ChrPtr(ListView), "folders")) {
3699                 wprintf(_("Folder list"));
3700         }
3701         else if (!strcasecmp(ChrPtr(ListView), "table")) {
3702                 wprintf(_("Room list"));
3703         }
3704         wprintf("</h1></div>\n");
3705         
3706         /** offer the ability to switch views */
3707         wprintf("<div id=\"actiondiv\">");
3708         wprintf("<ul class=\"room_actions\">\n");
3709         wprintf("<li class=\"start_page\">");
3710         offer_start_page(NULL, &NoCtx);
3711         wprintf("</li>");
3712         wprintf("<li><form name=\"roomlistomatic\">\n"
3713                 "<select name=\"newview\" size=\"1\" "
3714                 "OnChange=\"location.href=roomlistomatic.newview.options"
3715                 "[selectedIndex].value\">\n");
3716
3717         wprintf("<option %s value=\"knrooms?view=rooms\">"
3718                 "View as room list"
3719                 "</option>\n",
3720                 ( !strcasecmp(ChrPtr(ListView), "rooms") ? "SELECTED" : "" )
3721                 );
3722
3723         wprintf("<option %s value=\"knrooms?view=folders\">"
3724                 "View as folder list"
3725                 "</option>\n",
3726                 ( !strcasecmp(ChrPtr(ListView), "folders") ? "SELECTED" : "" )
3727                 );
3728
3729         wprintf("</select>");
3730         wprintf("</form></li>");
3731         wprintf("</ul></div></div>\n");
3732
3733         wprintf("<div id=\"content\" class=\"service\">\n");
3734
3735         /** Display the room list in the user's preferred format */
3736         list_all_rooms_by_floor(ChrPtr(ListView));
3737         wDumpContent(1);
3738 }
3739
3740
3741
3742 /**
3743  * \brief Set the message expire policy for this room and/or floor
3744  */
3745 void set_room_policy(void) {
3746         char buf[SIZ];
3747
3748         if (!havebstr("ok_button")) {
3749                 strcpy(WC->ImportantMessage,
3750                        _("Cancelled.  Changes were not saved."));
3751                 display_editroom();
3752                 return;
3753         }
3754
3755         serv_printf("SPEX room|%d|%d", ibstr("roompolicy"), ibstr("roomvalue"));
3756         serv_getln(buf, sizeof buf);
3757         strcpy(WC->ImportantMessage, &buf[4]);
3758
3759         if (WC->axlevel >= 6) {
3760                 strcat(WC->ImportantMessage, "<br />\n");
3761                 serv_printf("SPEX floor|%d|%d", ibstr("floorpolicy"), ibstr("floorvalue"));
3762                 serv_getln(buf, sizeof buf);
3763                 strcat(WC->ImportantMessage, &buf[4]);
3764         }
3765
3766         display_editroom();
3767 }
3768
3769 HashList *GetFloorListHash(StrBuf *Target, WCTemplputParams *TP) {
3770         /* todo: check context */
3771         const char *Err;
3772         StrBuf *Buf;
3773         StrBuf *Buf2;
3774         HashList *floors;
3775         HashList *floor;
3776         floors = NewHash(1, NULL);
3777         Buf = NewStrBuf();
3778         serv_puts("LFLR"); /* get floors */
3779         StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err); /* '100', we hope */
3780         if (GetServerStatus(Buf, NULL) == 1) 
3781                 while(StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err), strcmp(ChrPtr(Buf), "000")) {
3782                         int a;
3783                         const StrBuf *floorNum = NULL;
3784                         floor = NewHash(1, NULL);
3785                         for(a=0; a<FLOOR_PARAM_LEN; a++) {
3786                                 Buf2 = NewStrBuf();
3787                                 StrBufExtract_token(Buf2, Buf, a, '|');
3788                                 if (a==0) {
3789                                         floorNum = Buf2; /* hmm, should we copy Buf2 first? */
3790                                         
3791                                 }
3792                                 Put(floor, CKEY(FLOOR_PARAM_NAMES[a]), Buf2, HFreeStrBuf);
3793                         }
3794                         Put(floors, SKEY(floorNum), floor, HDeleteHash);
3795                 }
3796         FreeStrBuf(&Buf);
3797         return floors;
3798 }
3799
3800 void tmplput_FLOOR_Value(StrBuf *TemplBuffer, WCTemplputParams *TP) 
3801 {
3802         StrBuf *val;
3803         HashList *floor = (HashList *)(TP->Context);
3804         void *value;
3805         GetHash(floor, TKEY(0), &value);
3806         val = (StrBuf *)value;
3807         StrECMAEscAppend(TemplBuffer, val, 0);
3808 }
3809 HashList *GetRoomListHashLKRA(StrBuf *Target, WCTemplputParams *TP) 
3810 {
3811         serv_puts("LKRA");
3812         return GetRoomListHash(Target, TP);
3813 }
3814 HashList *GetRoomListHash(StrBuf *Target, WCTemplputParams *TP) 
3815 {
3816         /* TODO: Check context */
3817         HashList *rooms;
3818         HashList *room;
3819         StrBuf *buf;
3820         StrBuf *buf2;
3821         const char *Err;
3822         buf = NewStrBuf();
3823         rooms = NewHash(1, NULL);
3824         StrBufTCP_read_line(buf, &WC->serv_sock, 0, &Err);
3825         if (GetServerStatus(buf, NULL) == 1) 
3826                 while(StrBufTCP_read_line(buf, &WC->serv_sock, 0, &Err), strcmp(ChrPtr(buf), "000")) {
3827                         int i;
3828                         StrBuf *rmName = NULL;
3829                         room = NewHash(1, NULL);
3830                         for(i=0; i<ROOM_PARAM_LEN; i++) {
3831                                 buf2 = NewStrBuf();
3832                                 StrBufExtract_token(buf2, buf, i, '|');
3833                                 if (i==0) {
3834                                         rmName = buf2;
3835                                 }
3836                                 Put(room, CKEY(ROOM_PARAM_NAMES[i]), buf2, HFreeStrBuf);
3837                         }
3838                         Put(rooms, SKEY(rmName), room, HDeleteHash);
3839                 }
3840         SortByHashKey(rooms, 1);
3841         /*SortByPayload(rooms, SortRoomsByListOrder);  */
3842         FreeStrBuf(&buf);
3843         return rooms;
3844 }
3845 /** Unused function that orders rooms by the listorder flag */
3846 int SortRoomsByListOrder(const void *room1, const void *room2) 
3847 {
3848         int l1;
3849         int l2;
3850         HashList *r1 = (HashList *)GetSearchPayload(room1);
3851         HashList *r2 = (HashList *)GetSearchPayload(room2);
3852         StrBuf *listOrderBuf1;
3853         StrBuf *listOrderBuf2;
3854   
3855         GetHash(r1, CKEY(ROOM_PARAM_NAMES[3]), (void *)&listOrderBuf1);
3856         GetHash(r2, CKEY(ROOM_PARAM_NAMES[3]), (void *)&listOrderBuf2);
3857         l1 = atoi(ChrPtr(listOrderBuf1));
3858         l2 = atoi(ChrPtr(listOrderBuf2));
3859         if (l1 < l2) return -1;
3860         else if (l1 > l2) return +1;
3861         else return 0;
3862 }
3863 void tmplput_ROOM_Value(StrBuf *TemplBuffer, WCTemplputParams *TP) 
3864 {
3865         void *value;
3866         StrBuf *val;
3867         HashList *room = (HashList *)(TP->Context);
3868
3869         GetHash(room, TKEY(0), &value);
3870         val = (StrBuf *)value;
3871         StrECMAEscAppend(TemplBuffer, val, 0);
3872 }
3873 void jsonRoomFlr(void) 
3874 {
3875         /* Send as our own (application/json) content type */
3876         hprintf("HTTP/1.1 200 OK\r\n");
3877         hprintf("Content-type: application/json; charset=utf-8\r\n");
3878         hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
3879         hprintf("Connection: close\r\n");
3880         hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
3881         begin_burst();
3882         DoTemplate(HKEY("json_roomflr"),NULL,&NoCtx);
3883         end_burst(); 
3884 }
3885
3886 void tmplput_RoomName(StrBuf *Target, WCTemplputParams *TP)
3887 {
3888         StrBufAppendTemplate(Target, TP, WC->wc_roomname, 0);
3889 }
3890
3891 void _gotonext(void) {
3892         slrp_highest();
3893         gotonext();
3894 }
3895
3896 void dotskip(void) {
3897         smart_goto(sbstr("room"));
3898 }
3899
3900 void _display_private(void) {
3901         display_private("", 0);
3902 }
3903
3904 void dotgoto(void) {
3905         if (!havebstr("room")) {
3906                 readloop(readnew);
3907                 return;
3908         }
3909         if (WC->wc_view != VIEW_MAILBOX) {      /* dotgoto acts like dotskip when we're in a mailbox view */
3910                 slrp_highest();
3911         }
3912         smart_goto(sbstr("room"));
3913 }
3914
3915 void tmplput_roombanner(StrBuf *Target, WCTemplputParams *TP)
3916 {
3917         wprintf("<div id=\"banner\">\n");
3918         embed_room_banner(NULL, navbar_default);
3919         wprintf("</div>\n");
3920 }
3921
3922
3923 void tmplput_ungoto(StrBuf *Target, WCTemplputParams *TP)
3924 {
3925         wcsession *WCC = WC;
3926
3927         if ((WCC!=NULL) && 
3928             (!IsEmptyStr(WCC->ugname)))
3929                 StrBufAppendBufPlain(Target, WCC->ugname, -1, 0);
3930 }
3931
3932
3933 int ConditionalHaveUngoto(StrBuf *Target, WCTemplputParams *TP)
3934 {
3935         wcsession *WCC = WC;
3936         
3937         return ((WCC!=NULL) && 
3938                 (!IsEmptyStr(WCC->ugname)) && 
3939                 (strcasecmp(WCC->ugname, ChrPtr(WCC->wc_roomname)) == 0));
3940 }
3941
3942 int ConditionalRoomHas_QR_PERMANENT(StrBuf *Target, WCTemplputParams *TP)
3943 {
3944         wcsession *WCC = WC;
3945         
3946         return ((WCC!=NULL) &&
3947                 ((WCC->room_flags & QR_PERMANENT) != 0));
3948 }
3949
3950 int ConditionalRoomHas_QR_INUSE(StrBuf *Target, WCTemplputParams *TP)
3951 {
3952         wcsession *WCC = WC;
3953         
3954         return ((WCC!=NULL) &&
3955                 ((WCC->room_flags & QR_INUSE) != 0));
3956 }
3957
3958 int ConditionalRoomHas_QR_PRIVATE(StrBuf *Target, WCTemplputParams *TP)
3959 {
3960         wcsession *WCC = WC;
3961         
3962         return ((WCC!=NULL) &&
3963                 ((WCC->room_flags & QR_PRIVATE) != 0));
3964 }
3965
3966 int ConditionalRoomHas_QR_PASSWORDED(StrBuf *Target, WCTemplputParams *TP)
3967 {
3968         wcsession *WCC = WC;
3969         
3970         return ((WCC!=NULL) &&
3971                 ((WCC->room_flags & QR_PASSWORDED) != 0));
3972 }
3973
3974 int ConditionalRoomHas_QR_GUESSNAME(StrBuf *Target, WCTemplputParams *TP)
3975 {
3976         wcsession *WCC = WC;
3977         
3978         return ((WCC!=NULL) &&
3979                 ((WCC->room_flags & QR_GUESSNAME) != 0));
3980 }
3981
3982 int ConditionalRoomHas_QR_DIRECTORY(StrBuf *Target, WCTemplputParams *TP)
3983 {
3984         wcsession *WCC = WC;
3985         
3986         return ((WCC!=NULL) &&
3987                 ((WCC->room_flags & QR_DIRECTORY) != 0));
3988 }
3989
3990 int ConditionalRoomHas_QR_UPLOAD(StrBuf *Target, WCTemplputParams *TP)
3991 {
3992         wcsession *WCC = WC;
3993         
3994         return ((WCC!=NULL) &&
3995                 ((WCC->room_flags & QR_UPLOAD) != 0));
3996 }
3997
3998 int ConditionalRoomHas_QR_DOWNLOAD(StrBuf *Target, WCTemplputParams *TP)
3999 {
4000         wcsession *WCC = WC;
4001         
4002         return ((WCC!=NULL) &&
4003                 ((WCC->room_flags & QR_DOWNLOAD) != 0));
4004 }
4005
4006 int ConditionalRoomHas_QR_VISDIR(StrBuf *Target, WCTemplputParams *TP)
4007 {
4008         wcsession *WCC = WC;
4009         
4010         return ((WCC!=NULL) &&
4011                 ((WCC->room_flags & QR_VISDIR) != 0));
4012 }
4013
4014 int ConditionalRoomHas_QR_ANONONLY(StrBuf *Target, WCTemplputParams *TP)
4015 {
4016         wcsession *WCC = WC;
4017         
4018         return ((WCC!=NULL) &&
4019                 ((WCC->room_flags & QR_ANONONLY) != 0));
4020 }
4021
4022 int ConditionalRoomHas_QR_ANONOPT(StrBuf *Target, WCTemplputParams *TP)
4023 {
4024         wcsession *WCC = WC;
4025         
4026         return ((WCC!=NULL) &&
4027                 ((WCC->room_flags & QR_ANONOPT) != 0));
4028 }
4029
4030 int ConditionalRoomHas_QR_NETWORK(StrBuf *Target, WCTemplputParams *TP)
4031 {
4032         wcsession *WCC = WC;
4033         
4034         return ((WCC!=NULL) &&
4035                 ((WCC->room_flags & QR_NETWORK) != 0));
4036 }
4037
4038 int ConditionalRoomHas_QR_PREFONLY(StrBuf *Target, WCTemplputParams *TP)
4039 {
4040         wcsession *WCC = WC;
4041         
4042         return ((WCC!=NULL) &&
4043                 ((WCC->room_flags & QR_PREFONLY) != 0));
4044 }
4045
4046 int ConditionalRoomHas_QR_READONLY(StrBuf *Target, WCTemplputParams *TP)
4047 {
4048         wcsession *WCC = WC;
4049         
4050         return ((WCC!=NULL) &&
4051                 ((WCC->room_flags & QR_READONLY) != 0));
4052 }
4053
4054 int ConditionalRoomHas_QR_MAILBOX(StrBuf *Target, WCTemplputParams *TP)
4055 {
4056         wcsession *WCC = WC;
4057         
4058         return ((WCC!=NULL) &&
4059                 ((WCC->room_flags & QR_MAILBOX) != 0));
4060 }
4061
4062
4063 int ConditionalHaveRoomeditRights(StrBuf *Target, WCTemplputParams *TP)
4064 {
4065         wcsession *WCC = WC;
4066
4067         return ( (WCC!= NULL) && 
4068                  ((WCC->axlevel >= 6) || 
4069                   (WCC->is_room_aide) || 
4070                   (WCC->is_mailbox) ));
4071 }
4072
4073 int ConditionalIsRoomtype(StrBuf *Target, WCTemplputParams *TP)
4074 {
4075         wcsession *WCC = WC;
4076
4077         if ((WCC == NULL) ||
4078             (TP->Tokens->nParameters < 3) ||
4079             (TP->Tokens->Params[2]->Type != TYPE_STR)||
4080             (TP->Tokens->Params[2]->len < 7))
4081                 return 0;
4082
4083         switch(WCC->wc_view) {
4084         case VIEW_BBS:
4085                 return (!strcasecmp(TP->Tokens->Params[2]->Start, "VIEW_BBS"));
4086         case VIEW_MAILBOX:
4087                 return (!strcasecmp(TP->Tokens->Params[2]->Start, "VIEW_MAILBOX"));
4088         case VIEW_ADDRESSBOOK:
4089                 return (!strcasecmp(TP->Tokens->Params[2]->Start, "VIEW_ADDRESSBOOK"));
4090         case VIEW_TASKS:
4091                 return (!strcasecmp(TP->Tokens->Params[2]->Start, "VIEW_TASKS"));
4092         case VIEW_NOTES:
4093                 return (!strcasecmp(TP->Tokens->Params[2]->Start, "VIEW_NOTES"));
4094         case VIEW_WIKI:
4095                 return (!strcasecmp(TP->Tokens->Params[2]->Start, "VIEW_WIKI"));
4096         case VIEW_JOURNAL:
4097                 return (!strcasecmp(TP->Tokens->Params[2]->Start, "VIEW_JOURNAL"));
4098         case VIEW_CALENDAR:
4099                 return (!strcasecmp(TP->Tokens->Params[2]->Start, "VIEW_CALENDAR"));
4100         case VIEW_CALBRIEF:
4101                 return (!strcasecmp(TP->Tokens->Params[2]->Start, "VIEW_CALBRIEF"));
4102         default:
4103                 return 0;
4104         }
4105 }
4106
4107 void 
4108 InitModule_ROOMOPS
4109 (void)
4110 {
4111         RegisterPreference("roomlistview",
4112                            _("Room list view"),
4113                            PRF_STRING,
4114                            NULL);
4115         RegisterPreference("emptyfloors", _("Show empty floors"), PRF_YESNO, NULL);
4116
4117         RegisterNamespace("ROOMNAME", 0, 1, tmplput_RoomName, 0);
4118
4119         WebcitAddUrlHandler(HKEY("knrooms"), knrooms, 0);
4120         WebcitAddUrlHandler(HKEY("gotonext"), _gotonext, NEED_URL);
4121         WebcitAddUrlHandler(HKEY("skip"), gotonext, NEED_URL);
4122         WebcitAddUrlHandler(HKEY("ungoto"), ungoto, NEED_URL);
4123         WebcitAddUrlHandler(HKEY("dotgoto"), dotgoto, NEED_URL);
4124         WebcitAddUrlHandler(HKEY("dotskip"), dotskip, NEED_URL);
4125         WebcitAddUrlHandler(HKEY("display_private"), _display_private, 0);
4126         WebcitAddUrlHandler(HKEY("goto_private"), goto_private, NEED_URL);
4127         WebcitAddUrlHandler(HKEY("zapped_list"), zapped_list, 0);
4128         WebcitAddUrlHandler(HKEY("display_zap"), display_zap, 0);
4129         WebcitAddUrlHandler(HKEY("zap"), zap, 0);
4130         WebcitAddUrlHandler(HKEY("display_entroom"), display_entroom, 0);
4131         WebcitAddUrlHandler(HKEY("entroom"), entroom, 0);
4132         WebcitAddUrlHandler(HKEY("display_whok"), display_whok, 0);
4133         WebcitAddUrlHandler(HKEY("do_invt_kick"), do_invt_kick, 0);
4134         WebcitAddUrlHandler(HKEY("display_editroom"), display_editroom, 0);
4135         WebcitAddUrlHandler(HKEY("netedit"), netedit, 0);
4136         WebcitAddUrlHandler(HKEY("editroom"), editroom, 0);
4137         WebcitAddUrlHandler(HKEY("delete_room"), delete_room, 0);
4138         WebcitAddUrlHandler(HKEY("set_room_policy"), set_room_policy, 0);
4139         WebcitAddUrlHandler(HKEY("set_floordiv_expanded"), set_floordiv_expanded, NEED_URL|AJAX);
4140         WebcitAddUrlHandler(HKEY("changeview"), change_view, 0);
4141         WebcitAddUrlHandler(HKEY("toggle_self_service"), toggle_self_service, 0);
4142         WebcitAddUrlHandler(HKEY("json_roomflr"), jsonRoomFlr, 0);
4143         RegisterNamespace("ROOMBANNER", 0, 1, tmplput_roombanner, 0);
4144
4145         RegisterConditional(HKEY("COND:ROOM:TYPE_IS"), 0, ConditionalIsRoomtype, CTX_NONE);
4146         RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_PERMANENT"), 0, ConditionalRoomHas_QR_PERMANENT, CTX_NONE);
4147         RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_INUSE"), 0, ConditionalRoomHas_QR_INUSE, CTX_NONE);
4148         RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_PRIVATE"), 0, ConditionalRoomHas_QR_PRIVATE, CTX_NONE);
4149         RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_PASSWORDED"), 0, ConditionalRoomHas_QR_PASSWORDED, CTX_NONE);
4150         RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_GUESSNAME"), 0, ConditionalRoomHas_QR_GUESSNAME, CTX_NONE);
4151         RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_DIRECTORY"), 0, ConditionalRoomHas_QR_DIRECTORY, CTX_NONE);
4152         RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_UPLOAD"), 0, ConditionalRoomHas_QR_UPLOAD, CTX_NONE);
4153         RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_DOWNLOAD"), 0, ConditionalRoomHas_QR_DOWNLOAD, CTX_NONE);
4154         RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_VISIDIR"), 0, ConditionalRoomHas_QR_VISDIR, CTX_NONE);
4155         RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_ANONONLY"), 0, ConditionalRoomHas_QR_ANONONLY, CTX_NONE);
4156         RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_ANONOPT"), 0, ConditionalRoomHas_QR_ANONOPT, CTX_NONE);
4157         RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_NETWORK"), 0, ConditionalRoomHas_QR_NETWORK, CTX_NONE);
4158         RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_PREFONLY"), 0, ConditionalRoomHas_QR_PREFONLY, CTX_NONE);
4159         RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_READONLY"), 0, ConditionalRoomHas_QR_READONLY, CTX_NONE);
4160         RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_MAILBOX"), 0, ConditionalRoomHas_QR_MAILBOX, CTX_NONE);
4161
4162         RegisterConditional(HKEY("COND:UNGOTO"), 0, ConditionalHaveUngoto, CTX_NONE);
4163         RegisterConditional(HKEY("COND:ROOM:EDITACCESS"), 0, ConditionalHaveRoomeditRights, CTX_NONE);
4164
4165         RegisterNamespace("ROOM:UNGOTO", 0, 0, tmplput_ungoto, 0);
4166         RegisterIterator("FLOORS", 0, NULL, GetFloorListHash, NULL, DeleteHash, CTX_FLOORS, CTX_NONE, IT_NOFLAG);
4167         RegisterNamespace("FLOOR:INFO", 1, 2, tmplput_FLOOR_Value, CTX_FLOORS);
4168         RegisterIterator("LKRA", 0, NULL, GetRoomListHashLKRA, NULL, DeleteHash, CTX_ROOMS, CTX_NONE, IT_NOFLAG);
4169         RegisterNamespace("ROOM:INFO", 1, 2, tmplput_ROOM_Value, CTX_ROOMS);
4170 }
4171
4172
4173
4174 void 
4175 SessionDestroyModule_ROOMOPS
4176 (wcsession *sess)
4177 {
4178         if (sess->cache_fold != NULL) {
4179                 free(sess->cache_fold);
4180         }
4181         
4182         free_march_list(sess);
4183 }
4184 /*@}*/