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