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