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