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