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