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