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