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