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