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