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