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