* Removed the last instance if is_room_aide
[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 void display_whok(void);
19 int ConditionalHaveRoomeditRights(StrBuf *Target, WCTemplputParams *TP);
20
21 /*
22  * Initialize the viewdefs with localized strings
23  */
24 void initialize_viewdefs(void) {
25         viewdefs[0] = _("Bulletin Board");
26         viewdefs[1] = _("Mail Folder");
27         viewdefs[2] = _("Address Book");
28         viewdefs[3] = _("Calendar");
29         viewdefs[4] = _("Task List");
30         viewdefs[5] = _("Notes List");
31         viewdefs[6] = _("Wiki");
32         viewdefs[7] = _("Calendar List");
33         viewdefs[8] = _("Journal");
34 }
35
36 /*
37  * Determine which views are allowed as the default for creating a new room.
38  */
39 int is_view_allowed_as_default(int which_view)
40 {
41         switch(which_view) {
42                 case VIEW_BBS:          return(1);
43                 case VIEW_MAILBOX:      return(1);
44                 case VIEW_ADDRESSBOOK:  return(1);
45                 case VIEW_CALENDAR:     return(1);
46                 case VIEW_TASKS:        return(1);
47                 case VIEW_NOTES:        return(1);
48                 case VIEW_WIKI:         return(1);
49                 case VIEW_CALBRIEF:     return(0);
50                 case VIEW_JOURNAL:      return(0);
51                 default:                return(0);      /* should never get here */
52         }
53 }
54
55
56 /*
57  * load the list of floors
58  */
59 void load_floorlist(StrBuf *Buf)
60 {
61         int a;
62         int Done = 0;
63
64         for (a = 0; a < MAX_FLOORS; ++a)
65                 floorlist[a][0] = 0;
66
67         serv_puts("LFLR");
68         StrBuf_ServGetln(Buf);
69         if (GetServerStatus(Buf, NULL) != 1) {
70                 strcpy(floorlist[0], "Main Floor");
71                 return;
72         }
73         while (!Done && (StrBuf_ServGetln(Buf)>=0)) {
74                 if ( (StrLength(Buf)==3) && 
75                      !strcmp(ChrPtr(Buf), "000")) {
76                         Done = 1;
77                         break;
78                 }
79                 extract_token(floorlist[StrBufExtract_int(Buf, 0, '|')], ChrPtr(Buf), 1, '|', sizeof floorlist[0]);
80         }
81 }
82
83
84
85
86 /*
87  * display rooms in tree structure
88  */
89 void room_tree_list(struct roomlisting *rp)
90 {
91         char rmname[64];
92         int f;
93
94         if (rp == NULL) {
95                 return;
96         }
97
98         room_tree_list(rp->lnext);
99
100         strcpy(rmname, rp->rlname);
101         f = rp->rlflags;
102
103         wc_printf("<a href=\"dotgoto?room=");
104         urlescputs(rmname);
105         wc_printf("\"");
106         wc_printf(">");
107         escputs1(rmname, 1, 1);
108         if ((f & QR_DIRECTORY) && (f & QR_NETWORK))
109                 wc_printf("}");
110         else if (f & QR_DIRECTORY)
111                 wc_printf("]");
112         else if (f & QR_NETWORK)
113                 wc_printf(")");
114         else
115                 wc_printf("&gt;");
116         wc_printf("</a><tt> </tt>\n");
117
118         room_tree_list(rp->rnext);
119         free(rp);
120 }
121
122
123 /* 
124  * Room ordering stuff (compare first by floor, then by order)
125  */
126 int rordercmp(struct roomlisting *r1, struct roomlisting *r2)
127 {
128         if ((r1 == NULL) && (r2 == NULL))
129                 return (0);
130         if (r1 == NULL)
131                 return (-1);
132         if (r2 == NULL)
133                 return (1);
134         if (r1->rlfloor < r2->rlfloor)
135                 return (-1);
136         if (r1->rlfloor > r2->rlfloor)
137                 return (1);
138         if (r1->rlorder < r2->rlorder)
139                 return (-1);
140         if (r1->rlorder > r2->rlorder)
141                 return (1);
142         return (0);
143 }
144
145
146 /*
147  * Common code for all room listings
148  */
149 void listrms(char *variety)
150 {
151         char buf[SIZ];
152         int num_rooms = 0;
153
154         struct roomlisting *rl = NULL;
155         struct roomlisting *rp;
156         struct roomlisting *rs;
157
158         /* Ask the server for a room list */
159         serv_puts(variety);
160         serv_getln(buf, sizeof buf);
161         if (buf[0] != '1') {
162                 wc_printf("&nbsp;");
163                 return;
164         }
165
166         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
167                 ++num_rooms;
168                 rp = malloc(sizeof(struct roomlisting));
169                 extract_token(rp->rlname, buf, 0, '|', sizeof rp->rlname);
170                 rp->rlflags = extract_int(buf, 1);
171                 rp->rlfloor = extract_int(buf, 2);
172                 rp->rlorder = extract_int(buf, 3);
173                 rp->lnext = NULL;
174                 rp->rnext = NULL;
175
176                 rs = rl;
177                 if (rl == NULL) {
178                         rl = rp;
179                 } else
180                         while (rp != NULL) {
181                                 if (rordercmp(rp, rs) < 0) {
182                                         if (rs->lnext == NULL) {
183                                                 rs->lnext = rp;
184                                                 rp = NULL;
185                                         } else {
186                                                 rs = rs->lnext;
187                                         }
188                                 } else {
189                                         if (rs->rnext == NULL) {
190                                                 rs->rnext = rp;
191                                                 rp = NULL;
192                                         } else {
193                                                 rs = rs->rnext;
194                                         }
195                                 }
196                         }
197         }
198
199         room_tree_list(rl);
200
201         /*
202          * If no rooms were listed, print an nbsp to make the cell
203          * borders show up anyway.
204          */
205         if (num_rooms == 0) wc_printf("&nbsp;");
206 }
207
208
209 /*
210  * list all forgotten rooms
211  */
212 void zapped_list(void)
213 {
214         WCTemplputParams SubTP;
215         StrBuf *Buf;
216
217         output_headers(1, 1, 1, 0, 0, 0);
218         memset(&SubTP, 0, sizeof(WCTemplputParams));
219         Buf = NewStrBufPlain(_("Zapped (forgotten) rooms"), -1);
220         SubTP.Filter.ContextType = CTX_STRBUF;
221         SubTP.Context = Buf;
222         DoTemplate(HKEY("beginbox"), NULL, &SubTP);
223
224         FreeStrBuf(&Buf);
225
226         listrms("LZRM -1");
227
228         wc_printf("<br /><br />\n");
229         wc_printf(_("Click on any room to un-zap it and goto that room.\n"));
230         do_template("endbox", NULL);
231         wDumpContent(1);
232 }
233
234
235 /*
236  * read this room's info file (set v to 1 for verbose mode)
237  */
238 void readinfo(StrBuf *Target, WCTemplputParams *TP)
239 {
240         char buf[256];
241         char briefinfo[128];
242         char fullinfo[8192];
243         int fullinfo_len = 0;
244
245         serv_puts("RINF");
246         serv_getln(buf, sizeof buf);
247         if (buf[0] == '1') {
248
249                 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
250                         if (fullinfo_len < (sizeof fullinfo - sizeof buf)) {
251                                 strcpy(&fullinfo[fullinfo_len], buf);
252                                 fullinfo_len += strlen(buf);
253                         }
254                 }
255
256                 safestrncpy(briefinfo, fullinfo, sizeof briefinfo);
257                 strcpy(&briefinfo[50], "...");
258
259                 wc_printf("<div class=\"infos\" "
260                         "onclick=\"javascript:Effect.Appear('room_infos', { duration: 0.5 });\" "
261                         ">"
262                 );
263                 escputs(briefinfo);
264                 wc_printf("</div><div id=\"room_infos\" style=\"display:none;\">");
265                 wc_printf("<img class=\"close_infos\" "
266                         "onclick=\"javascript:Effect.Fade('room_infos', { duration: 0.5 });\" "
267                         "src=\"static/closewindow.gif\" alt=\"%s\"  width=\"16\" height=\"16\">",
268                         _("Close window")
269                 );
270                 escputs(fullinfo);
271                 wc_printf("</div>");
272         }
273         else {
274                 wc_printf("&nbsp;");
275         }
276 }
277
278
279
280
281 /*
282  * Display room banner icon.  
283  * The server doesn't actually need the room name, but we supply it in
284  * order to keep the browser from using a cached icon from another room.
285  */
286 void embed_room_graphic(StrBuf *Target, WCTemplputParams *TP)
287 {
288         char buf[SIZ];
289
290         serv_puts("OIMG _roompic_");
291         serv_getln(buf, sizeof buf);
292         if (buf[0] == '2') {
293                 wc_printf("<img height=\"64px\" src=\"image?name=_roompic_&room=");
294                 urlescputs(ChrPtr(WC->CurRoom.name));
295                 wc_printf("\">");
296                 serv_puts("CLOS");
297                 serv_getln(buf, sizeof buf);
298         }
299         else if (WC->CurRoom.view == VIEW_ADDRESSBOOK) {
300                 wc_printf("<img class=\"roompic\" alt=\"\" src=\""
301                         "static/viewcontacts_48x.gif"
302                         "\" >"
303                         );
304         }
305         else if ( (WC->CurRoom.view == VIEW_CALENDAR) || (WC->CurRoom.view == VIEW_CALBRIEF) ) {
306                 wc_printf("<img class=\"roompic\" alt=\"\" src=\""
307                         "static/calarea_48x.gif"
308                         "\" width=\"48\" height=\"48\">"
309                         );
310         }
311         else if (WC->CurRoom.view == VIEW_TASKS) {
312                 wc_printf("<img class=\"roompic\" alt=\"\" src=\""
313                         "static/taskmanag_48x.gif"
314                         "\" width=\"48\" height=\"48\">"
315                         );
316         }
317         else if (WC->CurRoom.view == VIEW_NOTES) {
318                 wc_printf("<img class=\"roompic\" alt=\"\" src=\""
319                         "static/storenotes_48x.gif"
320                         "\" width=\"48\" height=\"48\">"
321                         );
322         }
323         else if (WC->CurRoom.view == VIEW_MAILBOX) {
324                 wc_printf("<img class=\"roompic\" alt=\"\" src=\""
325                         "static/privatemess_48x.gif"
326                         "\" width=\"48\" height=\"48\">"
327                         );
328         }
329         else {
330                 wc_printf("<img class=\"roompic\" alt=\"\" src=\""
331                         "static/chatrooms_48x.gif"
332                         "\" width=\"48\" height=\"48\">"
333                         );
334         }
335
336 }
337
338
339
340 /*
341  * Display the current view and offer an option to change it
342  */
343 void embed_view_o_matic(StrBuf *Target, WCTemplputParams *TP)
344 {
345         int i;
346
347         wc_printf("<form name=\"viewomatic\" action=\"changeview\">\n");
348         wc_printf("\t<div style=\"display: inline;\">\n\t<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
349         wc_printf("<label for=\"view_name\">");
350         wc_printf(_("View as:"));
351         wc_printf("</label> "
352                 "<select name=\"newview\" size=\"1\" "
353                 "id=\"view_name\" class=\"selectbox\" "
354                 "OnChange=\"location.href=viewomatic.newview.options"
355                 "[selectedIndex].value\">\n");
356
357         for (i=0; i<(sizeof viewdefs / sizeof (char *)); ++i) {
358                 /*
359                  * Only offer the views that make sense, given the default
360                  * view for the room.  For example, don't offer a Calendar
361                  * view in a non-Calendar room.
362                  */
363                 if (
364                         (i == WC->CurRoom.view)
365                         ||      (i == WC->CurRoom.defview)                      /* default */
366                         ||      ( (i == 0) && (WC->CurRoom.defview == 1) )      /* mail or bulletin */
367                         ||      ( (i == 1) && (WC->CurRoom.defview == 0) )      /* mail or bulletin */
368                         /* ||   ( (i == 7) && (WC->CurRoom.defview == 3) )      (calendar list temporarily disabled) */
369                         ) {
370
371                         wc_printf("<option %s value=\"changeview?view=%d\">",
372                                 ((i == WC->CurRoom.view) ? "selected" : ""),
373                                 i );
374                         escputs(viewdefs[i]);
375                         wc_printf("</option>\n");
376                 }
377         }
378         wc_printf("</select></div></form>\n");
379 }
380
381
382 /*
383  * Display a search box
384  */
385 void embed_search_o_matic(StrBuf *Target, WCTemplputParams *TP)
386 {
387         wc_printf("<form name=\"searchomatic\" action=\"do_search\">\n");
388         wc_printf("<div style=\"display: inline;\"><input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
389         wc_printf("<label for=\"srchquery\">");
390         wc_printf(_("Search: "));
391         wc_printf("</label><input ");
392         wc_printf("%s", WC->serv_info->serv_fulltext_enabled ? "" : "disabled ");
393         wc_printf("type=\"text\" name=\"query\" id=\"srchquery\" size=\"15\" maxlength=\"128\" class=\"inputbox\">\n"
394                 );
395         wc_printf("</div></form>\n");
396 }
397
398
399 /*
400  * Embed the room banner
401  *
402  * got                  The information returned from a GOTO server command
403  * navbar_style         Determines which navigation buttons to display
404  *
405  */
406
407 void embed_room_banner(char *got, int navbar_style) {
408         wcsession *WCC = WC;
409         char buf[256];
410         char buf2[1024];
411         char with_files[256];
412         int file_count=0;
413         
414         /*
415          * We need to have the information returned by a GOTO server command.
416          * If it isn't supplied, we fake it by issuing our own GOTO.
417          */
418         if (got == NULL) {
419                 memset(buf, '0', 20);
420                 buf[20] = '\0';
421                 serv_printf("GOTO %s", ChrPtr(WC->CurRoom.name));
422                 serv_getln(buf, sizeof buf);
423                 got = buf;
424         }
425
426         /* The browser needs some information for its own use */
427         wc_printf("<script type=\"text/javascript\">    \n"
428                   "     room_is_trash = %d;             \n"
429                   "</script>\n",
430                   ((WC->CurRoom.RAFlags & UA_ISTRASH) != 0)
431         );
432
433         /*
434          * If the user happens to select the "make this my start page" link,
435          * we want it to remember the URL as a "/dotskip" one instead of
436          * a "skip" or "gotonext" or something like that.
437          */
438         if (WCC->Hdr->this_page == NULL) {
439                 WCC->Hdr->this_page = NewStrBuf();
440         }
441         StrBufPrintf(WCC->Hdr->this_page, 
442                      "dotskip?room=%s",
443                      ChrPtr(WC->CurRoom.name)
444         );
445
446         /* Check for new mail. */
447         WC->new_mail = extract_int(&got[4], 9);
448         WC->CurRoom.view = extract_int(&got[4], 11);
449
450         /* Is this a directory room and does it contain files and how many? */
451         if ((WC->CurRoom.QRFlags & QR_DIRECTORY) && (WC->CurRoom.QRFlags & QR_VISDIR))
452         {
453                 serv_puts("RDIR");
454                 serv_getln(buf2, sizeof buf2);
455                 if (buf2[0] == '1') while (serv_getln(buf2, sizeof buf2), strcmp(buf2, "000"))
456                                             file_count++;
457                 snprintf (with_files, sizeof with_files, 
458                           "; <a href=\"do_template?template=files\"> %d %s </a>", 
459                           file_count, 
460                           ((file_count>1) || (file_count == 0)  ? _("files") : _("file")));
461         }
462         else
463                 strcpy (with_files, "");
464         
465         svprintf(HKEY("NUMMSGS"), WCS_STRING,
466                  _("%d new of %d messages%s"),
467                  extract_int(&got[4], 1),
468                  extract_int(&got[4], 2),
469                  with_files
470                 );
471         svcallback("ROOMPIC", embed_room_graphic);
472         svcallback("ROOMINFO", readinfo);
473         svcallback("VIEWOMATIC", embed_view_o_matic); 
474         svcallback("SEARCHOMATIC", embed_search_o_matic);
475         svcallback("START", offer_start_page); 
476  
477         do_template("roombanner", NULL);
478         /* roombanner contains this for mobile */
479         if (navbar_style != navbar_none && (WC->is_mobile < 1)) { 
480
481                 wc_printf("<div id=\"navbar\"><ul>");
482
483                 if (navbar_style == navbar_default) wc_printf(
484                         "<li class=\"ungoto\">"
485                         "<a href=\"ungoto\">"
486                         "<img src=\"static/ungoto2_24x.gif\" alt=\"\" width=\"24\" height=\"24\">"
487                         "<span class=\"navbar_link\">%s</span></A>"
488                         "</li>\n", _("Ungoto")
489                         );
490
491                 if ( (navbar_style == navbar_default) && (WC->CurRoom.view == VIEW_BBS) ) {
492                         wc_printf(
493                                 "<li class=\"newmess\">"
494                                 "<a href=\"readnew\">"
495                                 "<img src=\"static/newmess2_24x.gif\" alt=\"\" width=\"24\" height=\"24\">"
496                                 "<span class=\"navbar_link\">%s</span></A>"
497                                 "</li>\n", _("Read new messages")
498                                 );
499                 }
500
501                 if (navbar_style == navbar_default) {
502                         switch(WC->CurRoom.view) {
503                         case VIEW_ADDRESSBOOK:
504                                 wc_printf(
505                                         "<li class=\"viewcontacts\">"
506                                         "<a href=\"readfwd\">"
507                                         "<img src=\"static/viewcontacts_24x.gif\" "
508                                         "alt=\"\" width=\"24\" height=\"24\">"
509                                         "<span class=\"navbar_link\">"
510                                         "%s"
511                                         "</span></a></li>\n", _("View contacts")
512                                         );
513                                 break;
514                         case VIEW_CALENDAR:
515                                 wc_printf(
516                                         "<li class=\"staskday\">"
517                                         "<a href=\"readfwd?calview=day\">"
518                                         "<img src=\"static/taskday2_24x.gif\" "
519                                         "alt=\"\" width=\"24\" height=\"24\">"
520                                         "<span class=\"navbar_link\">"
521                                         "%s"
522                                         "</span></a></li>\n", _("Day view")
523                                         );
524                                 wc_printf(
525                                         "<li class=\"monthview\">"
526                                         "<a href=\"readfwd?calview=month\">"
527                                         "<img src=\"static/monthview2_24x.gif\" "
528                                         "alt=\"\" width=\"24\" height=\"24\">"
529                                         "<span class=\"navbar_link\">"
530                                         "%s"
531                                         "</span></a></li>\n", _("Month view")
532                                         );
533                                 break;
534                         case VIEW_CALBRIEF:
535                                 wc_printf(
536                                         "<li class=\"monthview\">"
537                                         "<a href=\"readfwd?calview=month\">"
538                                         "<img src=\"static/monthview2_24x.gif\" "
539                                         "alt=\"\" width=\"24\" height=\"24\">"
540                                         "<span class=\"navbar_link\">"
541                                         "%s"
542                                         "</span></a></li>\n", _("Calendar list")
543                                         );
544                                 break;
545                         case VIEW_TASKS:
546                                 wc_printf(
547                                         "<li class=\"taskmanag\">"
548                                         "<a href=\"readfwd\">"
549                                         "<img src=\"static/taskmanag_24x.gif\" "
550                                         "alt=\"\" width=\"24\" height=\"24\">"
551                                         "<span class=\"navbar_link\">"
552                                         "%s"
553                                         "</span></a></li>\n", _("View tasks")
554                                         );
555                                 break;
556                         case VIEW_NOTES:
557                                 wc_printf(
558                                         "<li class=\"viewnotes\">"
559                                         "<a href=\"readfwd\">"
560                                         "<img src=\"static/viewnotes_24x.gif\" "
561                                         "alt=\"\" width=\"24\" height=\"24\">"
562                                         "<span class=\"navbar_link\">"
563                                         "%s"
564                                         "</span></a></li>\n", _("View notes")
565                                         );
566                                 break;
567                         case VIEW_MAILBOX:
568                                 wc_printf(
569                                         "<li class=\"readallmess\">"
570                                         "<a id=\"m_refresh\" href=\"readfwd\">"
571                                         "<img src=\"static/readallmess3_24x.gif\" "
572                                         "alt=\"\" width=\"24\" height=\"24\">"
573                                         "<span class=\"navbar_link\">"
574                                         "%s"
575                                         "</span></a></li>\n", _("Refresh message list")
576                                         );
577                                 break;
578                         case VIEW_WIKI:
579                                 wc_printf(
580                                         "<li class=\"readallmess\">"
581                                         "<a href=\"wiki?page=home\">"
582                                         "<img src=\"static/readallmess3_24x.gif\" "
583                                         "alt=\"\" width=\"24\" height=\"24\">"
584                                         "<span class=\"navbar_link\">"
585                                         "%s"
586                                         "</span></a></li>\n", _("Wiki home")
587                                         );
588                                 break;
589                         default:
590                                 wc_printf(
591                                         "<li class=\"readallmess\">"
592                                         "<a href=\"readfwd\">"
593                                         "<img src=\"static/readallmess3_24x.gif\" "
594                                         "alt=\"\" width=\"24\" height=\"24\">"
595                                         "<span class=\"navbar_link\">"
596                                         "%s"
597                                         "</span></a></li>\n", _("Read all messages")
598                                         );
599                                 break;
600                         }
601                 }
602
603                 if (navbar_style == navbar_default) {
604                         switch(WC->CurRoom.view) {
605                         case VIEW_ADDRESSBOOK:
606                                 wc_printf(
607                                         "<li class=\"addnewcontact\">"
608                                         "<a href=\"display_enter\">"
609                                         "<img src=\"static/addnewcontact_24x.gif\" "
610                                         "alt=\"\" width=\"24\" height=\"24\">"
611                                         "<span class=\"navbar_link\">"
612                                         "%s"
613                                         "</span></a></li>\n", _("Add new contact")
614                                         );
615                                 break;
616                         case VIEW_CALENDAR:
617                         case VIEW_CALBRIEF:
618                                 wc_printf("<li class=\"addevent\"><a href=\"display_enter");
619                                 if (havebstr("year" )) wc_printf("?year=%s", bstr("year"));
620                                 if (havebstr("month")) wc_printf("?month=%s", bstr("month"));
621                                 if (havebstr("day"  )) wc_printf("?day=%s", bstr("day"));
622                                 wc_printf("\">"
623                                         "<img  src=\"static/addevent_24x.gif\" "
624                                         "alt=\"\" width=\"24\" height=\"24\">"
625                                         "<span class=\"navbar_link\">"
626                                         "%s"
627                                         "</span></a></li>\n", _("Add new event")
628                                         );
629                                 break;
630                         case VIEW_TASKS:
631                                 wc_printf(
632                                         "<li class=\"newmess\">"
633                                         "<a href=\"display_enter\">"
634                                         "<img  src=\"static/newmess3_24x.gif\" "
635                                         "alt=\"\" width=\"24\" height=\"24\">"
636                                         "<span class=\"navbar_link\">"
637                                         "%s"
638                                         "</span></a></li>\n", _("Add new task")
639                                         );
640                                 break;
641                         case VIEW_NOTES:
642                                 wc_printf(
643                                         "<li class=\"enternewnote\">"
644                                         "<a href=\"add_new_note\">"
645                                         "<img  src=\"static/enternewnote_24x.gif\" "
646                                         "alt=\"\" width=\"24\" height=\"24\">"
647                                         "<span class=\"navbar_link\">"
648                                         "%s"
649                                         "</span></a></li>\n", _("Add new note")
650                                         );
651                                 break;
652                         case VIEW_WIKI:
653                                 safestrncpy(buf, bstr("page"), sizeof buf);
654                                 if (IsEmptyStr(buf)) {
655                                         safestrncpy(buf, "home", sizeof buf);
656                                 }
657                                 str_wiki_index(buf);
658                                 wc_printf(
659                                         "<li class=\"newmess\">"
660                                         "<a href=\"display_enter?page=%s\">"
661                                         "<img  src=\"static/newmess3_24x.gif\" "
662                                         "alt=\"\" width=\"24\" height=\"24\">"
663                                         "<span class=\"navbar_link\">"
664                                         "%s"
665                                         "</span></a></li>\n", buf, _("Edit this page")
666                                         );
667
668                                 if (bmstrcasestr((char *)ChrPtr(WCC->Hdr->HR.ReqLine), "wiki_history")) {
669                                         /* already viewing history; display a link to the current page */
670                                         wc_printf(
671                                                 "<li class=\"newmess\">"
672                                                 "<a href=\"wiki?page=%s\">"
673                                                 "<img  src=\"static/newmess3_24x.gif\" "
674                                                 "alt=\"\" width=\"24\" height=\"24\">"
675                                                 "<span class=\"navbar_link\">"
676                                                 "%s"
677                                                 "</span></a></li>\n", buf, _("Current version")
678                                                 );
679                                 }
680                                 else {
681                                         /* display a link to the history */
682                                         wc_printf(
683                                                 "<li class=\"newmess\">"
684                                                 "<a href=\"wiki_history?page=%s\">"
685                                                 "<img  src=\"static/newmess3_24x.gif\" "
686                                                 "alt=\"\" width=\"24\" height=\"24\">"
687                                                 "<span class=\"navbar_link\">"
688                                                 "%s"
689                                                 "</span></a></li>\n", buf, _("History")
690                                                 );
691                                 }
692                                 break;
693                         case VIEW_MAILBOX:
694                                 wc_printf(
695                                         "<li class=\"newmess\">"
696                                         "<a href=\"display_enter\">"
697                                         "<img  src=\"static/newmess3_24x.gif\" "
698                                         "alt=\"\" width=\"24\" height=\"24\">"
699                                         "<span class=\"navbar_link\">"
700                                         "%s"
701                                         "</span></a></li>\n", _("Write mail")
702                                         );
703                                 wc_printf(
704                                         "<li class=\"newmess\">"
705                                         "<a href=\"javascript:deleteAllSelectedMessages();\">"
706                                         "<img  src=\"static/delete.gif\" "
707                                         "alt=\"\" width=\"24\" height=\"24\"><span class=\"navbar_link\">"
708                                         "%s"
709                                         "</span></a></li>\n", _("Delete")
710                                         );
711                                 break;
712                         default:
713                                 wc_printf(
714                                         "<li class=\"newmess\">"
715                                         "<a href=\"display_enter\">"
716                                         "<img  src=\"static/newmess3_24x.gif\" "
717                                         "alt=\"\" width=\"24\" height=\"24\">"
718                                         "<span class=\"navbar_link\">"
719                                         "%s"
720                                         "</span></a></li>\n", _("Enter a message")
721                                         );
722                                 break;
723                         }
724                 }
725
726                 if (navbar_style == navbar_default) wc_printf(
727                         "<li class=\"skipthisroom\">"
728                         "<a href=\"skip\" "
729                         "title=\"%s\">"
730                         "<img  src=\"static/skipthisroom_24x.gif\" alt=\"\" "
731                         "width=\"24\" height=\"24\">"
732                         "<span class=\"navbar_link\">%s</span></a>"
733                         "</li>\n",
734                         _("Leave all messages marked as unread, go to next room with unread messages"),
735                         _("Skip this room")
736                         );
737
738                 if (navbar_style == navbar_default) wc_printf(
739                         "<li class=\"markngo\">"
740                         "<a href=\"gotonext\" "
741                         "title=\"%s\">"
742                         "<img  src=\"static/markngo_24x.gif\" alt=\"\" "
743                         "width=\"24\" height=\"24\">"
744                         "<span class=\"navbar_link\">%s</span></a>"
745                         "</li>\n",
746                         _("Mark all messages as read, go to next room with unread messages"),
747                         _("Goto next room")
748                         );
749
750                 wc_printf("</ul></div>\n");
751         }
752
753 }
754
755
756 /*
757  * back end routine to take the session to a new room
758  */
759 long gotoroom(const StrBuf *gname)
760 {
761         wcsession *WCC = WC;
762         StrBuf *Buf;
763         static long ls = (-1L);
764         long err = 0;
765
766         /* store ungoto information */
767         strcpy(WCC->ugname, ChrPtr(WCC->CurRoom.name));
768         WCC->uglsn = ls;
769         Buf = NewStrBuf();
770
771         /* move to the new room */
772         serv_printf("GOTO %s", ChrPtr(gname));
773         StrBuf_ServGetln(Buf);
774         if  (GetServerStatus(Buf, &err) != 2) {
775                 serv_puts("GOTO _BASEROOM_");
776                 StrBuf_ServGetln(Buf);
777                 /* 
778                  * well, we know that this is the fallback case, 
779                  * but we're interested that the first command 
780                  * didn't work out in first place.
781                  */
782                 if (GetServerStatus(Buf, NULL) != 2) {
783                         FreeStrBuf(&Buf);
784                         return err;
785                 }
786         }
787         ParseGoto(&WCC->CurRoom, Buf);
788
789         remove_march(WCC->CurRoom.name);
790         if (!strcasecmp(ChrPtr(gname), "_BASEROOM_"))
791                 remove_march(gname);
792         FreeStrBuf(&Buf);
793
794         return err;
795 }
796
797
798 void ParseGoto(folder *room, StrBuf *Line)
799 {
800         wcsession *WCC = WC;
801         const char *Pos;
802         int flag;
803         void *vFloor = NULL;
804         StrBuf *pBuf;
805
806         if (StrLength(Line) < 4) {
807                 return;
808         }
809         
810         /* ignore the commandstate... */
811         Pos = ChrPtr(Line) + 4;
812
813         if (room->RoomNameParts != NULL)
814         {
815                 int i;
816                 for (i=0; i < room->nRoomNameParts; i++)
817                         FreeStrBuf(&room->RoomNameParts[i]);
818                 free(room->RoomNameParts);
819                 room->RoomNameParts = NULL;
820         }
821
822         pBuf = room->name;  
823         if (pBuf == NULL)
824                 pBuf = NewStrBufPlain(NULL, StrLength(Line));
825         else
826                 FlushStrBuf(pBuf);
827         memset(room, 0, sizeof(folder));
828         room->name = pBuf;
829
830         StrBufExtract_NextToken(room->name, Line, &Pos, '|'); // WC->CurRoom->name
831
832         room->nNewMessages = StrBufExtractNext_long(Line, &Pos, '|'); 
833         if (room->nNewMessages > 0)
834                 room->RAFlags |= UA_HASNEWMSGS;
835
836         room->nTotalMessages = StrBufExtractNext_long(Line, &Pos, '|');
837
838         room->ShowInfo =  StrBufExtractNext_long(Line, &Pos, '|');
839         
840         room->QRFlags = StrBufExtractNext_long(Line, &Pos, '|'); //CurRoom->QRFlags
841
842         room->HighestRead = StrBufExtractNext_long(Line, &Pos, '|');
843         room->LastMessageRead = StrBufExtractNext_long(Line, &Pos, '|');
844
845         room->is_inbox = StrBufExtractNext_long(Line, &Pos, '|'); // is_mailbox
846
847         flag = StrBufExtractNext_long(Line, &Pos, '|');
848         if (WCC->is_aide || flag) {
849                 room->RAFlags |= UA_ADMINALLOWED;
850         }
851
852         room->UsersNewMAilboxMessages = StrBufExtractNext_long(Line, &Pos, '|');
853
854         room->floorid = StrBufExtractNext_int(Line, &Pos, '|'); // wc_floor
855
856         room->view = StrBufExtractNext_long(Line, &Pos, '|'); // CurRoom->view
857
858         room->defview = StrBufExtractNext_long(Line, &Pos, '|'); // CurRoom->defview
859
860         flag = StrBufExtractNext_long(Line, &Pos, '|');
861         if (flag)
862                 room->RAFlags |= UA_ISTRASH; // wc_is_trash
863
864         room->QRFlags2 = StrBufExtractNext_long(Line, &Pos, '|'); // CurRoom->QRFlags2
865
866         /* find out, whether we are in a sub-room */
867         room->nRoomNameParts = StrBufNum_tokens(room->name, '\\');
868         if (room->nRoomNameParts > 1)
869         {
870                 int i;
871                 
872                 Pos = NULL;
873                 room->RoomNameParts = malloc(sizeof(StrBuf*) * (room->nRoomNameParts + 1));
874                 memset(room->RoomNameParts, 0, sizeof(StrBuf*) * (room->nRoomNameParts + 1));
875                 for (i=0; i < room->nRoomNameParts; i++)
876                 {
877                         room->RoomNameParts[i] = NewStrBuf();
878                         StrBufExtract_NextToken(room->RoomNameParts[i],
879                                                 room->name, &Pos, '\\');
880                 }
881         }
882
883         /* Private mailboxes on the main floor get remapped to the personal folder */
884         if ((room->QRFlags & QR_MAILBOX) && 
885             (room->floorid == 0))
886         {
887                 room->floorid = VIRTUAL_MY_FLOOR;
888                 if ((room->nRoomNameParts == 1) && 
889                     (StrLength(room->name) == 4) && 
890                     (strcmp(ChrPtr(room->name), "Mail") == 0))
891                 {
892                         room->is_inbox = 1;
893                 }
894                 
895         }
896         /* get a pointer to the floor we're on: */
897         GetHash(WCC->Floors, IKEY(room->floorid), &vFloor);
898         room->Floor = (const Floor*) vFloor;
899 }
900
901
902 /*
903  * goto next room
904  */
905 void smart_goto(const StrBuf *next_room) {
906         gotoroom(next_room);
907         readloop(readnew, eUseDefault);
908 }
909
910
911
912 /*
913  * mark all messages in current room as having been read
914  */
915 void slrp_highest(void)
916 {
917         char buf[256];
918
919         serv_puts("SLRP HIGHEST");
920         serv_getln(buf, sizeof buf);
921 }
922
923
924 typedef struct __room_states {
925         char password[SIZ];
926         char dirname[SIZ];
927         char name[SIZ];
928         int flags;
929         int floor;
930         int order;
931         int view;
932         int flags2;
933 } room_states;
934
935
936
937
938 /*
939  * Set/clear/read the "self-service list subscribe" flag for a room
940  * 
941  * set newval to 0 to clear, 1 to set, any other value to leave unchanged.
942  * returns the new value.
943  */
944
945 int self_service(int newval) {
946         int current_value = 0;
947         char buf[SIZ];
948         
949         char name[SIZ];
950         char password[SIZ];
951         char dirname[SIZ];
952         int flags, floor, order, view, flags2;
953
954         serv_puts("GETR");
955         serv_getln(buf, sizeof buf);
956         if (buf[0] != '2') return(0);
957
958         extract_token(name, &buf[4], 0, '|', sizeof name);
959         extract_token(password, &buf[4], 1, '|', sizeof password);
960         extract_token(dirname, &buf[4], 2, '|', sizeof dirname);
961         flags = extract_int(&buf[4], 3);
962         floor = extract_int(&buf[4], 4);
963         order = extract_int(&buf[4], 5);
964         view = extract_int(&buf[4], 6);
965         flags2 = extract_int(&buf[4], 7);
966
967         if (flags2 & QR2_SELFLIST) {
968                 current_value = 1;
969         }
970         else {
971                 current_value = 0;
972         }
973
974         if (newval == 1) {
975                 flags2 = flags2 | QR2_SELFLIST;
976         }
977         else if (newval == 0) {
978                 flags2 = flags2 & ~QR2_SELFLIST;
979         }
980         else {
981                 return(current_value);
982         }
983
984         if (newval != current_value) {
985                 serv_printf("SETR %s|%s|%s|%d|0|%d|%d|%d|%d",
986                             name, password, dirname, flags,
987                             floor, order, view, flags2);
988                 serv_getln(buf, sizeof buf);
989         }
990
991         return(newval);
992
993 }
994
995 int is_selflist(room_states *RoomFlags)
996 {
997         return ((RoomFlags->flags2 & QR2_SELFLIST) != 0);
998 }
999
1000 int is_publiclist(room_states *RoomFlags)
1001 {
1002         return ((RoomFlags->flags2 & QR2_SMTP_PUBLIC) != 0);
1003 }
1004
1005 int is_moderatedlist(room_states *RoomFlags)
1006 {
1007         return ((RoomFlags->flags2 & QR2_MODERATED) != 0);
1008 }
1009
1010 /*
1011  * Set/clear/read the "self-service list subscribe" flag for a room
1012  * 
1013  * set newval to 0 to clear, 1 to set, any other value to leave unchanged.
1014  * returns the new value.
1015  */
1016
1017 int get_roomflags(room_states *RoomOps) 
1018 {
1019         char buf[SIZ];
1020         
1021         serv_puts("GETR");
1022         serv_getln(buf, sizeof buf);
1023         if (buf[0] != '2') return(0);
1024
1025         extract_token(RoomOps->name, &buf[4], 0, '|', sizeof RoomOps->name);
1026         extract_token(RoomOps->password, &buf[4], 1, '|', sizeof RoomOps->password);
1027         extract_token(RoomOps->dirname, &buf[4], 2, '|', sizeof RoomOps->dirname);
1028         RoomOps->flags = extract_int(&buf[4], 3);
1029         RoomOps->floor = extract_int(&buf[4], 4);
1030         RoomOps->order = extract_int(&buf[4], 5);
1031         RoomOps->view = extract_int(&buf[4], 6);
1032         RoomOps->flags2 = extract_int(&buf[4], 7);
1033         return (1);
1034 }
1035
1036 int set_roomflags(room_states *RoomOps)
1037 {
1038         char buf[SIZ];
1039
1040         serv_printf("SETR %s|%s|%s|%d|0|%d|%d|%d|%d",
1041                     RoomOps->name, 
1042                     RoomOps->password, 
1043                     RoomOps->dirname, 
1044                     RoomOps->flags,
1045                     RoomOps->floor, 
1046                     RoomOps->order, 
1047                     RoomOps->view, 
1048                     RoomOps->flags2);
1049         serv_getln(buf, sizeof buf);
1050         return (1);
1051 }
1052
1053
1054
1055
1056
1057
1058 /*
1059  * display the form for editing a room
1060  */
1061 void display_editroom(void)
1062 {
1063         StrBuf *Buf;
1064         char buf[SIZ];
1065         char cmd[1024];
1066         char node[256];
1067         char remote_room[128];
1068         char recp[1024];
1069         char er_name[128];
1070         char er_password[10];
1071         char er_dirname[15];
1072         char er_roomaide[26];
1073         unsigned er_flags;
1074         unsigned er_flags2;
1075         int er_floor;
1076         int i, j;
1077         char *tab;
1078         char *shared_with;
1079         char *not_shared_with = NULL;
1080         int roompolicy = 0;
1081         int roomvalue = 0;
1082         int floorpolicy = 0;
1083         int floorvalue = 0;
1084         char pop3_host[128];
1085         char pop3_user[32];
1086         int bg = 0;
1087
1088         tab = bstr("tab");
1089         if (IsEmptyStr(tab)) tab = "admin";
1090
1091         Buf = NewStrBuf();
1092         load_floorlist(Buf);
1093         FreeStrBuf(&Buf);
1094         output_headers(1, 1, 1, 0, 0, 0);
1095
1096         wc_printf("<div class=\"fix_scrollbar_bug\">");
1097
1098         wc_printf("<br />\n");
1099
1100         /* print the tabbed dialog */
1101         wc_printf("<div align=\"center\">");
1102         wc_printf("<table id=\"AdminTabs\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"
1103                 "<tr align=\"center\" style=\"cursor:pointer\"><td>&nbsp;</td>"
1104                 );
1105
1106         wc_printf("<td class=\"");
1107         if (!strcmp(tab, "admin")) {
1108                 wc_printf(" tab_cell_label\">");
1109                 wc_printf(_("Administration"));
1110         }
1111         else {
1112                 wc_printf("< tab_cell_edit\"><a href=\"display_editroom?tab=admin\">");
1113                 wc_printf(_("Administration"));
1114                 wc_printf("</a>");
1115         }
1116         wc_printf("</td>\n");
1117         wc_printf("<td>&nbsp;</td>\n");
1118
1119         if ( ConditionalHaveRoomeditRights(NULL, NULL)) {
1120
1121                 wc_printf("<td class=\"");
1122                 if (!strcmp(tab, "config")) {
1123                         wc_printf(" tab_cell_label\">");
1124                         wc_printf(_("Configuration"));
1125                 }
1126                 else {
1127                         wc_printf(" tab_cell_edit\"><a href=\"display_editroom?tab=config\">");
1128                         wc_printf(_("Configuration"));
1129                         wc_printf("</a>");
1130                 }
1131                 wc_printf("</td>\n");
1132                 wc_printf("<td>&nbsp;</td>\n");
1133
1134                 wc_printf("<td class=\"");
1135                 if (!strcmp(tab, "expire")) {
1136                         wc_printf(" tab_cell_label\">");
1137                         wc_printf(_("Message expire policy"));
1138                 }
1139                 else {
1140                         wc_printf(" tab_cell_edit\"><a href=\"display_editroom?tab=expire\">");
1141                         wc_printf(_("Message expire policy"));
1142                         wc_printf("</a>");
1143                 }
1144                 wc_printf("</td>\n");
1145                 wc_printf("<td>&nbsp;</td>\n");
1146         
1147                 wc_printf("<td class=\"");
1148                 if (!strcmp(tab, "access")) {
1149                         wc_printf(" tab_cell_label\">");
1150                         wc_printf(_("Access controls"));
1151                 }
1152                 else {
1153                         wc_printf(" tab_cell_edit\"><a href=\"display_editroom?tab=access\">");
1154                         wc_printf(_("Access controls"));
1155                         wc_printf("</a>");
1156                 }
1157                 wc_printf("</td>\n");
1158                 wc_printf("<td>&nbsp;</td>\n");
1159
1160                 wc_printf("<td class=\"");
1161                 if (!strcmp(tab, "sharing")) {
1162                         wc_printf(" tab_cell_label\">");
1163                         wc_printf(_("Sharing"));
1164                 }
1165                 else {
1166                         wc_printf(" tab_cell_edit\"><a href=\"display_editroom?tab=sharing\">");
1167                         wc_printf(_("Sharing"));
1168                         wc_printf("</a>");
1169                 }
1170                 wc_printf("</td>\n");
1171                 wc_printf("<td>&nbsp;</td>\n");
1172
1173                 wc_printf("<td class=\"");
1174                 if (!strcmp(tab, "listserv")) {
1175                         wc_printf(" tab_cell_label\">");
1176                         wc_printf(_("Mailing list service"));
1177                 }
1178                 else {
1179                         wc_printf("< tab_cell_edit\"><a href=\"display_editroom?tab=listserv\">");
1180                         wc_printf(_("Mailing list service"));
1181                         wc_printf("</a>");
1182                 }
1183                 wc_printf("</td>\n");
1184                 wc_printf("<td>&nbsp;</td>\n");
1185
1186         }
1187
1188         wc_printf("<td class=\"");
1189         if (!strcmp(tab, "feeds")) {
1190                 wc_printf(" tab_cell_label\">");
1191                 wc_printf(_("Remote retrieval"));
1192         }
1193         else {
1194                 wc_printf("< tab_cell_edit\"><a href=\"display_editroom?tab=feeds\">");
1195                 wc_printf(_("Remote retrieval"));
1196                 wc_printf("</a>");
1197         }
1198         wc_printf("</td>\n");
1199         wc_printf("<td>&nbsp;</td>\n");
1200
1201         wc_printf("</tr></table>\n");
1202         wc_printf("</div>\n");
1203         /* end tabbed dialog */ 
1204
1205         wc_printf("<script type=\"text/javascript\">"
1206                 " Nifty(\"table#AdminTabs td\", \"small transparent top\");"
1207                 "</script>"
1208                 );
1209
1210         /* begin content of whatever tab is open now */
1211
1212         if (!strcmp(tab, "admin")) {
1213                 wc_printf("<div class=\"tabcontent\">");
1214                 wc_printf("<ul>"
1215                         "<li><a href=\"delete_room\" "
1216                         "onClick=\"return confirm('");
1217                 wc_printf(_("Are you sure you want to delete this room?"));
1218                 wc_printf("');\">\n");
1219                 wc_printf(_("Delete this room"));
1220                 wc_printf("</a>\n"
1221                         "<li><a href=\"display_editroompic?which_room=");
1222                 urlescputs(ChrPtr(WC->CurRoom.name));
1223                 wc_printf("\">\n");
1224                 wc_printf(_("Set or change the icon for this room's banner"));
1225                 wc_printf("</a>\n"
1226                         "<li><a href=\"display_editinfo\">\n");
1227                 wc_printf(_("Edit this room's Info file"));
1228                 wc_printf("</a>\n"
1229                         "</ul>");
1230                 wc_printf("</div>");
1231         }
1232
1233         if (!strcmp(tab, "config")) {
1234                 wc_printf("<div class=\"tabcontent\">");
1235                 serv_puts("GETR");
1236                 serv_getln(buf, sizeof buf);
1237
1238                 if (!strncmp(buf, "550", 3)) {
1239                         wc_printf("<br><br><div align=center>%s</div><br><br>\n",
1240                                 _("Higher access is required to access this function.")
1241                                 );
1242                 }
1243                 else if (buf[0] != '2') {
1244                         wc_printf("<br><br><div align=center>%s</div><br><br>\n", &buf[4]);
1245                 }
1246                 else {
1247                         extract_token(er_name, &buf[4], 0, '|', sizeof er_name);
1248                         extract_token(er_password, &buf[4], 1, '|', sizeof er_password);
1249                         extract_token(er_dirname, &buf[4], 2, '|', sizeof er_dirname);
1250                         er_flags = extract_int(&buf[4], 3);
1251                         er_floor = extract_int(&buf[4], 4);
1252                         er_flags2 = extract_int(&buf[4], 7);
1253         
1254                         wc_printf("<form method=\"POST\" action=\"editroom\">\n");
1255                         wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1256                 
1257                         wc_printf("<ul><li>");
1258                         wc_printf(_("Name of room: "));
1259                         wc_printf("<input type=\"text\" NAME=\"er_name\" VALUE=\"%s\" MAXLENGTH=\""ULONG_FMT"\">\n",
1260                                 er_name,
1261                                 (sizeof(er_name)-1)
1262                                 );
1263                 
1264                         wc_printf("<li>");
1265                         wc_printf(_("Resides on floor: "));
1266                         wc_printf("<select NAME=\"er_floor\" SIZE=\"1\"");
1267                         if (er_flags & QR_MAILBOX)
1268                                 wc_printf("disabled >\n");
1269                         for (i = 0; i < 128; ++i)
1270                                 if (!IsEmptyStr(floorlist[i])) {
1271                                         wc_printf("<OPTION ");
1272                                         if (i == er_floor )
1273                                                 wc_printf("SELECTED ");
1274                                         wc_printf("VALUE=\"%d\">", i);
1275                                         escputs(floorlist[i]);
1276                                         wc_printf("</OPTION>\n");
1277                                 }
1278                         wc_printf("</select>\n");
1279
1280                         wc_printf("<li>");
1281                         wc_printf(_("Type of room:"));
1282                         wc_printf("<ul>\n");
1283         
1284                         wc_printf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"public\" ");
1285                         if ((er_flags & (QR_PRIVATE + QR_MAILBOX)) == 0)
1286                                 wc_printf("CHECKED ");
1287                         wc_printf("OnChange=\""
1288                                 "       if (this.form.type[0].checked == true) {        "
1289                                 "               this.form.er_floor.disabled = false;    "
1290                                 "       }                                               "
1291                                 "\"> ");
1292                         wc_printf(_("Public (automatically appears to everyone)"));
1293                         wc_printf("\n");
1294         
1295                         wc_printf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"hidden\" ");
1296                         if ((er_flags & QR_PRIVATE) &&
1297                             (er_flags & QR_GUESSNAME))
1298                                 wc_printf("CHECKED ");
1299                         wc_printf(" OnChange=\""
1300                                 "       if (this.form.type[1].checked == true) {        "
1301                                 "               this.form.er_floor.disabled = false;    "
1302                                 "       }                                               "
1303                                 "\"> ");
1304                         wc_printf(_("Private - hidden (accessible to anyone who knows its name)"));
1305                 
1306                         wc_printf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
1307                         if ((er_flags & QR_PRIVATE) &&
1308                             (er_flags & QR_PASSWORDED))
1309                                 wc_printf("CHECKED ");
1310                         wc_printf(" OnChange=\""
1311                                 "       if (this.form.type[2].checked == true) {        "
1312                                 "               this.form.er_floor.disabled = false;    "
1313                                 "       }                                               "
1314                                 "\"> ");
1315                         wc_printf(_("Private - require password: "));
1316                         wc_printf("\n<input type=\"text\" NAME=\"er_password\" VALUE=\"%s\" MAXLENGTH=\"9\">\n",
1317                                 er_password);
1318                 
1319                         wc_printf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
1320                         if ((er_flags & QR_PRIVATE)
1321                             && ((er_flags & QR_GUESSNAME) == 0)
1322                             && ((er_flags & QR_PASSWORDED) == 0))
1323                                 wc_printf("CHECKED ");
1324                         wc_printf(" OnChange=\""
1325                                 "       if (this.form.type[3].checked == true) {        "
1326                                 "               this.form.er_floor.disabled = false;    "
1327                                 "       }                                               "
1328                                 "\"> ");
1329                         wc_printf(_("Private - invitation only"));
1330                 
1331                         wc_printf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"personal\" ");
1332                         if (er_flags & QR_MAILBOX)
1333                                 wc_printf("CHECKED ");
1334                         wc_printf (" OnChange=\""
1335                                  "      if (this.form.type[4].checked == true) {        "
1336                                  "              this.form.er_floor.disabled = true;     "
1337                                  "      }                                               "
1338                                  "\"> ");
1339                         wc_printf(_("Personal (mailbox for you only)"));
1340                         
1341                         wc_printf("\n<li><input type=\"checkbox\" NAME=\"bump\" VALUE=\"yes\" ");
1342                         wc_printf("> ");
1343                         wc_printf(_("If private, cause current users to forget room"));
1344                 
1345                         wc_printf("\n</ul>\n");
1346                 
1347                         wc_printf("<li><input type=\"checkbox\" NAME=\"prefonly\" VALUE=\"yes\" ");
1348                         if (er_flags & QR_PREFONLY)
1349                                 wc_printf("CHECKED ");
1350                         wc_printf("> ");
1351                         wc_printf(_("Preferred users only"));
1352                 
1353                         wc_printf("\n<li><input type=\"checkbox\" NAME=\"readonly\" VALUE=\"yes\" ");
1354                         if (er_flags & QR_READONLY)
1355                                 wc_printf("CHECKED ");
1356                         wc_printf("> ");
1357                         wc_printf(_("Read-only room"));
1358                 
1359                         wc_printf("\n<li><input type=\"checkbox\" NAME=\"collabdel\" VALUE=\"yes\" ");
1360                         if (er_flags2 & QR2_COLLABDEL)
1361                                 wc_printf("CHECKED ");
1362                         wc_printf("> ");
1363                         wc_printf(_("All users allowed to post may also delete messages"));
1364                 
1365                         /** directory stuff */
1366                         wc_printf("\n<li><input type=\"checkbox\" NAME=\"directory\" VALUE=\"yes\" ");
1367                         if (er_flags & QR_DIRECTORY)
1368                                 wc_printf("CHECKED ");
1369                         wc_printf("> ");
1370                         wc_printf(_("File directory room"));
1371         
1372                         wc_printf("\n<ul><li>");
1373                         wc_printf(_("Directory name: "));
1374                         wc_printf("<input type=\"text\" NAME=\"er_dirname\" VALUE=\"%s\" MAXLENGTH=\"14\">\n",
1375                                 er_dirname);
1376         
1377                         wc_printf("<li><input type=\"checkbox\" NAME=\"ulallowed\" VALUE=\"yes\" ");
1378                         if (er_flags & QR_UPLOAD)
1379                                 wc_printf("CHECKED ");
1380                         wc_printf("> ");
1381                         wc_printf(_("Uploading allowed"));
1382                 
1383                         wc_printf("\n<li><input type=\"checkbox\" NAME=\"dlallowed\" VALUE=\"yes\" ");
1384                         if (er_flags & QR_DOWNLOAD)
1385                                 wc_printf("CHECKED ");
1386                         wc_printf("> ");
1387                         wc_printf(_("Downloading allowed"));
1388                 
1389                         wc_printf("\n<li><input type=\"checkbox\" NAME=\"visdir\" VALUE=\"yes\" ");
1390                         if (er_flags & QR_VISDIR)
1391                                 wc_printf("CHECKED ");
1392                         wc_printf("> ");
1393                         wc_printf(_("Visible directory"));
1394                         wc_printf("</ul>\n");
1395                 
1396                         /** end of directory stuff */
1397         
1398                         wc_printf("<li><input type=\"checkbox\" NAME=\"network\" VALUE=\"yes\" ");
1399                         if (er_flags & QR_NETWORK)
1400                                 wc_printf("CHECKED ");
1401                         wc_printf("> ");
1402                         wc_printf(_("Network shared room"));
1403         
1404                         wc_printf("\n<li><input type=\"checkbox\" NAME=\"permanent\" VALUE=\"yes\" ");
1405                         if (er_flags & QR_PERMANENT)
1406                                 wc_printf("CHECKED ");
1407                         wc_printf("> ");
1408                         wc_printf(_("Permanent (does not auto-purge)"));
1409         
1410                         wc_printf("\n<li><input type=\"checkbox\" NAME=\"subjectreq\" VALUE=\"yes\" ");
1411                         if (er_flags2 & QR2_SUBJECTREQ)
1412                                 wc_printf("CHECKED ");
1413                         wc_printf("> ");
1414                         wc_printf(_("Subject Required (Force users to specify a message subject)"));
1415         
1416                         /** start of anon options */
1417                 
1418                         wc_printf("\n<li>");
1419                         wc_printf(_("Anonymous messages"));
1420                         wc_printf("<ul>\n");
1421                 
1422                         wc_printf("<li><input type=\"radio\" NAME=\"anon\" VALUE=\"no\" ");
1423                         if (((er_flags & QR_ANONONLY) == 0)
1424                             && ((er_flags & QR_ANONOPT) == 0))
1425                                 wc_printf("CHECKED ");
1426                         wc_printf("> ");
1427                         wc_printf(_("No anonymous messages"));
1428         
1429                         wc_printf("\n<li><input type=\"radio\" NAME=\"anon\" VALUE=\"anononly\" ");
1430                         if (er_flags & QR_ANONONLY)
1431                                 wc_printf("CHECKED ");
1432                         wc_printf("> ");
1433                         wc_printf(_("All messages are anonymous"));
1434                 
1435                         wc_printf("\n<li><input type=\"radio\" NAME=\"anon\" VALUE=\"anon2\" ");
1436                         if (er_flags & QR_ANONOPT)
1437                                 wc_printf("CHECKED ");
1438                         wc_printf("> ");
1439                         wc_printf(_("Prompt user when entering messages"));
1440                         wc_printf("</ul>\n");
1441                 
1442                         /* end of anon options */
1443                 
1444                         wc_printf("<li>");
1445                         wc_printf(_("Room aide: "));
1446                         serv_puts("GETA");
1447                         serv_getln(buf, sizeof buf);
1448                         if (buf[0] != '2') {
1449                                 wc_printf("<em>%s</em>\n", &buf[4]);
1450                         } else {
1451                                 extract_token(er_roomaide, &buf[4], 0, '|', sizeof er_roomaide);
1452                                 wc_printf("<input type=\"text\" NAME=\"er_roomaide\" VALUE=\"%s\" MAXLENGTH=\"25\">\n", er_roomaide);
1453                         }
1454                 
1455                         wc_printf("</ul><CENTER>\n");
1456                         wc_printf("<input type=\"hidden\" NAME=\"tab\" VALUE=\"config\">\n"
1457                                 "<input type=\"submit\" NAME=\"ok_button\" VALUE=\"%s\">"
1458                                 "&nbsp;"
1459                                 "<input type=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">"
1460                                 "</CENTER>\n",
1461                                 _("Save changes"),
1462                                 _("Cancel")
1463                                 );
1464                 }
1465                 wc_printf("</div>");
1466         }
1467
1468
1469         /* Sharing the room with other Citadel nodes... */
1470         if (!strcmp(tab, "sharing")) {
1471                 wc_printf("<div class=\"tabcontent\">");
1472
1473                 shared_with = strdup("");
1474                 not_shared_with = strdup("");
1475
1476                 /** Learn the current configuration */
1477                 serv_puts("CONF getsys|application/x-citadel-ignet-config");
1478                 serv_getln(buf, sizeof buf);
1479                 if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1480                                 extract_token(node, buf, 0, '|', sizeof node);
1481                                 not_shared_with = realloc(not_shared_with,
1482                                                           strlen(not_shared_with) + 32);
1483                                 strcat(not_shared_with, node);
1484                                 strcat(not_shared_with, "\n");
1485                         }
1486
1487                 serv_puts("GNET");
1488                 serv_getln(buf, sizeof buf);
1489                 if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1490                                 extract_token(cmd, buf, 0, '|', sizeof cmd);
1491                                 extract_token(node, buf, 1, '|', sizeof node);
1492                                 extract_token(remote_room, buf, 2, '|', sizeof remote_room);
1493                                 if (!strcasecmp(cmd, "ignet_push_share")) {
1494                                         shared_with = realloc(shared_with,
1495                                                               strlen(shared_with) + 32);
1496                                         strcat(shared_with, node);
1497                                         if (!IsEmptyStr(remote_room)) {
1498                                                 strcat(shared_with, "|");
1499                                                 strcat(shared_with, remote_room);
1500                                         }
1501                                         strcat(shared_with, "\n");
1502                                 }
1503                         }
1504
1505                 for (i=0; i<num_tokens(shared_with, '\n'); ++i) {
1506                         extract_token(buf, shared_with, i, '\n', sizeof buf);
1507                         extract_token(node, buf, 0, '|', sizeof node);
1508                         for (j=0; j<num_tokens(not_shared_with, '\n'); ++j) {
1509                                 extract_token(cmd, not_shared_with, j, '\n', sizeof cmd);
1510                                 if (!strcasecmp(node, cmd)) {
1511                                         remove_token(not_shared_with, j, '\n');
1512                                 }
1513                         }
1514                 }
1515
1516                 /* Display the stuff */
1517                 wc_printf("<CENTER><br />"
1518                         "<table border=1 cellpadding=5><tr>"
1519                         "<td><B><I>");
1520                 wc_printf(_("Shared with"));
1521                 wc_printf("</I></B></td>"
1522                         "<td><B><I>");
1523                 wc_printf(_("Not shared with"));
1524                 wc_printf("</I></B></td></tr>\n"
1525                         "<tr><td VALIGN=TOP>\n");
1526
1527                 wc_printf("<table border=0 cellpadding=5><tr class=\"tab_cell\"><td>");
1528                 wc_printf(_("Remote node name"));
1529                 wc_printf("</td><td>");
1530                 wc_printf(_("Remote room name"));
1531                 wc_printf("</td><td>");
1532                 wc_printf(_("Actions"));
1533                 wc_printf("</td></tr>\n");
1534
1535                 for (i=0; i<num_tokens(shared_with, '\n'); ++i) {
1536                         extract_token(buf, shared_with, i, '\n', sizeof buf);
1537                         extract_token(node, buf, 0, '|', sizeof node);
1538                         extract_token(remote_room, buf, 1, '|', sizeof remote_room);
1539                         if (!IsEmptyStr(node)) {
1540                                 wc_printf("<form method=\"POST\" action=\"netedit\">");
1541                                 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1542                                 wc_printf("<tr><td>%s</td>\n", node);
1543
1544                                 wc_printf("<td>");
1545                                 if (!IsEmptyStr(remote_room)) {
1546                                         escputs(remote_room);
1547                                 }
1548                                 wc_printf("</td>");
1549
1550                                 wc_printf("<td>");
1551                 
1552                                 wc_printf("<input type=\"hidden\" NAME=\"line\" "
1553                                         "VALUE=\"ignet_push_share|");
1554                                 urlescputs(node);
1555                                 if (!IsEmptyStr(remote_room)) {
1556                                         wc_printf("|");
1557                                         urlescputs(remote_room);
1558                                 }
1559                                 wc_printf("\">");
1560                                 wc_printf("<input type=\"hidden\" NAME=\"tab\" VALUE=\"sharing\">\n");
1561                                 wc_printf("<input type=\"hidden\" NAME=\"cmd\" VALUE=\"remove\">\n");
1562                                 wc_printf("<input type=\"submit\" "
1563                                         "NAME=\"unshare_button\" VALUE=\"%s\">", _("Unshare"));
1564                                 wc_printf("</td></tr></form>\n");
1565                         }
1566                 }
1567
1568                 wc_printf("</table>\n");
1569                 wc_printf("</td><td VALIGN=TOP>\n");
1570                 wc_printf("<table border=0 cellpadding=5><tr class=\"tab_cell\"><td>");
1571                 wc_printf(_("Remote node name"));
1572                 wc_printf("</td><td>");
1573                 wc_printf(_("Remote room name"));
1574                 wc_printf("</td><td>");
1575                 wc_printf(_("Actions"));
1576                 wc_printf("</td></tr>\n");
1577
1578                 for (i=0; i<num_tokens(not_shared_with, '\n'); ++i) {
1579                         extract_token(node, not_shared_with, i, '\n', sizeof node);
1580                         if (!IsEmptyStr(node)) {
1581                                 wc_printf("<form method=\"POST\" action=\"netedit\">");
1582                                 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1583                                 wc_printf("<tr><td>");
1584                                 escputs(node);
1585                                 wc_printf("</td><td>"
1586                                         "<input type=\"INPUT\" "
1587                                         "NAME=\"suffix\" "
1588                                         "MAXLENGTH=128>"
1589                                         "</td><td>");
1590                                 wc_printf("<input type=\"hidden\" "
1591                                         "NAME=\"line\" "
1592                                         "VALUE=\"ignet_push_share|");
1593                                 urlescputs(node);
1594                                 wc_printf("|\">");
1595                                 wc_printf("<input type=\"hidden\" NAME=\"tab\" "
1596                                         "VALUE=\"sharing\">\n");
1597                                 wc_printf("<input type=\"hidden\" NAME=\"cmd\" "
1598                                         "VALUE=\"add\">\n");
1599                                 wc_printf("<input type=\"submit\" "
1600                                         "NAME=\"add_button\" VALUE=\"%s\">", _("Share"));
1601                                 wc_printf("</td></tr></form>\n");
1602                         }
1603                 }
1604
1605                 wc_printf("</table>\n");
1606                 wc_printf("</td></tr>"
1607                         "</table></CENTER><br />\n"
1608                         "<I><B>%s</B><ul><li>", _("Notes:"));
1609                 wc_printf(_("When sharing a room, "
1610                           "it must be shared from both ends.  Adding a node to "
1611                           "the 'shared' list sends messages out, but in order to"
1612                           " receive messages, the other nodes must be configured"
1613                           " to send messages out to your system as well. "
1614                           "<li>If the remote room name is blank, it is assumed "
1615                           "that the room name is identical on the remote node."
1616                           "<li>If the remote room name is different, the remote "
1617                           "node must also configure the name of the room here."
1618                           "</ul></I><br />\n"
1619                                 ));
1620
1621                 wc_printf("</div>");
1622         }
1623
1624         if (not_shared_with != NULL)
1625                 free (not_shared_with);
1626
1627         /* Mailing list management */
1628         if (!strcmp(tab, "listserv")) {
1629                 room_states RoomFlags;
1630                 wc_printf("<div class=\"tabcontent\">");
1631
1632                 wc_printf("<br /><center>"
1633                         "<table BORDER=0 WIDTH=100%% CELLPADDING=5>"
1634                         "<tr><td VALIGN=TOP>");
1635
1636                 wc_printf(_("<i>The contents of this room are being "
1637                           "mailed <b>as individual messages</b> "
1638                           "to the following list recipients:"
1639                           "</i><br /><br />\n"));
1640
1641                 serv_puts("GNET");
1642                 serv_getln(buf, sizeof buf);
1643                 if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1644                                 extract_token(cmd, buf, 0, '|', sizeof cmd);
1645                                 if (!strcasecmp(cmd, "listrecp")) {
1646                                         extract_token(recp, buf, 1, '|', sizeof recp);
1647                         
1648                                         escputs(recp);
1649                                         wc_printf(" <a href=\"netedit?cmd=remove?tab=listserv?line=listrecp|");
1650                                         urlescputs(recp);
1651                                         wc_printf("\">");
1652                                         wc_printf(_("(remove)"));
1653                                         wc_printf("</A><br />");
1654                                 }
1655                         }
1656                 wc_printf("<br /><form method=\"POST\" action=\"netedit\">\n"
1657                         "<input type=\"hidden\" NAME=\"tab\" VALUE=\"listserv\">\n"
1658                         "<input type=\"hidden\" NAME=\"prefix\" VALUE=\"listrecp|\">\n");
1659                 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1660                 wc_printf("<input type=\"text\" id=\"add_as_listrecp\" NAME=\"line\">\n");
1661                 wc_printf("<input type=\"submit\" NAME=\"add_button\" VALUE=\"%s\">", _("Add"));
1662                 wc_printf("</form>\n");
1663
1664                 wc_printf("</td><td VALIGN=TOP>\n");
1665                 
1666                 wc_printf(_("<i>The contents of this room are being "
1667                           "mailed <b>in digest form</b> "
1668                           "to the following list recipients:"
1669                           "</i><br /><br />\n"));
1670
1671                 serv_puts("GNET");
1672                 serv_getln(buf, sizeof buf);
1673                 if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1674                                 extract_token(cmd, buf, 0, '|', sizeof cmd);
1675                                 if (!strcasecmp(cmd, "digestrecp")) {
1676                                         extract_token(recp, buf, 1, '|', sizeof recp);
1677                         
1678                                         escputs(recp);
1679                                         wc_printf(" <a href=\"netedit?cmd=remove?tab=listserv?line="
1680                                                 "digestrecp|");
1681                                         urlescputs(recp);
1682                                         wc_printf("\">");
1683                                         wc_printf(_("(remove)"));
1684                                         wc_printf("</A><br />");
1685                                 }
1686                         }
1687                 wc_printf("<br /><form method=\"POST\" action=\"netedit\">\n"
1688                         "<input type=\"hidden\" NAME=\"tab\" VALUE=\"listserv\">\n"
1689                         "<input type=\"hidden\" NAME=\"prefix\" VALUE=\"digestrecp|\">\n");
1690                 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1691                 wc_printf("<input type=\"text\" id=\"add_as_digestrecp\" NAME=\"line\">\n");
1692                 wc_printf("<input type=\"submit\" NAME=\"add_button\" VALUE=\"%s\">", _("Add"));
1693                 wc_printf("</form>\n");
1694                 
1695                 wc_printf("</td></tr></table>\n");
1696
1697                 /** Pop open an address book -- begin **/
1698                 wc_printf("<div align=right>"
1699                         "<a href=\"javascript:PopOpenAddressBook('add_as_listrecp|%s|add_as_digestrecp|%s');\" "
1700                         "title=\"%s\">"
1701                         "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
1702                         "&nbsp;%s</a>"
1703                         "</div>",
1704                         _("List"),
1705                         _("Digest"),
1706                         _("Add recipients from Contacts or other address books"),
1707                         _("Add recipients from Contacts or other address books")
1708                         );
1709                 /* Pop open an address book -- end **/
1710
1711                 wc_printf("<br />\n<form method=\"GET\" action=\"toggle_self_service\">\n");
1712
1713                 get_roomflags (&RoomFlags);
1714                 
1715                 /* Self Service subscription? */
1716                 wc_printf("<table><tr><td>\n");
1717                 wc_printf(_("Allow self-service subscribe/unsubscribe requests."));
1718                 wc_printf("</td><td><input type=\"checkbox\" name=\"QR2_SelfList\" value=\"yes\" %s></td></tr>\n"
1719                         " <tr><td colspan=\"2\">\n",
1720                         (is_selflist(&RoomFlags))?"checked":"");
1721                 wc_printf(_("The URL for subscribe/unsubscribe is: "));
1722                 wc_printf("<TT>%s://%s/listsub</TT></td></tr>\n",
1723                         (is_https ? "https" : "http"),
1724                         ChrPtr(WC->Hdr->HR.http_host));
1725                 /* Public posting? */
1726                 wc_printf("<tr><td>");
1727                 wc_printf(_("Allow non-subscribers to mail to this room."));
1728                 wc_printf("</td><td><input type=\"checkbox\" name=\"QR2_SubsOnly\" value=\"yes\" %s></td></tr>\n",
1729                         (is_publiclist(&RoomFlags))?"checked":"");
1730                 
1731                 /* Moderated List? */
1732                 wc_printf("<tr><td>");
1733                 wc_printf(_("Room post publication needs Aide permission."));
1734                 wc_printf("</td><td><input type=\"checkbox\" name=\"QR2_Moderated\" value=\"yes\" %s></td></tr>\n",
1735                         (is_moderatedlist(&RoomFlags))?"checked":"");
1736
1737
1738                 wc_printf("<tr><td colspan=\"2\" align=\"center\">"
1739                         "<input type=\"submit\" NAME=\"add_button\" VALUE=\"%s\"></td></tr>", _("Save changes"));
1740                 wc_printf("</table></form>");
1741                         
1742
1743                 wc_printf("</CENTER>\n");
1744                 wc_printf("</div>");
1745         }
1746
1747
1748         /* Configuration of The Dreaded Auto-Purger */
1749         if (!strcmp(tab, "expire")) {
1750                 wc_printf("<div class=\"tabcontent\">");
1751
1752                 serv_puts("GPEX room");
1753                 serv_getln(buf, sizeof buf);
1754                 if (!strncmp(buf, "550", 3)) {
1755                         wc_printf("<br><br><div align=center>%s</div><br><br>\n",
1756                                 _("Higher access is required to access this function.")
1757                                 );
1758                 }
1759                 else if (buf[0] != '2') {
1760                         wc_printf("<br><br><div align=center>%s</div><br><br>\n", &buf[4]);
1761                 }
1762                 else {
1763                         roompolicy = extract_int(&buf[4], 0);
1764                         roomvalue = extract_int(&buf[4], 1);
1765                 
1766                         serv_puts("GPEX floor");
1767                         serv_getln(buf, sizeof buf);
1768                         if (buf[0] == '2') {
1769                                 floorpolicy = extract_int(&buf[4], 0);
1770                                 floorvalue = extract_int(&buf[4], 1);
1771                         }
1772                         
1773                         wc_printf("<br /><form method=\"POST\" action=\"set_room_policy\">\n");
1774                         wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1775                         wc_printf("<table border=0 cellspacing=5>\n");
1776                         wc_printf("<tr><td>");
1777                         wc_printf(_("Message expire policy for this room"));
1778                         wc_printf("<br />(");
1779                         escputs(ChrPtr(WC->CurRoom.name));
1780                         wc_printf(")</td><td>");
1781                         wc_printf("<input type=\"radio\" NAME=\"roompolicy\" VALUE=\"0\" %s>",
1782                                 ((roompolicy == 0) ? "CHECKED" : "") );
1783                         wc_printf(_("Use the default policy for this floor"));
1784                         wc_printf("<br />\n");
1785                         wc_printf("<input type=\"radio\" NAME=\"roompolicy\" VALUE=\"1\" %s>",
1786                                 ((roompolicy == 1) ? "CHECKED" : "") );
1787                         wc_printf(_("Never automatically expire messages"));
1788                         wc_printf("<br />\n");
1789                         wc_printf("<input type=\"radio\" NAME=\"roompolicy\" VALUE=\"2\" %s>",
1790                                 ((roompolicy == 2) ? "CHECKED" : "") );
1791                         wc_printf(_("Expire by message count"));
1792                         wc_printf("<br />\n");
1793                         wc_printf("<input type=\"radio\" NAME=\"roompolicy\" VALUE=\"3\" %s>",
1794                                 ((roompolicy == 3) ? "CHECKED" : "") );
1795                         wc_printf(_("Expire by message age"));
1796                         wc_printf("<br />");
1797                         wc_printf(_("Number of messages or days: "));
1798                         wc_printf("<input type=\"text\" NAME=\"roomvalue\" MAXLENGTH=\"5\" VALUE=\"%d\">", roomvalue);
1799                         wc_printf("</td></tr>\n");
1800         
1801                         if (WC->axlevel >= 6) {
1802                                 wc_printf("<tr><td COLSPAN=2><hr /></td></tr>\n");
1803                                 wc_printf("<tr><td>");
1804                                 wc_printf(_("Message expire policy for this floor"));
1805                                 wc_printf("<br />(");
1806                                 escputs(floorlist[WC->CurRoom.floorid]);
1807                                 wc_printf(")</td><td>");
1808                                 wc_printf("<input type=\"radio\" NAME=\"floorpolicy\" VALUE=\"0\" %s>",
1809                                         ((floorpolicy == 0) ? "CHECKED" : "") );
1810                                 wc_printf(_("Use the system default"));
1811                                 wc_printf("<br />\n");
1812                                 wc_printf("<input type=\"radio\" NAME=\"floorpolicy\" VALUE=\"1\" %s>",
1813                                         ((floorpolicy == 1) ? "CHECKED" : "") );
1814                                 wc_printf(_("Never automatically expire messages"));
1815                                 wc_printf("<br />\n");
1816                                 wc_printf("<input type=\"radio\" NAME=\"floorpolicy\" VALUE=\"2\" %s>",
1817                                         ((floorpolicy == 2) ? "CHECKED" : "") );
1818                                 wc_printf(_("Expire by message count"));
1819                                 wc_printf("<br />\n");
1820                                 wc_printf("<input type=\"radio\" NAME=\"floorpolicy\" VALUE=\"3\" %s>",
1821                                         ((floorpolicy == 3) ? "CHECKED" : "") );
1822                                 wc_printf(_("Expire by message age"));
1823                                 wc_printf("<br />");
1824                                 wc_printf(_("Number of messages or days: "));
1825                                 wc_printf("<input type=\"text\" NAME=\"floorvalue\" MAXLENGTH=\"5\" VALUE=\"%d\">",
1826                                         floorvalue);
1827                         }
1828         
1829                         wc_printf("<CENTER>\n");
1830                         wc_printf("<tr><td COLSPAN=2><hr /><CENTER>\n");
1831                         wc_printf("<input type=\"submit\" NAME=\"ok_button\" VALUE=\"%s\">", _("Save changes"));
1832                         wc_printf("&nbsp;");
1833                         wc_printf("<input type=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
1834                         wc_printf("</CENTER></td><tr>\n");
1835         
1836                         wc_printf("</table>\n"
1837                                 "<input type=\"hidden\" NAME=\"tab\" VALUE=\"expire\">\n"
1838                                 "</form>\n"
1839                                 );
1840                 }
1841
1842                 wc_printf("</div>");
1843         }
1844
1845         /* Access controls */
1846         if (!strcmp(tab, "access")) {
1847                 wc_printf("<div class=\"tabcontent\">");
1848                 display_whok();
1849                 wc_printf("</div>");
1850         }
1851
1852         /* Fetch messages from remote locations */
1853         if (!strcmp(tab, "feeds")) {
1854                 wc_printf("<div class=\"tabcontent\">");
1855
1856                 wc_printf("<i>");
1857                 wc_printf(_("Retrieve messages from these remote POP3 accounts and store them in this room:"));
1858                 wc_printf("</i><br />\n");
1859
1860                 wc_printf("<table class=\"altern\" border=0 cellpadding=5>"
1861                         "<tr class=\"even\"><th>");
1862                 wc_printf(_("Remote host"));
1863                 wc_printf("</th><th>");
1864                 wc_printf(_("User name"));
1865                 wc_printf("</th><th>");
1866                 wc_printf(_("Password"));
1867                 wc_printf("</th><th>");
1868                 wc_printf(_("Keep messages on server?"));
1869                 wc_printf("</th><th>");
1870                 wc_printf(_("Interval"));
1871                 wc_printf("</th><th> </th></tr>");
1872
1873                 serv_puts("GNET");
1874                 serv_getln(buf, sizeof buf);
1875                 bg = 1;
1876                 if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1877                                 extract_token(cmd, buf, 0, '|', sizeof cmd);
1878                                 if (!strcasecmp(cmd, "pop3client")) {
1879                                         safestrncpy(recp, &buf[11], sizeof recp);
1880
1881                                         bg = 1 - bg;
1882                                         wc_printf("<tr class=\"%s\">",
1883                                                 (bg ? "even" : "odd")
1884                                                 );
1885
1886                                         wc_printf("<td>");
1887                                         extract_token(pop3_host, buf, 1, '|', sizeof pop3_host);
1888                                         escputs(pop3_host);
1889                                         wc_printf("</td>");
1890
1891                                         wc_printf("<td>");
1892                                         extract_token(pop3_user, buf, 2, '|', sizeof pop3_user);
1893                                         escputs(pop3_user);
1894                                         wc_printf("</td>");
1895
1896                                         wc_printf("<td>*****</td>");            /* Don't show the password */
1897
1898                                         wc_printf("<td>%s</td>", extract_int(buf, 4) ? _("Yes") : _("No"));
1899
1900                                         wc_printf("<td>%ld</td>", extract_long(buf, 5));        /* Fetching interval */
1901                         
1902                                         wc_printf("<td class=\"button_link\">");
1903                                         wc_printf(" <a href=\"netedit?cmd=remove?tab=feeds?line=pop3client|");
1904                                         urlescputs(recp);
1905                                         wc_printf("\">");
1906                                         wc_printf(_("(remove)"));
1907                                         wc_printf("</a></td>");
1908                         
1909                                         wc_printf("</tr>");
1910                                 }
1911                         }
1912
1913                 wc_printf("<form method=\"POST\" action=\"netedit\">\n"
1914                         "<tr>"
1915                         "<input type=\"hidden\" name=\"tab\" value=\"feeds\">"
1916                         "<input type=\"hidden\" name=\"prefix\" value=\"pop3client|\">\n");
1917                 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1918                 wc_printf("<td>");
1919                 wc_printf("<input type=\"text\" id=\"add_as_pop3host\" NAME=\"line_pop3host\">\n");
1920                 wc_printf("</td>");
1921                 wc_printf("<td>");
1922                 wc_printf("<input type=\"text\" id=\"add_as_pop3user\" NAME=\"line_pop3user\">\n");
1923                 wc_printf("</td>");
1924                 wc_printf("<td>");
1925                 wc_printf("<input type=\"password\" id=\"add_as_pop3pass\" NAME=\"line_pop3pass\">\n");
1926                 wc_printf("</td>");
1927                 wc_printf("<td>");
1928                 wc_printf("<input type=\"checkbox\" id=\"add_as_pop3keep\" NAME=\"line_pop3keep\" VALUE=\"1\">");
1929                 wc_printf("</td>");
1930                 wc_printf("<td>");
1931                 wc_printf("<input type=\"text\" id=\"add_as_pop3int\" NAME=\"line_pop3int\" MAXLENGTH=\"5\">");
1932                 wc_printf("</td>");
1933                 wc_printf("<td>");
1934                 wc_printf("<input type=\"submit\" NAME=\"add_button\" VALUE=\"%s\">", _("Add"));
1935                 wc_printf("</td></tr>");
1936                 wc_printf("</form></table>\n");
1937
1938                 wc_printf("<hr>\n");
1939
1940                 wc_printf("<i>");
1941                 wc_printf(_("Fetch the following RSS feeds and store them in this room:"));
1942                 wc_printf("</i><br />\n");
1943
1944                 wc_printf("<table class=\"altern\" border=0 cellpadding=5>"
1945                         "<tr class=\"even\"><th>");
1946                 wc_printf("<img src=\"static/rss_16x.png\" width=\"16\" height=\"16\" alt=\" \"> ");
1947                 wc_printf(_("Feed URL"));
1948                 wc_printf("</th><th>");
1949                 wc_printf("</th></tr>");
1950
1951                 serv_puts("GNET");
1952                 serv_getln(buf, sizeof buf);
1953                 bg = 1;
1954                 if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1955                                 extract_token(cmd, buf, 0, '|', sizeof cmd);
1956                                 if (!strcasecmp(cmd, "rssclient")) {
1957                                         safestrncpy(recp, &buf[10], sizeof recp);
1958
1959                                         bg = 1 - bg;
1960                                         wc_printf("<tr class=\"%s\">",
1961                                                 (bg ? "even" : "odd")
1962                                                 );
1963
1964                                         wc_printf("<td>");
1965                                         extract_token(pop3_host, buf, 1, '|', sizeof pop3_host);
1966                                         escputs(pop3_host);
1967                                         wc_printf("</td>");
1968
1969                                         wc_printf("<td class=\"button_link\">");
1970                                         wc_printf(" <a href=\"netedit?cmd=remove?tab=feeds?line=rssclient|");
1971                                         urlescputs(recp);
1972                                         wc_printf("\">");
1973                                         wc_printf(_("(remove)"));
1974                                         wc_printf("</a></td>");
1975                         
1976                                         wc_printf("</tr>");
1977                                 }
1978                         }
1979
1980                 wc_printf("<form method=\"POST\" action=\"netedit\">\n"
1981                         "<tr>"
1982                         "<input type=\"hidden\" name=\"tab\" value=\"feeds\">"
1983                         "<input type=\"hidden\" name=\"prefix\" value=\"rssclient|\">\n");
1984                 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1985                 wc_printf("<td>");
1986                 wc_printf("<input type=\"text\" id=\"add_as_pop3host\" size=\"72\" "
1987                         "maxlength=\"256\" name=\"line_pop3host\">\n");
1988                 wc_printf("</td>");
1989                 wc_printf("<td>");
1990                 wc_printf("<input type=\"submit\" name=\"add_button\" value=\"%s\">", _("Add"));
1991                 wc_printf("</td></tr>");
1992                 wc_printf("</form></table>\n");
1993
1994                 wc_printf("</div>");
1995         }
1996
1997
1998         /* end content of whatever tab is open now */
1999         wc_printf("</div>\n");
2000
2001         address_book_popup();
2002         wDumpContent(1);
2003 }
2004
2005
2006 /* 
2007  * Toggle self-service list subscription
2008  */
2009 void toggle_self_service(void) {
2010         room_states RoomFlags;
2011
2012         get_roomflags (&RoomFlags);
2013
2014         if (yesbstr("QR2_SelfList")) 
2015                 RoomFlags.flags2 = RoomFlags.flags2 | QR2_SELFLIST;
2016         else 
2017                 RoomFlags.flags2 = RoomFlags.flags2 & ~QR2_SELFLIST;
2018
2019         if (yesbstr("QR2_SMTP_PUBLIC")) 
2020                 RoomFlags.flags2 = RoomFlags.flags2 | QR2_SMTP_PUBLIC;
2021         else
2022                 RoomFlags.flags2 = RoomFlags.flags2 & ~QR2_SMTP_PUBLIC;
2023
2024         if (yesbstr("QR2_Moderated")) 
2025                 RoomFlags.flags2 = RoomFlags.flags2 | QR2_MODERATED;
2026         else
2027                 RoomFlags.flags2 = RoomFlags.flags2 & ~QR2_MODERATED;
2028         if (yesbstr("QR2_SubsOnly")) 
2029                 RoomFlags.flags2 = RoomFlags.flags2 | QR2_SMTP_PUBLIC;
2030         else
2031                 RoomFlags.flags2 = RoomFlags.flags2 & ~QR2_SMTP_PUBLIC;
2032
2033         set_roomflags (&RoomFlags);
2034         
2035         display_editroom();
2036 }
2037
2038
2039
2040 /*
2041  * save new parameters for a room
2042  */
2043 void editroom(void)
2044 {
2045         const StrBuf *Ptr;
2046         StrBuf *Buf;
2047         StrBuf *er_name;
2048         StrBuf *er_password;
2049         StrBuf *er_dirname;
2050         StrBuf *er_roomaide;
2051         int er_floor;
2052         unsigned er_flags;
2053         int er_listingorder;
2054         int er_defaultview;
2055         unsigned er_flags2;
2056         int bump;
2057
2058
2059         if (!havebstr("ok_button")) {
2060                 strcpy(WC->ImportantMessage,
2061                        _("Cancelled.  Changes were not saved."));
2062                 display_editroom();
2063                 return;
2064         }
2065         serv_puts("GETR");
2066         Buf = NewStrBuf();
2067         StrBuf_ServGetln(Buf);
2068         if (GetServerStatus(Buf, NULL) != 2) {
2069                 StrBufCutLeft(Buf, 4);
2070                 strcpy(WC->ImportantMessage, ChrPtr(Buf));
2071                 display_editroom();
2072                 FreeStrBuf(&Buf);
2073                 return;
2074         }
2075
2076         er_name = NewStrBuf();
2077         er_password = NewStrBuf();
2078         er_dirname = NewStrBuf();
2079         er_roomaide = NewStrBuf();
2080
2081         StrBufCutLeft(Buf, 4);
2082         StrBufExtract_token(er_name, Buf, 0, '|');
2083         StrBufExtract_token(er_password, Buf, 1, '|');
2084         StrBufExtract_token(er_dirname, Buf, 2, '|');
2085         er_flags = StrBufExtract_int(Buf, 3, '|');
2086         er_listingorder = StrBufExtract_int(Buf, 5, '|');
2087         er_defaultview = StrBufExtract_int(Buf, 6, '|');
2088         er_flags2 = StrBufExtract_int(Buf, 7, '|');
2089
2090         er_roomaide = NewStrBufDup(sbstr("er_roomaide"));
2091         if (StrLength(er_roomaide) == 0) {
2092                 serv_puts("GETA");
2093                 StrBuf_ServGetln(Buf);
2094                 if (GetServerStatus(Buf, NULL) != 2) {
2095                         FlushStrBuf(er_roomaide);
2096                 } else {
2097                         StrBufCutLeft(Buf, 4);
2098                         StrBufExtract_token(er_roomaide, Buf, 0, '|');
2099                 }
2100         }
2101         Ptr = sbstr("er_name");
2102         if (StrLength(Ptr) > 0) {
2103                 FlushStrBuf(er_name);
2104                 StrBufAppendBuf(er_name, Ptr, 0);
2105         }
2106
2107         Ptr = sbstr("er_password");
2108         if (StrLength(Ptr) > 0) {
2109                 FlushStrBuf(er_password);
2110                 StrBufAppendBuf(er_password, Ptr, 0);
2111         }
2112                 
2113
2114         Ptr = sbstr("er_dirname");
2115         if (StrLength(Ptr) > 0) { /* todo: cut 15 */
2116                 FlushStrBuf(er_dirname);
2117                 StrBufAppendBuf(er_dirname, Ptr, 0);
2118         }
2119
2120
2121         Ptr = sbstr("type");
2122         er_flags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
2123
2124         if (!strcmp(ChrPtr(Ptr), "invonly")) {
2125                 er_flags |= (QR_PRIVATE);
2126         }
2127         if (!strcmp(ChrPtr(Ptr), "hidden")) {
2128                 er_flags |= (QR_PRIVATE | QR_GUESSNAME);
2129         }
2130         if (!strcmp(ChrPtr(Ptr), "passworded")) {
2131                 er_flags |= (QR_PRIVATE | QR_PASSWORDED);
2132         }
2133         if (!strcmp(ChrPtr(Ptr), "personal")) {
2134                 er_flags |= QR_MAILBOX;
2135         } else {
2136                 er_flags &= ~QR_MAILBOX;
2137         }
2138         
2139         if (yesbstr("prefonly")) {
2140                 er_flags |= QR_PREFONLY;
2141         } else {
2142                 er_flags &= ~QR_PREFONLY;
2143         }
2144
2145         if (yesbstr("readonly")) {
2146                 er_flags |= QR_READONLY;
2147         } else {
2148                 er_flags &= ~QR_READONLY;
2149         }
2150
2151         
2152         if (yesbstr("collabdel")) {
2153                 er_flags2 |= QR2_COLLABDEL;
2154         } else {
2155                 er_flags2 &= ~QR2_COLLABDEL;
2156         }
2157
2158         if (yesbstr("permanent")) {
2159                 er_flags |= QR_PERMANENT;
2160         } else {
2161                 er_flags &= ~QR_PERMANENT;
2162         }
2163
2164         if (yesbstr("subjectreq")) {
2165                 er_flags2 |= QR2_SUBJECTREQ;
2166         } else {
2167                 er_flags2 &= ~QR2_SUBJECTREQ;
2168         }
2169
2170         if (yesbstr("network")) {
2171                 er_flags |= QR_NETWORK;
2172         } else {
2173                 er_flags &= ~QR_NETWORK;
2174         }
2175
2176         if (yesbstr("directory")) {
2177                 er_flags |= QR_DIRECTORY;
2178         } else {
2179                 er_flags &= ~QR_DIRECTORY;
2180         }
2181
2182         if (yesbstr("ulallowed")) {
2183                 er_flags |= QR_UPLOAD;
2184         } else {
2185                 er_flags &= ~QR_UPLOAD;
2186         }
2187
2188         if (yesbstr("dlallowed")) {
2189                 er_flags |= QR_DOWNLOAD;
2190         } else {
2191                 er_flags &= ~QR_DOWNLOAD;
2192         }
2193
2194         if (yesbstr("visdir")) {
2195                 er_flags |= QR_VISDIR;
2196         } else {
2197                 er_flags &= ~QR_VISDIR;
2198         }
2199
2200         Ptr = sbstr("anon");
2201
2202         er_flags &= ~(QR_ANONONLY | QR_ANONOPT);
2203         if (!strcmp(ChrPtr(Ptr), "anononly"))
2204                 er_flags |= QR_ANONONLY;
2205         if (!strcmp(ChrPtr(Ptr), "anon2"))
2206                 er_flags |= QR_ANONOPT;
2207
2208         bump = yesbstr("bump");
2209
2210         er_floor = ibstr("er_floor");
2211
2212         StrBufPrintf(Buf, "SETR %s|%s|%s|%u|%d|%d|%d|%d|%u",
2213                      ChrPtr(er_name), 
2214                      ChrPtr(er_password), 
2215                      ChrPtr(er_dirname), 
2216                      er_flags, 
2217                      bump, 
2218                      er_floor,
2219                      er_listingorder, 
2220                      er_defaultview, 
2221                      er_flags2);
2222         serv_putbuf(Buf);
2223         StrBuf_ServGetln(Buf);
2224         if (GetServerStatus(Buf, NULL) != 2) {
2225                 strcpy(WC->ImportantMessage, &ChrPtr(Buf)[4]);
2226                 display_editroom();
2227                 FreeStrBuf(&Buf);
2228                 FreeStrBuf(&er_name);
2229                 FreeStrBuf(&er_password);
2230                 FreeStrBuf(&er_dirname);
2231                 FreeStrBuf(&er_roomaide);
2232                 return;
2233         }
2234         gotoroom(er_name);
2235
2236         if (StrLength(er_roomaide) > 0) {
2237                 serv_printf("SETA %s", ChrPtr(er_roomaide));
2238                 StrBuf_ServGetln(Buf);
2239                 if (GetServerStatus(Buf, NULL) != 2) {
2240                         strcpy(WC->ImportantMessage, &ChrPtr(Buf)[4]);
2241                         display_main_menu();
2242                         FreeStrBuf(&Buf);
2243                         FreeStrBuf(&er_name);
2244                         FreeStrBuf(&er_password);
2245                         FreeStrBuf(&er_dirname);
2246                         FreeStrBuf(&er_roomaide);
2247                         return;
2248                 }
2249         }
2250         gotoroom(er_name);
2251         strcpy(WC->ImportantMessage, _("Your changes have been saved."));
2252         display_editroom();
2253         FreeStrBuf(&Buf);
2254         FreeStrBuf(&er_name);
2255         FreeStrBuf(&er_password);
2256         FreeStrBuf(&er_dirname);
2257         FreeStrBuf(&er_roomaide);
2258         return;
2259 }
2260
2261
2262 /*
2263  * Display form for Invite, Kick, and show Who Knows a room
2264  */
2265 void do_invt_kick(void) {
2266         char buf[SIZ], room[SIZ], username[SIZ];
2267
2268         serv_puts("GETR");
2269         serv_getln(buf, sizeof buf);
2270
2271         if (buf[0] != '2') {
2272                 escputs(&buf[4]);
2273                 return;
2274         }
2275         extract_token(room, &buf[4], 0, '|', sizeof room);
2276
2277         strcpy(username, bstr("username"));
2278
2279         if (havebstr("kick_button")) {
2280                 sprintf(buf, "KICK %s", username);
2281                 serv_puts(buf);
2282                 serv_getln(buf, sizeof buf);
2283
2284                 if (buf[0] != '2') {
2285                         strcpy(WC->ImportantMessage, &buf[4]);
2286                 } else {
2287                         sprintf(WC->ImportantMessage,
2288                                 _("<B><I>User %s kicked out of room %s.</I></B>\n"), 
2289                                 username, room);
2290                 }
2291         }
2292
2293         if (havebstr("invite_button")) {
2294                 sprintf(buf, "INVT %s", username);
2295                 serv_puts(buf);
2296                 serv_getln(buf, sizeof buf);
2297
2298                 if (buf[0] != '2') {
2299                         strcpy(WC->ImportantMessage, &buf[4]);
2300                 } else {
2301                         sprintf(WC->ImportantMessage,
2302                                 _("<B><I>User %s invited to room %s.</I></B>\n"), 
2303                                 username, room);
2304                 }
2305         }
2306
2307         display_editroom();
2308 }
2309
2310
2311
2312 /*
2313  * Display form for Invite, Kick, and show Who Knows a room
2314  */
2315 void display_whok(void)
2316 {
2317         char buf[SIZ], room[SIZ], username[SIZ];
2318
2319         serv_puts("GETR");
2320         serv_getln(buf, sizeof buf);
2321
2322         if (buf[0] != '2') {
2323                 escputs(&buf[4]);
2324                 return;
2325         }
2326         extract_token(room, &buf[4], 0, '|', sizeof room);
2327
2328         
2329         wc_printf("<table border=0 CELLSPACING=10><tr VALIGN=TOP><td>");
2330         wc_printf(_("The users listed below have access to this room.  "
2331                   "To remove a user from the access list, select the user "
2332                   "name from the list and click 'Kick'."));
2333         wc_printf("<br /><br />");
2334         
2335         wc_printf("<CENTER><form method=\"POST\" action=\"do_invt_kick\">\n");
2336         wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
2337         wc_printf("<input type=\"hidden\" NAME=\"tab\" VALUE=\"access\">\n");
2338         wc_printf("<select NAME=\"username\" SIZE=\"10\" style=\"width:100%%\">\n");
2339         serv_puts("WHOK");
2340         serv_getln(buf, sizeof buf);
2341         if (buf[0] == '1') {
2342                 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2343                         extract_token(username, buf, 0, '|', sizeof username);
2344                         wc_printf("<OPTION>");
2345                         escputs(username);
2346                         wc_printf("\n");
2347                 }
2348         }
2349         wc_printf("</select><br />\n");
2350
2351         wc_printf("<input type=\"submit\" name=\"kick_button\" value=\"%s\">", _("Kick"));
2352         wc_printf("</form></CENTER>\n");
2353
2354         wc_printf("</td><td>");
2355         wc_printf(_("To grant another user access to this room, enter the "
2356                   "user name in the box below and click 'Invite'."));
2357         wc_printf("<br /><br />");
2358
2359         wc_printf("<CENTER><form method=\"POST\" action=\"do_invt_kick\">\n");
2360         wc_printf("<input type=\"hidden\" NAME=\"tab\" VALUE=\"access\">\n");
2361         wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
2362         wc_printf(_("Invite:"));
2363         wc_printf(" ");
2364         wc_printf("<input type=\"text\" name=\"username\" id=\"username_id\" style=\"width:100%%\"><br />\n"
2365                 "<input type=\"hidden\" name=\"invite_button\" value=\"Invite\">"
2366                 "<input type=\"submit\" value=\"%s\">"
2367                 "</form></CENTER>\n", _("Invite"));
2368         /* Pop open an address book -- begin **/
2369         wc_printf(
2370                 "<a href=\"javascript:PopOpenAddressBook('username_id|%s');\" "
2371                 "title=\"%s\">"
2372                 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
2373                 "&nbsp;%s</a>",
2374                 _("User"), 
2375                 _("Users"), _("Users")
2376                 );
2377         /* Pop open an address book -- end **/
2378
2379         wc_printf("</td></tr></table>\n");
2380         address_book_popup();
2381         wDumpContent(1);
2382 }
2383
2384
2385
2386 /*
2387  * display the form for entering a new room
2388  */
2389 void display_entroom(void)
2390 {
2391         StrBuf *Buf;
2392         int i;
2393         char buf[SIZ];
2394
2395         Buf = NewStrBuf();
2396         serv_puts("CRE8 0");
2397         serv_getln(buf, sizeof buf);
2398
2399         if (buf[0] != '2') {
2400                 strcpy(WC->ImportantMessage, &buf[4]);
2401                 display_main_menu();
2402                 FreeStrBuf(&Buf);
2403                 return;
2404         }
2405
2406         output_headers(1, 1, 1, 0, 0, 0);
2407
2408         svprintf(HKEY("BOXTITLE"), WCS_STRING, _("Create a new room"));
2409         do_template("beginbox", NULL);
2410
2411         wc_printf("<form name=\"create_room_form\" method=\"POST\" action=\"entroom\">\n");
2412         wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
2413
2414         wc_printf("<table class=\"altern\"> ");
2415
2416         wc_printf("<tr class=\"even\"><td>");
2417         wc_printf(_("Name of room: "));
2418         wc_printf("</td><td>");
2419         wc_printf("<input type=\"text\" NAME=\"er_name\" MAXLENGTH=\"127\">\n");
2420         wc_printf("</td></tr>");
2421
2422         wc_printf("<tr class=\"odd\"><td>");
2423         wc_printf(_("Resides on floor: "));
2424         wc_printf("</td><td>");
2425         load_floorlist(Buf); 
2426         wc_printf("<select name=\"er_floor\" size=\"1\">\n");
2427         for (i = 0; i < 128; ++i)
2428                 if (!IsEmptyStr(floorlist[i])) {
2429                         wc_printf("<option ");
2430                         wc_printf("value=\"%d\">", i);
2431                         escputs(floorlist[i]);
2432                         wc_printf("</option>\n");
2433                 }
2434         wc_printf("</select>\n");
2435         wc_printf("</td></tr>");
2436
2437         /*
2438          * Our clever little snippet of JavaScript automatically selects
2439          * a public room if the view is set to Bulletin Board or wiki, and
2440          * it selects a mailbox room otherwise.  The user can override this,
2441          * of course.  We also disable the floor selector for mailboxes.
2442          */
2443         wc_printf("<tr class=\"even\"><td>");
2444         wc_printf(_("Default view for room: "));
2445         wc_printf("</td><td>");
2446         wc_printf("<select name=\"er_view\" size=\"1\" OnChange=\""
2447                 "       if ( (this.form.er_view.value == 0)             "
2448                 "          || (this.form.er_view.value == 6) ) {        "
2449                 "               this.form.type[0].checked=true;         "
2450                 "               this.form.er_floor.disabled = false;    "
2451                 "       }                                               "
2452                 "       else {                                          "
2453                 "               this.form.type[4].checked=true;         "
2454                 "               this.form.er_floor.disabled = true;     "
2455                 "       }                                               "
2456                 "\">\n");
2457         for (i=0; i<(sizeof viewdefs / sizeof (char *)); ++i) {
2458                 if (is_view_allowed_as_default(i)) {
2459                         wc_printf("<option %s value=\"%d\">",
2460                                 ((i == 0) ? "selected" : ""), i );
2461                         escputs(viewdefs[i]);
2462                         wc_printf("</option>\n");
2463                 }
2464         }
2465         wc_printf("</select>\n");
2466         wc_printf("</td></tr>");
2467
2468         wc_printf("<tr class=\"even\"><td>");
2469         wc_printf(_("Type of room:"));
2470         wc_printf("</td><td>");
2471         wc_printf("<ul class=\"adminlist\">\n");
2472
2473         wc_printf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"public\" ");
2474         wc_printf("CHECKED OnChange=\""
2475                 "       if (this.form.type[0].checked == true) {        "
2476                 "               this.form.er_floor.disabled = false;    "
2477                 "       }                                               "
2478                 "\"> ");
2479         wc_printf(_("Public (automatically appears to everyone)"));
2480         wc_printf("</li>");
2481
2482         wc_printf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"hidden\" OnChange=\""
2483                 "       if (this.form.type[1].checked == true) {        "
2484                 "               this.form.er_floor.disabled = false;    "
2485                 "       }                                               "
2486                 "\"> ");
2487         wc_printf(_("Private - hidden (accessible to anyone who knows its name)"));
2488         wc_printf("</li>");
2489
2490         wc_printf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"passworded\" OnChange=\""
2491                 "       if (this.form.type[2].checked == true) {        "
2492                 "               this.form.er_floor.disabled = false;    "
2493                 "       }                                               "
2494                 "\"> ");
2495         wc_printf(_("Private - require password: "));
2496         wc_printf("<input type=\"text\" NAME=\"er_password\" MAXLENGTH=\"9\">\n");
2497         wc_printf("</li>");
2498
2499         wc_printf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"invonly\" OnChange=\""
2500                 "       if (this.form.type[3].checked == true) {        "
2501                 "               this.form.er_floor.disabled = false;    "
2502                 "       }                                               "
2503                 "\"> ");
2504         wc_printf(_("Private - invitation only"));
2505         wc_printf("</li>");
2506
2507         wc_printf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"personal\" "
2508                 "OnChange=\""
2509                 "       if (this.form.type[4].checked == true) {        "
2510                 "               this.form.er_floor.disabled = true;     "
2511                 "       }                                               "
2512                 "\"> ");
2513         wc_printf(_("Personal (mailbox for you only)"));
2514         wc_printf("</li>");
2515
2516         wc_printf("\n</ul>\n");
2517         wc_printf("</td></tr></table>\n");
2518
2519         wc_printf("<div class=\"buttons\">\n");
2520         wc_printf("<input type=\"submit\" name=\"ok_button\" value=\"%s\">", _("Create new room"));
2521         wc_printf("&nbsp;");
2522         wc_printf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">", _("Cancel"));
2523         wc_printf("</div>\n");
2524         wc_printf("</form>\n<hr />");
2525         serv_printf("MESG roomaccess");
2526         serv_getln(buf, sizeof buf);
2527         if (buf[0] == '1') {
2528                 fmout("LEFT");
2529         }
2530
2531         do_template("endbox", NULL);
2532
2533         wDumpContent(1);
2534         FreeStrBuf(&Buf);
2535 }
2536
2537
2538
2539
2540 /*
2541  * support function for entroom() -- sets the default view 
2542  */
2543 void er_set_default_view(int newview) {
2544
2545         char buf[SIZ];
2546
2547         char rm_name[SIZ];
2548         char rm_pass[SIZ];
2549         char rm_dir[SIZ];
2550         int rm_bits1;
2551         int rm_floor;
2552         int rm_listorder;
2553         int rm_bits2;
2554
2555         serv_puts("GETR");
2556         serv_getln(buf, sizeof buf);
2557         if (buf[0] != '2') return;
2558
2559         extract_token(rm_name, &buf[4], 0, '|', sizeof rm_name);
2560         extract_token(rm_pass, &buf[4], 1, '|', sizeof rm_pass);
2561         extract_token(rm_dir, &buf[4], 2, '|', sizeof rm_dir);
2562         rm_bits1 = extract_int(&buf[4], 3);
2563         rm_floor = extract_int(&buf[4], 4);
2564         rm_listorder = extract_int(&buf[4], 5);
2565         rm_bits2 = extract_int(&buf[4], 7);
2566
2567         serv_printf("SETR %s|%s|%s|%d|0|%d|%d|%d|%d",
2568                     rm_name, rm_pass, rm_dir, rm_bits1, rm_floor,
2569                     rm_listorder, newview, rm_bits2
2570                 );
2571         serv_getln(buf, sizeof buf);
2572 }
2573
2574
2575
2576 /*
2577  * Create a new room
2578  */
2579 void entroom(void)
2580 {
2581         char buf[SIZ];
2582         const StrBuf *er_name;
2583         const StrBuf *er_type;
2584         const StrBuf *er_password;
2585         int er_floor;
2586         int er_num_type;
2587         int er_view;
2588         wcsession *WCC = WC;
2589
2590         if (!havebstr("ok_button")) {
2591                 strcpy(WC->ImportantMessage,
2592                        _("Cancelled.  No new room was created."));
2593                 display_main_menu();
2594                 return;
2595         }
2596         er_name = sbstr("er_name");
2597         er_type = sbstr("type");
2598         er_password = sbstr("er_password");
2599         er_floor = ibstr("er_floor");
2600         er_view = ibstr("er_view");
2601
2602         er_num_type = 0;
2603         if (!strcmp(ChrPtr(er_type), "hidden"))
2604                 er_num_type = 1;
2605         else if (!strcmp(ChrPtr(er_type), "passworded"))
2606                 er_num_type = 2;
2607         else if (!strcmp(ChrPtr(er_type), "invonly"))
2608                 er_num_type = 3;
2609         else if (!strcmp(ChrPtr(er_type), "personal"))
2610                 er_num_type = 4;
2611
2612         serv_printf("CRE8 1|%s|%d|%s|%d|%d|%d", 
2613                     ChrPtr(er_name), 
2614                     er_num_type, 
2615                     ChrPtr(er_password), 
2616                     er_floor, 
2617                     0, 
2618                     er_view);
2619
2620         serv_getln(buf, sizeof buf);
2621         if (buf[0] != '2') {
2622                 strcpy(WCC->ImportantMessage, &buf[4]);
2623                 display_main_menu();
2624                 return;
2625         }
2626         /** TODO: Room created, now update the left hand icon bar for this user */
2627         burn_folder_cache(0);   /* burn the old folder cache */
2628         
2629         gotoroom(er_name);
2630
2631         serv_printf("VIEW %d", er_view);
2632         serv_getln(buf, sizeof buf);
2633         WCC->CurRoom.view = er_view;
2634
2635         if ( (WCC != NULL) && ( (WCC->CurRoom.RAFlags & UA_ADMINALLOWED) != 0) )  {
2636                 display_editroom ();
2637         } else {
2638                 do_change_view(er_view);                /* Now go there */
2639         }
2640
2641 }
2642
2643
2644 /**
2645  * \brief display the screen to enter a private room
2646  */
2647 void display_private(char *rname, int req_pass)
2648 {
2649         WCTemplputParams SubTP;
2650         StrBuf *Buf;
2651         output_headers(1, 1, 1, 0, 0, 0);
2652
2653         Buf = NewStrBufPlain(_("Go to a hidden room"), -1);
2654         memset(&SubTP, 0, sizeof(WCTemplputParams));
2655         SubTP.Filter.ContextType = CTX_STRBUF;
2656         SubTP.Context = Buf;
2657         DoTemplate(HKEY("beginbox"), NULL, &SubTP);
2658
2659         FreeStrBuf(&Buf);
2660
2661         wc_printf("<p>");
2662         wc_printf(_("If you know the name of a hidden (guess-name) or "
2663                   "passworded room, you can enter that room by typing "
2664                   "its name below.  Once you gain access to a private "
2665                   "room, it will appear in your regular room listings "
2666                   "so you don't have to keep returning here."));
2667         wc_printf("</p>");
2668
2669         wc_printf("<form method=\"post\" action=\"goto_private\">\n");
2670         wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
2671
2672         wc_printf("<table class=\"altern\"> "
2673                 "<tr class=\"even\"><td>");
2674         wc_printf(_("Enter room name:"));
2675         wc_printf("</td><td>"
2676                 "<input type=\"text\" name=\"gr_name\" "
2677                 "value=\"%s\" maxlength=\"128\">\n", rname);
2678
2679         if (req_pass) {
2680                 wc_printf("</td></tr><tr class=\"odd\"><td>");
2681                 wc_printf(_("Enter room password:"));
2682                 wc_printf("</td><td>");
2683                 wc_printf("<input type=\"password\" name=\"gr_pass\" maxlength=\"9\">\n");
2684         }
2685         wc_printf("</td></tr></table>\n");
2686
2687         wc_printf("<div class=\"buttons\">\n");
2688         wc_printf("<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
2689                 "&nbsp;"
2690                 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">",
2691                 _("Go there"),
2692                 _("Cancel")
2693                 );
2694         wc_printf("</div></form>\n");
2695
2696         do_template("endbox", NULL);
2697
2698         wDumpContent(1);
2699 }
2700
2701 /**
2702  * \brief goto a private room
2703  */
2704 void goto_private(void)
2705 {
2706         char hold_rm[SIZ];
2707         char buf[SIZ];
2708
2709         if (!havebstr("ok_button")) {
2710                 display_main_menu();
2711                 return;
2712         }
2713         strcpy(hold_rm, ChrPtr(WC->CurRoom.name));
2714         serv_printf("GOTO %s|%s",
2715                     bstr("gr_name"),
2716                     bstr("gr_pass"));
2717         serv_getln(buf, sizeof buf);
2718
2719         if (buf[0] == '2') {
2720                 smart_goto(sbstr("gr_name"));
2721                 return;
2722         }
2723         if (!strncmp(buf, "540", 3)) {
2724                 display_private(bstr("gr_name"), 1);
2725                 return;
2726         }
2727         output_headers(1, 1, 1, 0, 0, 0);
2728         wc_printf("%s\n", &buf[4]);
2729         wDumpContent(1);
2730         return;
2731 }
2732
2733
2734 /**
2735  * \brief display the screen to zap a room
2736  */
2737 void display_zap(void)
2738 {
2739         output_headers(1, 1, 2, 0, 0, 0);
2740
2741         wc_printf("<div id=\"banner\">\n");
2742         wc_printf("<h1>");
2743         wc_printf(_("Zap (forget/unsubscribe) the current room"));
2744         wc_printf("</h1>\n");
2745         wc_printf("</div>\n");
2746
2747         wc_printf("<div id=\"content\" class=\"service\">\n");
2748
2749         wc_printf(_("If you select this option, <em>%s</em> will "
2750                   "disappear from your room list.  Is this what you wish "
2751                   "to do?<br />\n"), ChrPtr(WC->CurRoom.name));
2752
2753         wc_printf("<form method=\"POST\" action=\"zap\">\n");
2754         wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
2755         wc_printf("<input type=\"submit\" NAME=\"ok_button\" VALUE=\"%s\">", _("Zap this room"));
2756         wc_printf("&nbsp;");
2757         wc_printf("<input type=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
2758         wc_printf("</form>\n");
2759         wDumpContent(1);
2760 }
2761
2762
2763 /**
2764  * \brief zap a room
2765  */
2766 void zap(void)
2767 {
2768         char buf[SIZ];
2769         StrBuf *final_destination;
2770
2771         /**
2772          * If the forget-room routine fails for any reason, we fall back
2773          * to the current room; otherwise, we go to the Lobby
2774          */
2775         final_destination = NewStrBufDup(WC->CurRoom.name);
2776
2777         if (havebstr("ok_button")) {
2778                 serv_printf("GOTO %s", ChrPtr(WC->CurRoom.name));
2779                 serv_getln(buf, sizeof buf);
2780                 if (buf[0] == '2') {
2781                         serv_puts("FORG");
2782                         serv_getln(buf, sizeof buf);
2783                         if (buf[0] == '2') {
2784                                 FlushStrBuf(final_destination);
2785                                 StrBufAppendBufPlain(final_destination, HKEY("_BASEROOM_"), 0);
2786                         }
2787                 }
2788         }
2789         smart_goto(final_destination);
2790         FreeStrBuf(&final_destination);
2791 }
2792
2793
2794
2795 /**
2796  * \brief Delete the current room
2797  */
2798 void delete_room(void)
2799 {
2800         char buf[SIZ];
2801
2802         
2803         serv_puts("KILL 1");
2804         serv_getln(buf, sizeof buf);
2805         burn_folder_cache(0);   /* Burn the cahce of known rooms to update the icon bar */
2806         if (buf[0] != '2') {
2807                 strcpy(WC->ImportantMessage, &buf[4]);
2808                 display_main_menu();
2809                 return;
2810         } else {
2811                 StrBuf *Buf;
2812                 
2813                 Buf = NewStrBufPlain(HKEY("_BASEROOM_"));
2814                 smart_goto(Buf);
2815                 FreeStrBuf(&Buf);
2816         }
2817 }
2818
2819
2820
2821 /**
2822  * \brief Perform changes to a room's network configuration
2823  */
2824 void netedit(void) {
2825         FILE *fp;
2826         char buf[SIZ];
2827         char line[SIZ];
2828         char cmpa0[SIZ];
2829         char cmpa1[SIZ];
2830         char cmpb0[SIZ];
2831         char cmpb1[SIZ];
2832         int i, num_addrs;
2833         /*/ TODO: do line dynamic! */
2834         if (havebstr("line_pop3host")) {
2835                 strcpy(line, bstr("prefix"));
2836                 strcat(line, bstr("line_pop3host"));
2837                 strcat(line, "|");
2838                 strcat(line, bstr("line_pop3user"));
2839                 strcat(line, "|");
2840                 strcat(line, bstr("line_pop3pass"));
2841                 strcat(line, "|");
2842                 strcat(line, ibstr("line_pop3keep") ? "1" : "0" );
2843                 strcat(line, "|");
2844                 sprintf(&line[strlen(line)],"%ld", lbstr("line_pop3int"));
2845                 strcat(line, bstr("suffix"));
2846         }
2847         else if (havebstr("line")) {
2848                 strcpy(line, bstr("prefix"));
2849                 strcat(line, bstr("line"));
2850                 strcat(line, bstr("suffix"));
2851         }
2852         else {
2853                 display_editroom();
2854                 return;
2855         }
2856
2857
2858         fp = tmpfile();
2859         if (fp == NULL) {
2860                 display_editroom();
2861                 return;
2862         }
2863
2864         serv_puts("GNET");
2865         serv_getln(buf, sizeof buf);
2866         if (buf[0] != '1') {
2867                 fclose(fp);
2868                 display_editroom();
2869                 return;
2870         }
2871
2872         /** This loop works for add *or* remove.  Spiffy, eh? */
2873         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2874                 extract_token(cmpa0, buf, 0, '|', sizeof cmpa0);
2875                 extract_token(cmpa1, buf, 1, '|', sizeof cmpa1);
2876                 extract_token(cmpb0, line, 0, '|', sizeof cmpb0);
2877                 extract_token(cmpb1, line, 1, '|', sizeof cmpb1);
2878                 if ( (strcasecmp(cmpa0, cmpb0)) 
2879                      || (strcasecmp(cmpa1, cmpb1)) ) {
2880                         fprintf(fp, "%s\n", buf);
2881                 }
2882         }
2883
2884         rewind(fp);
2885         serv_puts("SNET");
2886         serv_getln(buf, sizeof buf);
2887         if (buf[0] != '4') {
2888                 fclose(fp);
2889                 display_editroom();
2890                 return;
2891         }
2892
2893         while (fgets(buf, sizeof buf, fp) != NULL) {
2894                 buf[strlen(buf)-1] = 0;
2895                 serv_puts(buf);
2896         }
2897
2898         if (havebstr("add_button")) {
2899                 num_addrs = num_tokens(bstr("line"), ',');
2900                 if (num_addrs < 2) {
2901                         /* just adding one node or address */
2902                         serv_puts(line);
2903                 }
2904                 else {
2905                         /* adding multiple addresses separated by commas */
2906                         for (i=0; i<num_addrs; ++i) {
2907                                 strcpy(line, bstr("prefix"));
2908                                 extract_token(buf, bstr("line"), i, ',', sizeof buf);
2909                                 striplt(buf);
2910                                 strcat(line, buf);
2911                                 strcat(line, bstr("suffix"));
2912                                 serv_puts(line);
2913                         }
2914                 }
2915         }
2916
2917         serv_puts("000");
2918         fclose(fp);
2919         display_editroom();
2920 }
2921
2922
2923
2924 /**
2925  * \brief Convert a room name to a folder-ish-looking name.
2926  * \param folder the folderish name
2927  * \param room the room name
2928  * \param floor the floor name
2929  * \param is_mailbox is it a mailbox?
2930  */
2931 void room_to_folder(char *folder, char *room, int floor, int is_mailbox)
2932 {
2933         int i, len;
2934
2935         /**
2936          * For mailboxes, just do it straight...
2937          */
2938         if (is_mailbox) {
2939                 sprintf(folder, "My folders|%s", room);
2940         }
2941
2942         /**
2943          * Otherwise, prefix the floor name as a "public folders" moniker
2944          */
2945         else {
2946                 if (floor > MAX_FLOORS) {
2947                         wc_backtrace ();
2948                         sprintf(folder, "%%%%%%|%s", room);
2949                 }
2950                 else {
2951                         sprintf(folder, "%s|%s", floorlist[floor], room);
2952                 }
2953         }
2954
2955         /**
2956          * Replace "\" characters with "|" for pseudo-folder-delimiting
2957          */
2958         len = strlen (folder);
2959         for (i=0; i<len; ++i) {
2960                 if (folder[i] == '\\') folder[i] = '|';
2961         }
2962 }
2963
2964
2965
2966
2967 /**
2968  * \brief Back end for change_view()
2969  * \param newview set newview???
2970  */
2971 void do_change_view(int newview) {
2972         char buf[SIZ];
2973
2974         serv_printf("VIEW %d", newview);
2975         serv_getln(buf, sizeof buf);
2976         WC->CurRoom.view = newview;
2977         smart_goto(WC->CurRoom.name);
2978 }
2979
2980
2981
2982 /**
2983  * \brief Change the view for this room
2984  */
2985 void change_view(void) {
2986         int view;
2987
2988         view = lbstr("view");
2989         do_change_view(view);
2990 }
2991
2992 /**
2993  * \brief Burn the cached folder list.  
2994  * \param age How old the cahce needs to be before we burn it.
2995  */
2996
2997 void burn_folder_cache(time_t age)
2998 {
2999         /** If our cached folder list is very old, burn it. */
3000         if (WC->cache_fold != NULL) {
3001                 if ((time(NULL) - WC->cache_timestamp) > age) {
3002                         free(WC->cache_fold);
3003                         WC->cache_fold = NULL;
3004                 }
3005         }
3006 }
3007
3008
3009
3010 /**
3011  * \brief Do either a known rooms list or a folders list, depending on the
3012  * user's preference
3013  */
3014 void knrooms(void)
3015 {
3016         StrBuf *ListView = NULL;
3017
3018         /** Determine whether the user is trying to change views */
3019         if (havebstr("view")) {
3020                 ListView = NewStrBufDup(SBSTR("view"));
3021                 set_preference("roomlistview", ListView, 1);
3022         }
3023         /** Sanitize the input so its safe */
3024         if((get_preference("roomlistview", &ListView) != 0)||
3025            ((strcasecmp(ChrPtr(ListView), "folders") != 0) &&
3026             (strcasecmp(ChrPtr(ListView), "table") != 0))) 
3027         {
3028                 if (ListView == NULL) {
3029                         ListView = NewStrBufPlain(HKEY("rooms"));
3030                         set_preference("roomlistview", ListView, 0);
3031                         ListView = NULL;
3032                 }
3033                 else {
3034                         ListView = NewStrBufPlain(HKEY("rooms"));
3035                         set_preference("roomlistview", ListView, 0);
3036                         ListView = NULL;
3037                 }
3038         }
3039         FreeStrBuf(&ListView);
3040         url_do_template();
3041 }
3042
3043
3044
3045 /**
3046  * \brief Set the message expire policy for this room and/or floor
3047  */
3048 void set_room_policy(void) {
3049         char buf[SIZ];
3050
3051         if (!havebstr("ok_button")) {
3052                 strcpy(WC->ImportantMessage,
3053                        _("Cancelled.  Changes were not saved."));
3054                 display_editroom();
3055                 return;
3056         }
3057
3058         serv_printf("SPEX room|%d|%d", ibstr("roompolicy"), ibstr("roomvalue"));
3059         serv_getln(buf, sizeof buf);
3060         strcpy(WC->ImportantMessage, &buf[4]);
3061
3062         if (WC->axlevel >= 6) {
3063                 strcat(WC->ImportantMessage, "<br />\n");
3064                 serv_printf("SPEX floor|%d|%d", ibstr("floorpolicy"), ibstr("floorvalue"));
3065                 serv_getln(buf, sizeof buf);
3066                 strcat(WC->ImportantMessage, &buf[4]);
3067         }
3068
3069         display_editroom();
3070 }
3071
3072 void tmplput_RoomName(StrBuf *Target, WCTemplputParams *TP)
3073 {
3074         StrBufAppendTemplate(Target, TP, WC->CurRoom.name, 0);
3075 }
3076
3077
3078 void _display_private(void) {
3079         display_private("", 0);
3080 }
3081
3082 void dotgoto(void) {
3083         if (!havebstr("room")) {
3084                 readloop(readnew, eUseDefault);
3085                 return;
3086         }
3087         if (WC->CurRoom.view != VIEW_MAILBOX) { /* dotgoto acts like dotskip when we're in a mailbox view */
3088                 slrp_highest();
3089         }
3090         smart_goto(sbstr("room"));
3091 }
3092
3093
3094
3095 void tmplput_current_room(StrBuf *Target, WCTemplputParams *TP)
3096 {
3097         wcsession *WCC = WC;
3098
3099         if (WCC != NULL)
3100                 StrBufAppendTemplate(Target, TP, 
3101                                      WCC->CurRoom.name, 
3102                                      0); 
3103 }
3104
3105 void tmplput_roombanner(StrBuf *Target, WCTemplputParams *TP)
3106 {
3107         wc_printf("<div id=\"banner\">\n");
3108         embed_room_banner(NULL, navbar_default);
3109         wc_printf("</div>\n");
3110 }
3111
3112
3113 void tmplput_ungoto(StrBuf *Target, WCTemplputParams *TP)
3114 {
3115         wcsession *WCC = WC;
3116
3117         if ((WCC!=NULL) && 
3118             (!IsEmptyStr(WCC->ugname)))
3119                 StrBufAppendBufPlain(Target, WCC->ugname, -1, 0);
3120 }
3121
3122 int ConditionalRoomAide(StrBuf *Target, WCTemplputParams *TP)
3123 {
3124         wcsession *WCC = WC;
3125         return (WCC != NULL)? 
3126                 ((WCC->CurRoom.RAFlags & UA_ADMINALLOWED) != 0) : 0;
3127 }
3128
3129 int ConditionalRoomAcessDelete(StrBuf *Target, WCTemplputParams *TP)
3130 {
3131         wcsession *WCC = WC;
3132         return (WCC == NULL)? 0 : 
3133                 ( ((WCC->CurRoom.RAFlags & UA_ADMINALLOWED) != 0) ||
3134                    (WCC->CurRoom.is_inbox) || 
3135                    (WCC->CurRoom.QRFlags2 & QR2_COLLABDEL) );
3136 }
3137
3138 int ConditionalHaveUngoto(StrBuf *Target, WCTemplputParams *TP)
3139 {
3140         wcsession *WCC = WC;
3141         
3142         return ((WCC!=NULL) && 
3143                 (!IsEmptyStr(WCC->ugname)) && 
3144                 (strcasecmp(WCC->ugname, ChrPtr(WCC->CurRoom.name)) == 0));
3145 }
3146
3147 int ConditionalCurrentRoomHas_QRFlag(StrBuf *Target, WCTemplputParams *TP)
3148 {
3149         long QR_CheckFlag;
3150         wcsession *WCC = WC;
3151         
3152         QR_CheckFlag = GetTemplateTokenNumber(Target, TP, 2, 0);
3153         if (QR_CheckFlag == 0)
3154                 LogTemplateError(Target, "Conditional", ERR_PARM1, TP,
3155                                  "requires one of the #\"QR*\"- defines or an integer flag 0 is invalid!");
3156
3157         return ((WCC!=NULL) &&
3158                 ((WCC->CurRoom.QRFlags & QR_CheckFlag) != 0));
3159 }
3160
3161 int ConditionalRoomHas_QRFlag(StrBuf *Target, WCTemplputParams *TP)
3162 {
3163         long QR_CheckFlag;
3164         folder *Folder = (folder *)(TP->Context);
3165
3166         QR_CheckFlag = GetTemplateTokenNumber(Target, TP, 2, 0);
3167         if (QR_CheckFlag == 0)
3168                 LogTemplateError(Target, "Conditional", ERR_PARM1, TP,
3169                                  "requires one of the #\"QR*\"- defines or an integer flag 0 is invalid!");
3170         return ((Folder->QRFlags & QR_CheckFlag) != 0);
3171 }
3172
3173
3174 int ConditionalCurrentRoomHas_QRFlag2(StrBuf *Target, WCTemplputParams *TP)
3175 {
3176         long QR2_CheckFlag;
3177         wcsession *WCC = WC;
3178         
3179         QR2_CheckFlag = GetTemplateTokenNumber(Target, TP, 2, 0);
3180         if (QR2_CheckFlag == 0)
3181                 LogTemplateError(Target, "Conditional", ERR_PARM1, TP,
3182                                  "requires one of the #\"QR2*\"- defines or an integer flag 0 is invalid!");
3183
3184         return ((WCC!=NULL) &&
3185                 ((WCC->CurRoom.QRFlags2 & QR2_CheckFlag) != 0));
3186 }
3187
3188 int ConditionalRoomHas_QRFlag2(StrBuf *Target, WCTemplputParams *TP)
3189 {
3190         long QR2_CheckFlag;
3191         folder *Folder = (folder *)(TP->Context);
3192
3193         QR2_CheckFlag = GetTemplateTokenNumber(Target, TP, 2, 0);
3194         if (QR2_CheckFlag == 0)
3195                 LogTemplateError(Target, "Conditional", ERR_PARM1, TP,
3196                                  "requires one of the #\"QR2*\"- defines or an integer flag 0 is invalid!");
3197         return ((Folder->QRFlags2 & QR2_CheckFlag) != 0);
3198 }
3199
3200
3201 int ConditionalHaveRoomeditRights(StrBuf *Target, WCTemplputParams *TP)
3202 {
3203         wcsession *WCC = WC;
3204
3205         return ( (WCC!= NULL) && 
3206                  ((WCC->axlevel >= 6) || 
3207                   ((WCC->CurRoom.RAFlags & UA_ADMINALLOWED) != 0) ||
3208                   (WCC->CurRoom.is_inbox) ));
3209 }
3210
3211 int ConditionalIsRoomtype(StrBuf *Target, WCTemplputParams *TP)
3212 {
3213         wcsession *WCC = WC;
3214
3215         if ((WCC == NULL) ||
3216             (TP->Tokens->nParameters < 3))
3217                 return 0;
3218         return WCC->CurRoom.view == GetTemplateTokenNumber(Target, TP, 2, VIEW_BBS);
3219 }
3220
3221 void 
3222 InitModule_ROOMOPS
3223 (void)
3224 {
3225         RegisterPreference("roomlistview",
3226                            _("Room list view"),
3227                            PRF_STRING,
3228                            NULL);
3229         RegisterPreference("emptyfloors", _("Show empty floors"), PRF_YESNO, NULL);
3230
3231         RegisterNamespace("ROOMNAME", 0, 1, tmplput_RoomName, NULL, CTX_NONE);
3232
3233         WebcitAddUrlHandler(HKEY("knrooms"), "", 0, knrooms, 0);
3234         WebcitAddUrlHandler(HKEY("dotgoto"), "", 0, dotgoto, NEED_URL);
3235         WebcitAddUrlHandler(HKEY("dotskip"), "", 0, dotskip, NEED_URL);
3236         WebcitAddUrlHandler(HKEY("display_private"), "", 0, _display_private, 0);
3237         WebcitAddUrlHandler(HKEY("goto_private"), "", 0, goto_private, NEED_URL);
3238         WebcitAddUrlHandler(HKEY("zapped_list"), "", 0, zapped_list, 0);
3239         WebcitAddUrlHandler(HKEY("display_zap"), "", 0, display_zap, 0);
3240         WebcitAddUrlHandler(HKEY("zap"), "", 0, zap, 0);
3241         WebcitAddUrlHandler(HKEY("display_entroom"), "", 0, display_entroom, 0);
3242         WebcitAddUrlHandler(HKEY("entroom"), "", 0, entroom, 0);
3243         WebcitAddUrlHandler(HKEY("display_whok"), "", 0, display_whok, 0);
3244         WebcitAddUrlHandler(HKEY("do_invt_kick"), "", 0, do_invt_kick, 0);
3245         WebcitAddUrlHandler(HKEY("display_editroom"), "", 0, display_editroom, 0);
3246         WebcitAddUrlHandler(HKEY("netedit"), "", 0, netedit, 0);
3247         WebcitAddUrlHandler(HKEY("editroom"), "", 0, editroom, 0);
3248         WebcitAddUrlHandler(HKEY("delete_room"), "", 0, delete_room, 0);
3249         WebcitAddUrlHandler(HKEY("set_room_policy"), "", 0, set_room_policy, 0);
3250         WebcitAddUrlHandler(HKEY("changeview"), "", 0, change_view, 0);
3251         WebcitAddUrlHandler(HKEY("toggle_self_service"), "", 0, toggle_self_service, 0);
3252         RegisterNamespace("ROOMBANNER", 0, 1, tmplput_roombanner, NULL, CTX_NONE);
3253
3254         RegisterConditional(HKEY("COND:ROOM:TYPE_IS"), 0, ConditionalIsRoomtype, CTX_NONE);
3255         RegisterConditional(HKEY("COND:THISROOM:FLAG:QR"), 0, ConditionalCurrentRoomHas_QRFlag, CTX_NONE);
3256         RegisterConditional(HKEY("COND:ROOM:FLAG:QR"), 0, ConditionalRoomHas_QRFlag, CTX_ROOMS);
3257
3258         RegisterConditional(HKEY("COND:THISROOM:FLAG:QR2"), 0, ConditionalCurrentRoomHas_QRFlag2, CTX_NONE);
3259         RegisterConditional(HKEY("COND:ROOM:FLAG:QR2"), 0, ConditionalRoomHas_QRFlag2, CTX_ROOMS);
3260
3261         REGISTERTokenParamDefine(QR_PERMANENT);
3262         REGISTERTokenParamDefine(QR_INUSE);
3263         REGISTERTokenParamDefine(QR_PRIVATE);
3264         REGISTERTokenParamDefine(QR_PASSWORDED);
3265         REGISTERTokenParamDefine(QR_GUESSNAME);
3266         REGISTERTokenParamDefine(QR_DIRECTORY);
3267         REGISTERTokenParamDefine(QR_UPLOAD);
3268         REGISTERTokenParamDefine(QR_DOWNLOAD);
3269         REGISTERTokenParamDefine(QR_VISDIR);
3270         REGISTERTokenParamDefine(QR_ANONONLY);
3271         REGISTERTokenParamDefine(QR_ANONOPT);
3272         REGISTERTokenParamDefine(QR_NETWORK);
3273         REGISTERTokenParamDefine(QR_PREFONLY);
3274         REGISTERTokenParamDefine(QR_READONLY);
3275         REGISTERTokenParamDefine(QR_MAILBOX);
3276         REGISTERTokenParamDefine(QR2_SYSTEM);
3277         REGISTERTokenParamDefine(QR2_SELFLIST);
3278         REGISTERTokenParamDefine(QR2_COLLABDEL);
3279         REGISTERTokenParamDefine(QR2_SUBJECTREQ);
3280         REGISTERTokenParamDefine(QR2_SMTP_PUBLIC);
3281         REGISTERTokenParamDefine(QR2_MODERATED);
3282
3283         REGISTERTokenParamDefine(UA_KNOWN);
3284         REGISTERTokenParamDefine(UA_GOTOALLOWED);
3285         REGISTERTokenParamDefine(UA_HASNEWMSGS);
3286         REGISTERTokenParamDefine(UA_ZAPPED);
3287         REGISTERTokenParamDefine(UA_POSTALLOWED);
3288         REGISTERTokenParamDefine(UA_ADMINALLOWED);
3289         REGISTERTokenParamDefine(UA_DELETEALLOWED);
3290         REGISTERTokenParamDefine(UA_ISTRASH);
3291
3292         REGISTERTokenParamDefine(US_NEEDVALID);
3293         REGISTERTokenParamDefine(US_PERM);
3294         REGISTERTokenParamDefine(US_LASTOLD);
3295         REGISTERTokenParamDefine(US_EXPERT);
3296         REGISTERTokenParamDefine(US_UNLISTED);
3297         REGISTERTokenParamDefine(US_NOPROMPT);
3298         REGISTERTokenParamDefine(US_PROMPTCTL);
3299         REGISTERTokenParamDefine(US_DISAPPEAR);
3300         REGISTERTokenParamDefine(US_REGIS);
3301         REGISTERTokenParamDefine(US_PAGINATOR);
3302         REGISTERTokenParamDefine(US_INTERNET);
3303         REGISTERTokenParamDefine(US_FLOORS);
3304         REGISTERTokenParamDefine(US_COLOR);
3305         REGISTERTokenParamDefine(US_USER_SET);
3306
3307         REGISTERTokenParamDefine(VIEW_BBS);
3308         REGISTERTokenParamDefine(VIEW_MAILBOX); 
3309         REGISTERTokenParamDefine(VIEW_ADDRESSBOOK);
3310         REGISTERTokenParamDefine(VIEW_CALENDAR);        
3311         REGISTERTokenParamDefine(VIEW_TASKS);   
3312         REGISTERTokenParamDefine(VIEW_NOTES);           
3313         REGISTERTokenParamDefine(VIEW_WIKI);            
3314         REGISTERTokenParamDefine(VIEW_CALBRIEF);
3315         REGISTERTokenParamDefine(VIEW_JOURNAL);
3316         REGISTERTokenParamDefine(VIEW_BLOG);
3317
3318
3319         REGISTERTokenParamDefine(ignet_push_share);
3320         REGISTERTokenParamDefine(listrecp);
3321         REGISTERTokenParamDefine(digestrecp);
3322         REGISTERTokenParamDefine(pop3client);
3323         REGISTERTokenParamDefine(rssclient);
3324         REGISTERTokenParamDefine(participate);
3325
3326         RegisterConditional(HKEY("COND:ROOMAIDE"), 2, ConditionalRoomAide, CTX_NONE);
3327         RegisterConditional(HKEY("COND:ACCESS:DELETE"), 2, ConditionalRoomAcessDelete, CTX_NONE);
3328
3329         RegisterConditional(HKEY("COND:UNGOTO"), 0, ConditionalHaveUngoto, CTX_NONE);
3330         RegisterConditional(HKEY("COND:ROOM:EDITACCESS"), 0, ConditionalHaveRoomeditRights, CTX_NONE);
3331
3332         RegisterNamespace("CURRENT_ROOM", 0, 1, tmplput_current_room, NULL, CTX_NONE);
3333         RegisterNamespace("ROOM:UNGOTO", 0, 0, tmplput_ungoto, NULL, CTX_NONE);
3334         RegisterIterator("FLOORS", 0, NULL, GetFloorListHash, NULL, NULL, CTX_FLOORS, CTX_NONE, IT_NOFLAG);
3335
3336
3337 }
3338
3339
3340 void 
3341 SessionDestroyModule_ROOMOPS
3342 (wcsession *sess)
3343 {
3344         FlushFolder(&sess->CurRoom);
3345         if (sess->cache_fold != NULL) {
3346                 free(sess->cache_fold);
3347         }
3348         
3349         free_march_list(sess);
3350         DeleteHash(&sess->Floors);
3351 }
3352 /*@}*/