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