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