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