* fix select-o-matic
[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 void tmplput_RoomViewString(StrBuf *Target, WCTemplputParams *TP) 
1136 {
1137         long CheckThis;
1138         StrBuf *Buf;
1139
1140         CheckThis = GetTemplateTokenNumber(Target, TP, 0, 0);
1141         if ((CheckThis >= VIEW_MAX) || (CheckThis < VIEW_BBS))
1142         {
1143                 LogTemplateError(Target, "Token", ERR_PARM2, TP,
1144                                  "Roomview [%ld] not valid\n", 
1145                                  CheckThis);
1146                 return;
1147         }
1148
1149         Buf = NewStrBufPlain(_(viewdefs[CheckThis]), -1);
1150         StrBufAppendTemplate(Target, TP, Buf, 0);
1151         FreeStrBuf(&Buf);
1152 }
1153
1154
1155 /*
1156  * goto next room
1157  */
1158 void smart_goto(const StrBuf *next_room) {
1159         gotoroom(next_room);
1160         readloop(readnew, eUseDefault);
1161 }
1162
1163
1164
1165 /*
1166  * mark all messages in current room as having been read
1167  */
1168 void slrp_highest(void)
1169 {
1170         char buf[256];
1171
1172         serv_puts("SLRP HIGHEST");
1173         serv_getln(buf, sizeof buf);
1174 }
1175
1176
1177 typedef struct __room_states {
1178         char password[SIZ];
1179         char dirname[SIZ];
1180         char name[SIZ];
1181         int flags;
1182         int floor;
1183         int order;
1184         int view;
1185         int flags2;
1186 } room_states;
1187
1188
1189
1190
1191 /*
1192  * Set/clear/read the "self-service list subscribe" flag for a room
1193  * 
1194  * set newval to 0 to clear, 1 to set, any other value to leave unchanged.
1195  * returns the new value.
1196  */
1197
1198 int self_service(int newval) {
1199         int current_value = 0;
1200         char buf[SIZ];
1201         
1202         char name[SIZ];
1203         char password[SIZ];
1204         char dirname[SIZ];
1205         int flags, floor, order, view, flags2;
1206
1207         serv_puts("GETR");
1208         serv_getln(buf, sizeof buf);
1209         if (buf[0] != '2') return(0);
1210
1211         extract_token(name, &buf[4], 0, '|', sizeof name);
1212         extract_token(password, &buf[4], 1, '|', sizeof password);
1213         extract_token(dirname, &buf[4], 2, '|', sizeof dirname);
1214         flags = extract_int(&buf[4], 3);
1215         floor = extract_int(&buf[4], 4);
1216         order = extract_int(&buf[4], 5);
1217         view = extract_int(&buf[4], 6);
1218         flags2 = extract_int(&buf[4], 7);
1219
1220         if (flags2 & QR2_SELFLIST) {
1221                 current_value = 1;
1222         }
1223         else {
1224                 current_value = 0;
1225         }
1226
1227         if (newval == 1) {
1228                 flags2 = flags2 | QR2_SELFLIST;
1229         }
1230         else if (newval == 0) {
1231                 flags2 = flags2 & ~QR2_SELFLIST;
1232         }
1233         else {
1234                 return(current_value);
1235         }
1236
1237         if (newval != current_value) {
1238                 serv_printf("SETR %s|%s|%s|%d|0|%d|%d|%d|%d",
1239                             name, password, dirname, flags,
1240                             floor, order, view, flags2);
1241                 serv_getln(buf, sizeof buf);
1242         }
1243
1244         return(newval);
1245
1246 }
1247
1248 int is_selflist(room_states *RoomFlags)
1249 {
1250         return ((RoomFlags->flags2 & QR2_SELFLIST) != 0);
1251 }
1252
1253 int is_publiclist(room_states *RoomFlags)
1254 {
1255         return ((RoomFlags->flags2 & QR2_SMTP_PUBLIC) != 0);
1256 }
1257
1258 int is_moderatedlist(room_states *RoomFlags)
1259 {
1260         return ((RoomFlags->flags2 & QR2_MODERATED) != 0);
1261 }
1262
1263 /*
1264  * Set/clear/read the "self-service list subscribe" flag for a room
1265  * 
1266  * set newval to 0 to clear, 1 to set, any other value to leave unchanged.
1267  * returns the new value.
1268  */
1269
1270 int get_roomflags(room_states *RoomOps) 
1271 {
1272         char buf[SIZ];
1273         
1274         serv_puts("GETR");
1275         serv_getln(buf, sizeof buf);
1276         if (buf[0] != '2') return(0);
1277
1278         extract_token(RoomOps->name, &buf[4], 0, '|', sizeof RoomOps->name);
1279         extract_token(RoomOps->password, &buf[4], 1, '|', sizeof RoomOps->password);
1280         extract_token(RoomOps->dirname, &buf[4], 2, '|', sizeof RoomOps->dirname);
1281         RoomOps->flags = extract_int(&buf[4], 3);
1282         RoomOps->floor = extract_int(&buf[4], 4);
1283         RoomOps->order = extract_int(&buf[4], 5);
1284         RoomOps->view = extract_int(&buf[4], 6);
1285         RoomOps->flags2 = extract_int(&buf[4], 7);
1286         return (1);
1287 }
1288
1289 int set_roomflags(room_states *RoomOps)
1290 {
1291         char buf[SIZ];
1292
1293         serv_printf("SETR %s|%s|%s|%d|0|%d|%d|%d|%d",
1294                     RoomOps->name, 
1295                     RoomOps->password, 
1296                     RoomOps->dirname, 
1297                     RoomOps->flags,
1298                     RoomOps->floor, 
1299                     RoomOps->order, 
1300                     RoomOps->view, 
1301                     RoomOps->flags2);
1302         serv_getln(buf, sizeof buf);
1303         return (1);
1304 }
1305
1306
1307
1308
1309
1310
1311 /*
1312  * display the form for editing a room
1313  */
1314 void display_editroom(void)
1315 {
1316         StrBuf *Buf;
1317         char buf[SIZ];
1318         char cmd[1024];
1319         char node[256];
1320         char remote_room[128];
1321         char recp[1024];
1322         char er_name[128];
1323         char er_password[10];
1324         char er_dirname[15];
1325         char er_roomaide[26];
1326         unsigned er_flags;
1327         unsigned er_flags2;
1328         int er_floor;
1329         int i, j;
1330         char *tab;
1331         char *shared_with;
1332         char *not_shared_with = NULL;
1333         int roompolicy = 0;
1334         int roomvalue = 0;
1335         int floorpolicy = 0;
1336         int floorvalue = 0;
1337         char pop3_host[128];
1338         char pop3_user[32];
1339         int bg = 0;
1340
1341         tab = bstr("tab");
1342         if (IsEmptyStr(tab)) tab = "admin";
1343
1344         Buf = NewStrBuf();
1345         load_floorlist(Buf);
1346         FreeStrBuf(&Buf);
1347         output_headers(1, 1, 1, 0, 0, 0);
1348
1349         wc_printf("<div class=\"fix_scrollbar_bug\">");
1350
1351         wc_printf("<br />\n");
1352
1353         /* print the tabbed dialog */
1354         wc_printf("<div align=\"center\">");
1355         wc_printf("<table id=\"AdminTabs\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"
1356                 "<tr align=\"center\" style=\"cursor:pointer\"><td>&nbsp;</td>"
1357                 );
1358
1359         wc_printf("<td class=\"");
1360         if (!strcmp(tab, "admin")) {
1361                 wc_printf(" tab_cell_label\">");
1362                 wc_printf(_("Administration"));
1363         }
1364         else {
1365                 wc_printf("< tab_cell_edit\"><a href=\"display_editroom?tab=admin\">");
1366                 wc_printf(_("Administration"));
1367                 wc_printf("</a>");
1368         }
1369         wc_printf("</td>\n");
1370         wc_printf("<td>&nbsp;</td>\n");
1371
1372         if ( ConditionalHaveRoomeditRights(NULL, NULL)) {
1373
1374                 wc_printf("<td class=\"");
1375                 if (!strcmp(tab, "config")) {
1376                         wc_printf(" tab_cell_label\">");
1377                         wc_printf(_("Configuration"));
1378                 }
1379                 else {
1380                         wc_printf(" tab_cell_edit\"><a href=\"display_editroom?tab=config\">");
1381                         wc_printf(_("Configuration"));
1382                         wc_printf("</a>");
1383                 }
1384                 wc_printf("</td>\n");
1385                 wc_printf("<td>&nbsp;</td>\n");
1386
1387                 wc_printf("<td class=\"");
1388                 if (!strcmp(tab, "expire")) {
1389                         wc_printf(" tab_cell_label\">");
1390                         wc_printf(_("Message expire policy"));
1391                 }
1392                 else {
1393                         wc_printf(" tab_cell_edit\"><a href=\"display_editroom?tab=expire\">");
1394                         wc_printf(_("Message expire policy"));
1395                         wc_printf("</a>");
1396                 }
1397                 wc_printf("</td>\n");
1398                 wc_printf("<td>&nbsp;</td>\n");
1399         
1400                 wc_printf("<td class=\"");
1401                 if (!strcmp(tab, "access")) {
1402                         wc_printf(" tab_cell_label\">");
1403                         wc_printf(_("Access controls"));
1404                 }
1405                 else {
1406                         wc_printf(" tab_cell_edit\"><a href=\"display_editroom?tab=access\">");
1407                         wc_printf(_("Access controls"));
1408                         wc_printf("</a>");
1409                 }
1410                 wc_printf("</td>\n");
1411                 wc_printf("<td>&nbsp;</td>\n");
1412
1413                 wc_printf("<td class=\"");
1414                 if (!strcmp(tab, "sharing")) {
1415                         wc_printf(" tab_cell_label\">");
1416                         wc_printf(_("Sharing"));
1417                 }
1418                 else {
1419                         wc_printf(" tab_cell_edit\"><a href=\"display_editroom?tab=sharing\">");
1420                         wc_printf(_("Sharing"));
1421                         wc_printf("</a>");
1422                 }
1423                 wc_printf("</td>\n");
1424                 wc_printf("<td>&nbsp;</td>\n");
1425
1426                 wc_printf("<td class=\"");
1427                 if (!strcmp(tab, "listserv")) {
1428                         wc_printf(" tab_cell_label\">");
1429                         wc_printf(_("Mailing list service"));
1430                 }
1431                 else {
1432                         wc_printf("< tab_cell_edit\"><a href=\"display_editroom?tab=listserv\">");
1433                         wc_printf(_("Mailing list service"));
1434                         wc_printf("</a>");
1435                 }
1436                 wc_printf("</td>\n");
1437                 wc_printf("<td>&nbsp;</td>\n");
1438
1439         }
1440
1441         wc_printf("<td class=\"");
1442         if (!strcmp(tab, "feeds")) {
1443                 wc_printf(" tab_cell_label\">");
1444                 wc_printf(_("Remote retrieval"));
1445         }
1446         else {
1447                 wc_printf("< tab_cell_edit\"><a href=\"display_editroom?tab=feeds\">");
1448                 wc_printf(_("Remote retrieval"));
1449                 wc_printf("</a>");
1450         }
1451         wc_printf("</td>\n");
1452         wc_printf("<td>&nbsp;</td>\n");
1453
1454         wc_printf("</tr></table>\n");
1455         wc_printf("</div>\n");
1456         /* end tabbed dialog */ 
1457
1458         wc_printf("<script type=\"text/javascript\">"
1459                 " Nifty(\"table#AdminTabs td\", \"small transparent top\");"
1460                 "</script>"
1461                 );
1462
1463         /* begin content of whatever tab is open now */
1464
1465         if (!strcmp(tab, "admin")) {
1466                 wc_printf("<div class=\"tabcontent\">");
1467                 wc_printf("<ul>"
1468                         "<li><a href=\"delete_room\" "
1469                         "onClick=\"return confirm('");
1470                 wc_printf(_("Are you sure you want to delete this room?"));
1471                 wc_printf("');\">\n");
1472                 wc_printf(_("Delete this room"));
1473                 wc_printf("</a>\n"
1474                         "<li><a href=\"display_editroompic?which_room=");
1475                 urlescputs(ChrPtr(WC->CurRoom.name));
1476                 wc_printf("\">\n");
1477                 wc_printf(_("Set or change the icon for this room's banner"));
1478                 wc_printf("</a>\n"
1479                         "<li><a href=\"display_editinfo\">\n");
1480                 wc_printf(_("Edit this room's Info file"));
1481                 wc_printf("</a>\n"
1482                         "</ul>");
1483                 wc_printf("</div>");
1484         }
1485
1486         if (!strcmp(tab, "config")) {
1487                 wc_printf("<div class=\"tabcontent\">");
1488                 serv_puts("GETR");
1489                 serv_getln(buf, sizeof buf);
1490
1491                 if (!strncmp(buf, "550", 3)) {
1492                         wc_printf("<br><br><div align=center>%s</div><br><br>\n",
1493                                 _("Higher access is required to access this function.")
1494                                 );
1495                 }
1496                 else if (buf[0] != '2') {
1497                         wc_printf("<br><br><div align=center>%s</div><br><br>\n", &buf[4]);
1498                 }
1499                 else {
1500                         extract_token(er_name, &buf[4], 0, '|', sizeof er_name);
1501                         extract_token(er_password, &buf[4], 1, '|', sizeof er_password);
1502                         extract_token(er_dirname, &buf[4], 2, '|', sizeof er_dirname);
1503                         er_flags = extract_int(&buf[4], 3);
1504                         er_floor = extract_int(&buf[4], 4);
1505                         er_flags2 = extract_int(&buf[4], 7);
1506         
1507                         wc_printf("<form method=\"POST\" action=\"editroom\">\n");
1508                         wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1509                 
1510                         wc_printf("<ul><li>");
1511                         wc_printf(_("Name of room: "));
1512                         wc_printf("<input type=\"text\" NAME=\"er_name\" VALUE=\"%s\" MAXLENGTH=\""ULONG_FMT"\">\n",
1513                                 er_name,
1514                                 (sizeof(er_name)-1)
1515                                 );
1516                 
1517                         wc_printf("<li>");
1518                         wc_printf(_("Resides on floor: "));
1519                         wc_printf("<select NAME=\"er_floor\" SIZE=\"1\"");
1520                         if (er_flags & QR_MAILBOX)
1521                                 wc_printf("disabled >\n");
1522                         for (i = 0; i < 128; ++i)
1523                                 if (!IsEmptyStr(floorlist[i])) {
1524                                         wc_printf("<OPTION ");
1525                                         if (i == er_floor )
1526                                                 wc_printf("SELECTED ");
1527                                         wc_printf("VALUE=\"%d\">", i);
1528                                         escputs(floorlist[i]);
1529                                         wc_printf("</OPTION>\n");
1530                                 }
1531                         wc_printf("</select>\n");
1532
1533                         wc_printf("<li>");
1534                         wc_printf(_("Type of room:"));
1535                         wc_printf("<ul>\n");
1536         
1537                         wc_printf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"public\" ");
1538                         if ((er_flags & (QR_PRIVATE + QR_MAILBOX)) == 0)
1539                                 wc_printf("CHECKED ");
1540                         wc_printf("OnChange=\""
1541                                 "       if (this.form.type[0].checked == true) {        "
1542                                 "               this.form.er_floor.disabled = false;    "
1543                                 "       }                                               "
1544                                 "\"> ");
1545                         wc_printf(_("Public (automatically appears to everyone)"));
1546                         wc_printf("\n");
1547         
1548                         wc_printf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"hidden\" ");
1549                         if ((er_flags & QR_PRIVATE) &&
1550                             (er_flags & QR_GUESSNAME))
1551                                 wc_printf("CHECKED ");
1552                         wc_printf(" OnChange=\""
1553                                 "       if (this.form.type[1].checked == true) {        "
1554                                 "               this.form.er_floor.disabled = false;    "
1555                                 "       }                                               "
1556                                 "\"> ");
1557                         wc_printf(_("Private - hidden (accessible to anyone who knows its name)"));
1558                 
1559                         wc_printf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
1560                         if ((er_flags & QR_PRIVATE) &&
1561                             (er_flags & QR_PASSWORDED))
1562                                 wc_printf("CHECKED ");
1563                         wc_printf(" OnChange=\""
1564                                 "       if (this.form.type[2].checked == true) {        "
1565                                 "               this.form.er_floor.disabled = false;    "
1566                                 "       }                                               "
1567                                 "\"> ");
1568                         wc_printf(_("Private - require password: "));
1569                         wc_printf("\n<input type=\"text\" NAME=\"er_password\" VALUE=\"%s\" MAXLENGTH=\"9\">\n",
1570                                 er_password);
1571                 
1572                         wc_printf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
1573                         if ((er_flags & QR_PRIVATE)
1574                             && ((er_flags & QR_GUESSNAME) == 0)
1575                             && ((er_flags & QR_PASSWORDED) == 0))
1576                                 wc_printf("CHECKED ");
1577                         wc_printf(" OnChange=\""
1578                                 "       if (this.form.type[3].checked == true) {        "
1579                                 "               this.form.er_floor.disabled = false;    "
1580                                 "       }                                               "
1581                                 "\"> ");
1582                         wc_printf(_("Private - invitation only"));
1583                 
1584                         wc_printf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"personal\" ");
1585                         if (er_flags & QR_MAILBOX)
1586                                 wc_printf("CHECKED ");
1587                         wc_printf (" OnChange=\""
1588                                  "      if (this.form.type[4].checked == true) {        "
1589                                  "              this.form.er_floor.disabled = true;     "
1590                                  "      }                                               "
1591                                  "\"> ");
1592                         wc_printf(_("Personal (mailbox for you only)"));
1593                         
1594                         wc_printf("\n<li><input type=\"checkbox\" NAME=\"bump\" VALUE=\"yes\" ");
1595                         wc_printf("> ");
1596                         wc_printf(_("If private, cause current users to forget room"));
1597                 
1598                         wc_printf("\n</ul>\n");
1599                 
1600                         wc_printf("<li><input type=\"checkbox\" NAME=\"prefonly\" VALUE=\"yes\" ");
1601                         if (er_flags & QR_PREFONLY)
1602                                 wc_printf("CHECKED ");
1603                         wc_printf("> ");
1604                         wc_printf(_("Preferred users only"));
1605                 
1606                         wc_printf("\n<li><input type=\"checkbox\" NAME=\"readonly\" VALUE=\"yes\" ");
1607                         if (er_flags & QR_READONLY)
1608                                 wc_printf("CHECKED ");
1609                         wc_printf("> ");
1610                         wc_printf(_("Read-only room"));
1611                 
1612                         wc_printf("\n<li><input type=\"checkbox\" NAME=\"collabdel\" VALUE=\"yes\" ");
1613                         if (er_flags2 & QR2_COLLABDEL)
1614                                 wc_printf("CHECKED ");
1615                         wc_printf("> ");
1616                         wc_printf(_("All users allowed to post may also delete messages"));
1617                 
1618                         /** directory stuff */
1619                         wc_printf("\n<li><input type=\"checkbox\" NAME=\"directory\" VALUE=\"yes\" ");
1620                         if (er_flags & QR_DIRECTORY)
1621                                 wc_printf("CHECKED ");
1622                         wc_printf("> ");
1623                         wc_printf(_("File directory room"));
1624         
1625                         wc_printf("\n<ul><li>");
1626                         wc_printf(_("Directory name: "));
1627                         wc_printf("<input type=\"text\" NAME=\"er_dirname\" VALUE=\"%s\" MAXLENGTH=\"14\">\n",
1628                                 er_dirname);
1629         
1630                         wc_printf("<li><input type=\"checkbox\" NAME=\"ulallowed\" VALUE=\"yes\" ");
1631                         if (er_flags & QR_UPLOAD)
1632                                 wc_printf("CHECKED ");
1633                         wc_printf("> ");
1634                         wc_printf(_("Uploading allowed"));
1635                 
1636                         wc_printf("\n<li><input type=\"checkbox\" NAME=\"dlallowed\" VALUE=\"yes\" ");
1637                         if (er_flags & QR_DOWNLOAD)
1638                                 wc_printf("CHECKED ");
1639                         wc_printf("> ");
1640                         wc_printf(_("Downloading allowed"));
1641                 
1642                         wc_printf("\n<li><input type=\"checkbox\" NAME=\"visdir\" VALUE=\"yes\" ");
1643                         if (er_flags & QR_VISDIR)
1644                                 wc_printf("CHECKED ");
1645                         wc_printf("> ");
1646                         wc_printf(_("Visible directory"));
1647                         wc_printf("</ul>\n");
1648                 
1649                         /** end of directory stuff */
1650         
1651                         wc_printf("<li><input type=\"checkbox\" NAME=\"network\" VALUE=\"yes\" ");
1652                         if (er_flags & QR_NETWORK)
1653                                 wc_printf("CHECKED ");
1654                         wc_printf("> ");
1655                         wc_printf(_("Network shared room"));
1656         
1657                         wc_printf("\n<li><input type=\"checkbox\" NAME=\"permanent\" VALUE=\"yes\" ");
1658                         if (er_flags & QR_PERMANENT)
1659                                 wc_printf("CHECKED ");
1660                         wc_printf("> ");
1661                         wc_printf(_("Permanent (does not auto-purge)"));
1662         
1663                         wc_printf("\n<li><input type=\"checkbox\" NAME=\"subjectreq\" VALUE=\"yes\" ");
1664                         if (er_flags2 & QR2_SUBJECTREQ)
1665                                 wc_printf("CHECKED ");
1666                         wc_printf("> ");
1667                         wc_printf(_("Subject Required (Force users to specify a message subject)"));
1668         
1669                         /** start of anon options */
1670                 
1671                         wc_printf("\n<li>");
1672                         wc_printf(_("Anonymous messages"));
1673                         wc_printf("<ul>\n");
1674                 
1675                         wc_printf("<li><input type=\"radio\" NAME=\"anon\" VALUE=\"no\" ");
1676                         if (((er_flags & QR_ANONONLY) == 0)
1677                             && ((er_flags & QR_ANONOPT) == 0))
1678                                 wc_printf("CHECKED ");
1679                         wc_printf("> ");
1680                         wc_printf(_("No anonymous messages"));
1681         
1682                         wc_printf("\n<li><input type=\"radio\" NAME=\"anon\" VALUE=\"anononly\" ");
1683                         if (er_flags & QR_ANONONLY)
1684                                 wc_printf("CHECKED ");
1685                         wc_printf("> ");
1686                         wc_printf(_("All messages are anonymous"));
1687                 
1688                         wc_printf("\n<li><input type=\"radio\" NAME=\"anon\" VALUE=\"anon2\" ");
1689                         if (er_flags & QR_ANONOPT)
1690                                 wc_printf("CHECKED ");
1691                         wc_printf("> ");
1692                         wc_printf(_("Prompt user when entering messages"));
1693                         wc_printf("</ul>\n");
1694                 
1695                         /* end of anon options */
1696                 
1697                         wc_printf("<li>");
1698                         wc_printf(_("Room aide: "));
1699                         serv_puts("GETA");
1700                         serv_getln(buf, sizeof buf);
1701                         if (buf[0] != '2') {
1702                                 wc_printf("<em>%s</em>\n", &buf[4]);
1703                         } else {
1704                                 extract_token(er_roomaide, &buf[4], 0, '|', sizeof er_roomaide);
1705                                 wc_printf("<input type=\"text\" NAME=\"er_roomaide\" VALUE=\"%s\" MAXLENGTH=\"25\">\n", er_roomaide);
1706                         }
1707                 
1708                         wc_printf("</ul><CENTER>\n");
1709                         wc_printf("<input type=\"hidden\" NAME=\"tab\" VALUE=\"config\">\n"
1710                                 "<input type=\"submit\" NAME=\"ok_button\" VALUE=\"%s\">"
1711                                 "&nbsp;"
1712                                 "<input type=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">"
1713                                 "</CENTER>\n",
1714                                 _("Save changes"),
1715                                 _("Cancel")
1716                                 );
1717                 }
1718                 wc_printf("</div>");
1719         }
1720
1721
1722         /* Sharing the room with other Citadel nodes... */
1723         if (!strcmp(tab, "sharing")) {
1724                 wc_printf("<div class=\"tabcontent\">");
1725
1726                 shared_with = strdup("");
1727                 not_shared_with = strdup("");
1728
1729                 /** Learn the current configuration */
1730                 serv_puts("CONF getsys|application/x-citadel-ignet-config");
1731                 serv_getln(buf, sizeof buf);
1732                 if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1733                                 extract_token(node, buf, 0, '|', sizeof node);
1734                                 not_shared_with = realloc(not_shared_with,
1735                                                           strlen(not_shared_with) + 32);
1736                                 strcat(not_shared_with, node);
1737                                 strcat(not_shared_with, "\n");
1738                         }
1739
1740                 serv_puts("GNET");
1741                 serv_getln(buf, sizeof buf);
1742                 if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1743                                 extract_token(cmd, buf, 0, '|', sizeof cmd);
1744                                 extract_token(node, buf, 1, '|', sizeof node);
1745                                 extract_token(remote_room, buf, 2, '|', sizeof remote_room);
1746                                 if (!strcasecmp(cmd, "ignet_push_share")) {
1747                                         shared_with = realloc(shared_with,
1748                                                               strlen(shared_with) + 32);
1749                                         strcat(shared_with, node);
1750                                         if (!IsEmptyStr(remote_room)) {
1751                                                 strcat(shared_with, "|");
1752                                                 strcat(shared_with, remote_room);
1753                                         }
1754                                         strcat(shared_with, "\n");
1755                                 }
1756                         }
1757
1758                 for (i=0; i<num_tokens(shared_with, '\n'); ++i) {
1759                         extract_token(buf, shared_with, i, '\n', sizeof buf);
1760                         extract_token(node, buf, 0, '|', sizeof node);
1761                         for (j=0; j<num_tokens(not_shared_with, '\n'); ++j) {
1762                                 extract_token(cmd, not_shared_with, j, '\n', sizeof cmd);
1763                                 if (!strcasecmp(node, cmd)) {
1764                                         remove_token(not_shared_with, j, '\n');
1765                                 }
1766                         }
1767                 }
1768
1769                 /* Display the stuff */
1770                 wc_printf("<CENTER><br />"
1771                         "<table border=1 cellpadding=5><tr>"
1772                         "<td><B><I>");
1773                 wc_printf(_("Shared with"));
1774                 wc_printf("</I></B></td>"
1775                         "<td><B><I>");
1776                 wc_printf(_("Not shared with"));
1777                 wc_printf("</I></B></td></tr>\n"
1778                         "<tr><td VALIGN=TOP>\n");
1779
1780                 wc_printf("<table border=0 cellpadding=5><tr class=\"tab_cell\"><td>");
1781                 wc_printf(_("Remote node name"));
1782                 wc_printf("</td><td>");
1783                 wc_printf(_("Remote room name"));
1784                 wc_printf("</td><td>");
1785                 wc_printf(_("Actions"));
1786                 wc_printf("</td></tr>\n");
1787
1788                 for (i=0; i<num_tokens(shared_with, '\n'); ++i) {
1789                         extract_token(buf, shared_with, i, '\n', sizeof buf);
1790                         extract_token(node, buf, 0, '|', sizeof node);
1791                         extract_token(remote_room, buf, 1, '|', sizeof remote_room);
1792                         if (!IsEmptyStr(node)) {
1793                                 wc_printf("<form method=\"POST\" action=\"netedit\">");
1794                                 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1795                                 wc_printf("<tr><td>%s</td>\n", node);
1796
1797                                 wc_printf("<td>");
1798                                 if (!IsEmptyStr(remote_room)) {
1799                                         escputs(remote_room);
1800                                 }
1801                                 wc_printf("</td>");
1802
1803                                 wc_printf("<td>");
1804                 
1805                                 wc_printf("<input type=\"hidden\" NAME=\"line\" "
1806                                         "VALUE=\"ignet_push_share|");
1807                                 urlescputs(node);
1808                                 if (!IsEmptyStr(remote_room)) {
1809                                         wc_printf("|");
1810                                         urlescputs(remote_room);
1811                                 }
1812                                 wc_printf("\">");
1813                                 wc_printf("<input type=\"hidden\" NAME=\"tab\" VALUE=\"sharing\">\n");
1814                                 wc_printf("<input type=\"hidden\" NAME=\"cmd\" VALUE=\"remove\">\n");
1815                                 wc_printf("<input type=\"submit\" "
1816                                         "NAME=\"unshare_button\" VALUE=\"%s\">", _("Unshare"));
1817                                 wc_printf("</td></tr></form>\n");
1818                         }
1819                 }
1820
1821                 wc_printf("</table>\n");
1822                 wc_printf("</td><td VALIGN=TOP>\n");
1823                 wc_printf("<table border=0 cellpadding=5><tr class=\"tab_cell\"><td>");
1824                 wc_printf(_("Remote node name"));
1825                 wc_printf("</td><td>");
1826                 wc_printf(_("Remote room name"));
1827                 wc_printf("</td><td>");
1828                 wc_printf(_("Actions"));
1829                 wc_printf("</td></tr>\n");
1830
1831                 for (i=0; i<num_tokens(not_shared_with, '\n'); ++i) {
1832                         extract_token(node, not_shared_with, i, '\n', sizeof node);
1833                         if (!IsEmptyStr(node)) {
1834                                 wc_printf("<form method=\"POST\" action=\"netedit\">");
1835                                 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1836                                 wc_printf("<tr><td>");
1837                                 escputs(node);
1838                                 wc_printf("</td><td>"
1839                                         "<input type=\"INPUT\" "
1840                                         "NAME=\"suffix\" "
1841                                         "MAXLENGTH=128>"
1842                                         "</td><td>");
1843                                 wc_printf("<input type=\"hidden\" "
1844                                         "NAME=\"line\" "
1845                                         "VALUE=\"ignet_push_share|");
1846                                 urlescputs(node);
1847                                 wc_printf("|\">");
1848                                 wc_printf("<input type=\"hidden\" NAME=\"tab\" "
1849                                         "VALUE=\"sharing\">\n");
1850                                 wc_printf("<input type=\"hidden\" NAME=\"cmd\" "
1851                                         "VALUE=\"add\">\n");
1852                                 wc_printf("<input type=\"submit\" "
1853                                         "NAME=\"add_button\" VALUE=\"%s\">", _("Share"));
1854                                 wc_printf("</td></tr></form>\n");
1855                         }
1856                 }
1857
1858                 wc_printf("</table>\n");
1859                 wc_printf("</td></tr>"
1860                         "</table></CENTER><br />\n"
1861                         "<I><B>%s</B><ul><li>", _("Notes:"));
1862                 wc_printf(_("When sharing a room, "
1863                           "it must be shared from both ends.  Adding a node to "
1864                           "the 'shared' list sends messages out, but in order to"
1865                           " receive messages, the other nodes must be configured"
1866                           " to send messages out to your system as well. "
1867                           "<li>If the remote room name is blank, it is assumed "
1868                           "that the room name is identical on the remote node."
1869                           "<li>If the remote room name is different, the remote "
1870                           "node must also configure the name of the room here."
1871                           "</ul></I><br />\n"
1872                                 ));
1873
1874                 wc_printf("</div>");
1875         }
1876
1877         if (not_shared_with != NULL)
1878                 free (not_shared_with);
1879
1880         /* Mailing list management */
1881         if (!strcmp(tab, "listserv")) {
1882                 room_states RoomFlags;
1883                 wc_printf("<div class=\"tabcontent\">");
1884
1885                 wc_printf("<br /><center>"
1886                         "<table BORDER=0 WIDTH=100%% CELLPADDING=5>"
1887                         "<tr><td VALIGN=TOP>");
1888
1889                 wc_printf(_("<i>The contents of this room are being "
1890                           "mailed <b>as individual messages</b> "
1891                           "to the following list recipients:"
1892                           "</i><br /><br />\n"));
1893
1894                 serv_puts("GNET");
1895                 serv_getln(buf, sizeof buf);
1896                 if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1897                                 extract_token(cmd, buf, 0, '|', sizeof cmd);
1898                                 if (!strcasecmp(cmd, "listrecp")) {
1899                                         extract_token(recp, buf, 1, '|', sizeof recp);
1900                         
1901                                         escputs(recp);
1902                                         wc_printf(" <a href=\"netedit?cmd=remove?tab=listserv?line=listrecp|");
1903                                         urlescputs(recp);
1904                                         wc_printf("\">");
1905                                         wc_printf(_("(remove)"));
1906                                         wc_printf("</A><br />");
1907                                 }
1908                         }
1909                 wc_printf("<br /><form method=\"POST\" action=\"netedit\">\n"
1910                         "<input type=\"hidden\" NAME=\"tab\" VALUE=\"listserv\">\n"
1911                         "<input type=\"hidden\" NAME=\"prefix\" VALUE=\"listrecp|\">\n");
1912                 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1913                 wc_printf("<input type=\"text\" id=\"add_as_listrecp\" NAME=\"line\">\n");
1914                 wc_printf("<input type=\"submit\" NAME=\"add_button\" VALUE=\"%s\">", _("Add"));
1915                 wc_printf("</form>\n");
1916
1917                 wc_printf("</td><td VALIGN=TOP>\n");
1918                 
1919                 wc_printf(_("<i>The contents of this room are being "
1920                           "mailed <b>in digest form</b> "
1921                           "to the following list recipients:"
1922                           "</i><br /><br />\n"));
1923
1924                 serv_puts("GNET");
1925                 serv_getln(buf, sizeof buf);
1926                 if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1927                                 extract_token(cmd, buf, 0, '|', sizeof cmd);
1928                                 if (!strcasecmp(cmd, "digestrecp")) {
1929                                         extract_token(recp, buf, 1, '|', sizeof recp);
1930                         
1931                                         escputs(recp);
1932                                         wc_printf(" <a href=\"netedit?cmd=remove?tab=listserv?line="
1933                                                 "digestrecp|");
1934                                         urlescputs(recp);
1935                                         wc_printf("\">");
1936                                         wc_printf(_("(remove)"));
1937                                         wc_printf("</A><br />");
1938                                 }
1939                         }
1940                 wc_printf("<br /><form method=\"POST\" action=\"netedit\">\n"
1941                         "<input type=\"hidden\" NAME=\"tab\" VALUE=\"listserv\">\n"
1942                         "<input type=\"hidden\" NAME=\"prefix\" VALUE=\"digestrecp|\">\n");
1943                 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1944                 wc_printf("<input type=\"text\" id=\"add_as_digestrecp\" NAME=\"line\">\n");
1945                 wc_printf("<input type=\"submit\" NAME=\"add_button\" VALUE=\"%s\">", _("Add"));
1946                 wc_printf("</form>\n");
1947                 
1948                 wc_printf("</td></tr></table>\n");
1949
1950                 /** Pop open an address book -- begin **/
1951                 wc_printf("<div align=right>"
1952                         "<a href=\"javascript:PopOpenAddressBook('add_as_listrecp|%s|add_as_digestrecp|%s');\" "
1953                         "title=\"%s\">"
1954                         "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
1955                         "&nbsp;%s</a>"
1956                         "</div>",
1957                         _("List"),
1958                         _("Digest"),
1959                         _("Add recipients from Contacts or other address books"),
1960                         _("Add recipients from Contacts or other address books")
1961                         );
1962                 /* Pop open an address book -- end **/
1963
1964                 wc_printf("<br />\n<form method=\"GET\" action=\"toggle_self_service\">\n");
1965
1966                 get_roomflags (&RoomFlags);
1967                 
1968                 /* Self Service subscription? */
1969                 wc_printf("<table><tr><td>\n");
1970                 wc_printf(_("Allow self-service subscribe/unsubscribe requests."));
1971                 wc_printf("</td><td><input type=\"checkbox\" name=\"QR2_SelfList\" value=\"yes\" %s></td></tr>\n"
1972                         " <tr><td colspan=\"2\">\n",
1973                         (is_selflist(&RoomFlags))?"checked":"");
1974                 wc_printf(_("The URL for subscribe/unsubscribe is: "));
1975                 wc_printf("<TT>%s://%s/listsub</TT></td></tr>\n",
1976                         (is_https ? "https" : "http"),
1977                         ChrPtr(WC->Hdr->HR.http_host));
1978                 /* Public posting? */
1979                 wc_printf("<tr><td>");
1980                 wc_printf(_("Allow non-subscribers to mail to this room."));
1981                 wc_printf("</td><td><input type=\"checkbox\" name=\"QR2_SubsOnly\" value=\"yes\" %s></td></tr>\n",
1982                         (is_publiclist(&RoomFlags))?"checked":"");
1983                 
1984                 /* Moderated List? */
1985                 wc_printf("<tr><td>");
1986                 wc_printf(_("Room post publication needs Aide permission."));
1987                 wc_printf("</td><td><input type=\"checkbox\" name=\"QR2_Moderated\" value=\"yes\" %s></td></tr>\n",
1988                         (is_moderatedlist(&RoomFlags))?"checked":"");
1989
1990
1991                 wc_printf("<tr><td colspan=\"2\" align=\"center\">"
1992                         "<input type=\"submit\" NAME=\"add_button\" VALUE=\"%s\"></td></tr>", _("Save changes"));
1993                 wc_printf("</table></form>");
1994                         
1995
1996                 wc_printf("</CENTER>\n");
1997                 wc_printf("</div>");
1998         }
1999
2000
2001         /* Configuration of The Dreaded Auto-Purger */
2002         if (!strcmp(tab, "expire")) {
2003                 wc_printf("<div class=\"tabcontent\">");
2004
2005                 serv_puts("GPEX room");
2006                 serv_getln(buf, sizeof buf);
2007                 if (!strncmp(buf, "550", 3)) {
2008                         wc_printf("<br><br><div align=center>%s</div><br><br>\n",
2009                                 _("Higher access is required to access this function.")
2010                                 );
2011                 }
2012                 else if (buf[0] != '2') {
2013                         wc_printf("<br><br><div align=center>%s</div><br><br>\n", &buf[4]);
2014                 }
2015                 else {
2016                         roompolicy = extract_int(&buf[4], 0);
2017                         roomvalue = extract_int(&buf[4], 1);
2018                 
2019                         serv_puts("GPEX floor");
2020                         serv_getln(buf, sizeof buf);
2021                         if (buf[0] == '2') {
2022                                 floorpolicy = extract_int(&buf[4], 0);
2023                                 floorvalue = extract_int(&buf[4], 1);
2024                         }
2025                         
2026                         wc_printf("<br /><form method=\"POST\" action=\"set_room_policy\">\n");
2027                         wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
2028                         wc_printf("<table border=0 cellspacing=5>\n");
2029                         wc_printf("<tr><td>");
2030                         wc_printf(_("Message expire policy for this room"));
2031                         wc_printf("<br />(");
2032                         escputs(ChrPtr(WC->CurRoom.name));
2033                         wc_printf(")</td><td>");
2034                         wc_printf("<input type=\"radio\" NAME=\"roompolicy\" VALUE=\"0\" %s>",
2035                                 ((roompolicy == 0) ? "CHECKED" : "") );
2036                         wc_printf(_("Use the default policy for this floor"));
2037                         wc_printf("<br />\n");
2038                         wc_printf("<input type=\"radio\" NAME=\"roompolicy\" VALUE=\"1\" %s>",
2039                                 ((roompolicy == 1) ? "CHECKED" : "") );
2040                         wc_printf(_("Never automatically expire messages"));
2041                         wc_printf("<br />\n");
2042                         wc_printf("<input type=\"radio\" NAME=\"roompolicy\" VALUE=\"2\" %s>",
2043                                 ((roompolicy == 2) ? "CHECKED" : "") );
2044                         wc_printf(_("Expire by message count"));
2045                         wc_printf("<br />\n");
2046                         wc_printf("<input type=\"radio\" NAME=\"roompolicy\" VALUE=\"3\" %s>",
2047                                 ((roompolicy == 3) ? "CHECKED" : "") );
2048                         wc_printf(_("Expire by message age"));
2049                         wc_printf("<br />");
2050                         wc_printf(_("Number of messages or days: "));
2051                         wc_printf("<input type=\"text\" NAME=\"roomvalue\" MAXLENGTH=\"5\" VALUE=\"%d\">", roomvalue);
2052                         wc_printf("</td></tr>\n");
2053         
2054                         if (WC->axlevel >= 6) {
2055                                 wc_printf("<tr><td COLSPAN=2><hr /></td></tr>\n");
2056                                 wc_printf("<tr><td>");
2057                                 wc_printf(_("Message expire policy for this floor"));
2058                                 wc_printf("<br />(");
2059                                 escputs(floorlist[WC->CurRoom.floorid]);
2060                                 wc_printf(")</td><td>");
2061                                 wc_printf("<input type=\"radio\" NAME=\"floorpolicy\" VALUE=\"0\" %s>",
2062                                         ((floorpolicy == 0) ? "CHECKED" : "") );
2063                                 wc_printf(_("Use the system default"));
2064                                 wc_printf("<br />\n");
2065                                 wc_printf("<input type=\"radio\" NAME=\"floorpolicy\" VALUE=\"1\" %s>",
2066                                         ((floorpolicy == 1) ? "CHECKED" : "") );
2067                                 wc_printf(_("Never automatically expire messages"));
2068                                 wc_printf("<br />\n");
2069                                 wc_printf("<input type=\"radio\" NAME=\"floorpolicy\" VALUE=\"2\" %s>",
2070                                         ((floorpolicy == 2) ? "CHECKED" : "") );
2071                                 wc_printf(_("Expire by message count"));
2072                                 wc_printf("<br />\n");
2073                                 wc_printf("<input type=\"radio\" NAME=\"floorpolicy\" VALUE=\"3\" %s>",
2074                                         ((floorpolicy == 3) ? "CHECKED" : "") );
2075                                 wc_printf(_("Expire by message age"));
2076                                 wc_printf("<br />");
2077                                 wc_printf(_("Number of messages or days: "));
2078                                 wc_printf("<input type=\"text\" NAME=\"floorvalue\" MAXLENGTH=\"5\" VALUE=\"%d\">",
2079                                         floorvalue);
2080                         }
2081         
2082                         wc_printf("<CENTER>\n");
2083                         wc_printf("<tr><td COLSPAN=2><hr /><CENTER>\n");
2084                         wc_printf("<input type=\"submit\" NAME=\"ok_button\" VALUE=\"%s\">", _("Save changes"));
2085                         wc_printf("&nbsp;");
2086                         wc_printf("<input type=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
2087                         wc_printf("</CENTER></td><tr>\n");
2088         
2089                         wc_printf("</table>\n"
2090                                 "<input type=\"hidden\" NAME=\"tab\" VALUE=\"expire\">\n"
2091                                 "</form>\n"
2092                                 );
2093                 }
2094
2095                 wc_printf("</div>");
2096         }
2097
2098         /* Access controls */
2099         if (!strcmp(tab, "access")) {
2100                 wc_printf("<div class=\"tabcontent\">");
2101                 display_whok();
2102                 wc_printf("</div>");
2103         }
2104
2105         /* Fetch messages from remote locations */
2106         if (!strcmp(tab, "feeds")) {
2107                 wc_printf("<div class=\"tabcontent\">");
2108
2109                 wc_printf("<i>");
2110                 wc_printf(_("Retrieve messages from these remote POP3 accounts and store them in this room:"));
2111                 wc_printf("</i><br />\n");
2112
2113                 wc_printf("<table class=\"altern\" border=0 cellpadding=5>"
2114                         "<tr class=\"even\"><th>");
2115                 wc_printf(_("Remote host"));
2116                 wc_printf("</th><th>");
2117                 wc_printf(_("User name"));
2118                 wc_printf("</th><th>");
2119                 wc_printf(_("Password"));
2120                 wc_printf("</th><th>");
2121                 wc_printf(_("Keep messages on server?"));
2122                 wc_printf("</th><th>");
2123                 wc_printf(_("Interval"));
2124                 wc_printf("</th><th> </th></tr>");
2125
2126                 serv_puts("GNET");
2127                 serv_getln(buf, sizeof buf);
2128                 bg = 1;
2129                 if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2130                                 extract_token(cmd, buf, 0, '|', sizeof cmd);
2131                                 if (!strcasecmp(cmd, "pop3client")) {
2132                                         safestrncpy(recp, &buf[11], sizeof recp);
2133
2134                                         bg = 1 - bg;
2135                                         wc_printf("<tr class=\"%s\">",
2136                                                 (bg ? "even" : "odd")
2137                                                 );
2138
2139                                         wc_printf("<td>");
2140                                         extract_token(pop3_host, buf, 1, '|', sizeof pop3_host);
2141                                         escputs(pop3_host);
2142                                         wc_printf("</td>");
2143
2144                                         wc_printf("<td>");
2145                                         extract_token(pop3_user, buf, 2, '|', sizeof pop3_user);
2146                                         escputs(pop3_user);
2147                                         wc_printf("</td>");
2148
2149                                         wc_printf("<td>*****</td>");            /* Don't show the password */
2150
2151                                         wc_printf("<td>%s</td>", extract_int(buf, 4) ? _("Yes") : _("No"));
2152
2153                                         wc_printf("<td>%ld</td>", extract_long(buf, 5));        /* Fetching interval */
2154                         
2155                                         wc_printf("<td class=\"button_link\">");
2156                                         wc_printf(" <a href=\"netedit?cmd=remove?tab=feeds?line=pop3client|");
2157                                         urlescputs(recp);
2158                                         wc_printf("\">");
2159                                         wc_printf(_("(remove)"));
2160                                         wc_printf("</a></td>");
2161                         
2162                                         wc_printf("</tr>");
2163                                 }
2164                         }
2165
2166                 wc_printf("<form method=\"POST\" action=\"netedit\">\n"
2167                         "<tr>"
2168                         "<input type=\"hidden\" name=\"tab\" value=\"feeds\">"
2169                         "<input type=\"hidden\" name=\"prefix\" value=\"pop3client|\">\n");
2170                 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
2171                 wc_printf("<td>");
2172                 wc_printf("<input type=\"text\" id=\"add_as_pop3host\" NAME=\"line_pop3host\">\n");
2173                 wc_printf("</td>");
2174                 wc_printf("<td>");
2175                 wc_printf("<input type=\"text\" id=\"add_as_pop3user\" NAME=\"line_pop3user\">\n");
2176                 wc_printf("</td>");
2177                 wc_printf("<td>");
2178                 wc_printf("<input type=\"password\" id=\"add_as_pop3pass\" NAME=\"line_pop3pass\">\n");
2179                 wc_printf("</td>");
2180                 wc_printf("<td>");
2181                 wc_printf("<input type=\"checkbox\" id=\"add_as_pop3keep\" NAME=\"line_pop3keep\" VALUE=\"1\">");
2182                 wc_printf("</td>");
2183                 wc_printf("<td>");
2184                 wc_printf("<input type=\"text\" id=\"add_as_pop3int\" NAME=\"line_pop3int\" MAXLENGTH=\"5\">");
2185                 wc_printf("</td>");
2186                 wc_printf("<td>");
2187                 wc_printf("<input type=\"submit\" NAME=\"add_button\" VALUE=\"%s\">", _("Add"));
2188                 wc_printf("</td></tr>");
2189                 wc_printf("</form></table>\n");
2190
2191                 wc_printf("<hr>\n");
2192
2193                 wc_printf("<i>");
2194                 wc_printf(_("Fetch the following RSS feeds and store them in this room:"));
2195                 wc_printf("</i><br />\n");
2196
2197                 wc_printf("<table class=\"altern\" border=0 cellpadding=5>"
2198                         "<tr class=\"even\"><th>");
2199                 wc_printf("<img src=\"static/rss_16x.png\" width=\"16\" height=\"16\" alt=\" \"> ");
2200                 wc_printf(_("Feed URL"));
2201                 wc_printf("</th><th>");
2202                 wc_printf("</th></tr>");
2203
2204                 serv_puts("GNET");
2205                 serv_getln(buf, sizeof buf);
2206                 bg = 1;
2207                 if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2208                                 extract_token(cmd, buf, 0, '|', sizeof cmd);
2209                                 if (!strcasecmp(cmd, "rssclient")) {
2210                                         safestrncpy(recp, &buf[10], sizeof recp);
2211
2212                                         bg = 1 - bg;
2213                                         wc_printf("<tr class=\"%s\">",
2214                                                 (bg ? "even" : "odd")
2215                                                 );
2216
2217                                         wc_printf("<td>");
2218                                         extract_token(pop3_host, buf, 1, '|', sizeof pop3_host);
2219                                         escputs(pop3_host);
2220                                         wc_printf("</td>");
2221
2222                                         wc_printf("<td class=\"button_link\">");
2223                                         wc_printf(" <a href=\"netedit?cmd=remove?tab=feeds?line=rssclient|");
2224                                         urlescputs(recp);
2225                                         wc_printf("\">");
2226                                         wc_printf(_("(remove)"));
2227                                         wc_printf("</a></td>");
2228                         
2229                                         wc_printf("</tr>");
2230                                 }
2231                         }
2232
2233                 wc_printf("<form method=\"POST\" action=\"netedit\">\n"
2234                         "<tr>"
2235                         "<input type=\"hidden\" name=\"tab\" value=\"feeds\">"
2236                         "<input type=\"hidden\" name=\"prefix\" value=\"rssclient|\">\n");
2237                 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
2238                 wc_printf("<td>");
2239                 wc_printf("<input type=\"text\" id=\"add_as_pop3host\" size=\"72\" "
2240                         "maxlength=\"256\" name=\"line_pop3host\">\n");
2241                 wc_printf("</td>");
2242                 wc_printf("<td>");
2243                 wc_printf("<input type=\"submit\" name=\"add_button\" value=\"%s\">", _("Add"));
2244                 wc_printf("</td></tr>");
2245                 wc_printf("</form></table>\n");
2246
2247                 wc_printf("</div>");
2248         }
2249
2250
2251         /* end content of whatever tab is open now */
2252         wc_printf("</div>\n");
2253
2254         address_book_popup();
2255         wDumpContent(1);
2256 }
2257
2258
2259 /* 
2260  * Toggle self-service list subscription
2261  */
2262 void toggle_self_service(void) {
2263         room_states RoomFlags;
2264
2265         get_roomflags (&RoomFlags);
2266
2267         if (yesbstr("QR2_SelfList")) 
2268                 RoomFlags.flags2 = RoomFlags.flags2 | QR2_SELFLIST;
2269         else 
2270                 RoomFlags.flags2 = RoomFlags.flags2 & ~QR2_SELFLIST;
2271
2272         if (yesbstr("QR2_SMTP_PUBLIC")) 
2273                 RoomFlags.flags2 = RoomFlags.flags2 | QR2_SMTP_PUBLIC;
2274         else
2275                 RoomFlags.flags2 = RoomFlags.flags2 & ~QR2_SMTP_PUBLIC;
2276
2277         if (yesbstr("QR2_Moderated")) 
2278                 RoomFlags.flags2 = RoomFlags.flags2 | QR2_MODERATED;
2279         else
2280                 RoomFlags.flags2 = RoomFlags.flags2 & ~QR2_MODERATED;
2281         if (yesbstr("QR2_SubsOnly")) 
2282                 RoomFlags.flags2 = RoomFlags.flags2 | QR2_SMTP_PUBLIC;
2283         else
2284                 RoomFlags.flags2 = RoomFlags.flags2 & ~QR2_SMTP_PUBLIC;
2285
2286         set_roomflags (&RoomFlags);
2287         
2288         display_editroom();
2289 }
2290
2291
2292
2293 /*
2294  * save new parameters for a room
2295  */
2296 void editroom(void)
2297 {
2298         const StrBuf *Ptr;
2299         StrBuf *Buf;
2300         StrBuf *er_name;
2301         StrBuf *er_password;
2302         StrBuf *er_dirname;
2303         StrBuf *er_roomaide;
2304         int er_floor;
2305         unsigned er_flags;
2306         int er_listingorder;
2307         int er_defaultview;
2308         unsigned er_flags2;
2309         int bump;
2310
2311
2312         if (!havebstr("ok_button")) {
2313                 strcpy(WC->ImportantMessage,
2314                        _("Cancelled.  Changes were not saved."));
2315                 display_editroom();
2316                 return;
2317         }
2318         serv_puts("GETR");
2319         Buf = NewStrBuf();
2320         StrBuf_ServGetln(Buf);
2321         if (GetServerStatus(Buf, NULL) != 2) {
2322                 StrBufCutLeft(Buf, 4);
2323                 strcpy(WC->ImportantMessage, ChrPtr(Buf));
2324                 display_editroom();
2325                 FreeStrBuf(&Buf);
2326                 return;
2327         }
2328
2329         er_name = NewStrBuf();
2330         er_password = NewStrBuf();
2331         er_dirname = NewStrBuf();
2332         er_roomaide = NewStrBuf();
2333
2334         StrBufCutLeft(Buf, 4);
2335         StrBufExtract_token(er_name, Buf, 0, '|');
2336         StrBufExtract_token(er_password, Buf, 1, '|');
2337         StrBufExtract_token(er_dirname, Buf, 2, '|');
2338         er_flags = StrBufExtract_int(Buf, 3, '|');
2339         er_listingorder = StrBufExtract_int(Buf, 5, '|');
2340         er_defaultview = StrBufExtract_int(Buf, 6, '|');
2341         er_flags2 = StrBufExtract_int(Buf, 7, '|');
2342
2343         er_roomaide = NewStrBufDup(sbstr("er_roomaide"));
2344         if (StrLength(er_roomaide) == 0) {
2345                 serv_puts("GETA");
2346                 StrBuf_ServGetln(Buf);
2347                 if (GetServerStatus(Buf, NULL) != 2) {
2348                         FlushStrBuf(er_roomaide);
2349                 } else {
2350                         StrBufCutLeft(Buf, 4);
2351                         StrBufExtract_token(er_roomaide, Buf, 0, '|');
2352                 }
2353         }
2354         Ptr = sbstr("er_name");
2355         if (StrLength(Ptr) > 0) {
2356                 FlushStrBuf(er_name);
2357                 StrBufAppendBuf(er_name, Ptr, 0);
2358         }
2359
2360         Ptr = sbstr("er_password");
2361         if (StrLength(Ptr) > 0) {
2362                 FlushStrBuf(er_password);
2363                 StrBufAppendBuf(er_password, Ptr, 0);
2364         }
2365                 
2366
2367         Ptr = sbstr("er_dirname");
2368         if (StrLength(Ptr) > 0) { /* todo: cut 15 */
2369                 FlushStrBuf(er_dirname);
2370                 StrBufAppendBuf(er_dirname, Ptr, 0);
2371         }
2372
2373
2374         Ptr = sbstr("type");
2375         er_flags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
2376
2377         if (!strcmp(ChrPtr(Ptr), "invonly")) {
2378                 er_flags |= (QR_PRIVATE);
2379         }
2380         if (!strcmp(ChrPtr(Ptr), "hidden")) {
2381                 er_flags |= (QR_PRIVATE | QR_GUESSNAME);
2382         }
2383         if (!strcmp(ChrPtr(Ptr), "passworded")) {
2384                 er_flags |= (QR_PRIVATE | QR_PASSWORDED);
2385         }
2386         if (!strcmp(ChrPtr(Ptr), "personal")) {
2387                 er_flags |= QR_MAILBOX;
2388         } else {
2389                 er_flags &= ~QR_MAILBOX;
2390         }
2391         
2392         if (yesbstr("prefonly")) {
2393                 er_flags |= QR_PREFONLY;
2394         } else {
2395                 er_flags &= ~QR_PREFONLY;
2396         }
2397
2398         if (yesbstr("readonly")) {
2399                 er_flags |= QR_READONLY;
2400         } else {
2401                 er_flags &= ~QR_READONLY;
2402         }
2403
2404         
2405         if (yesbstr("collabdel")) {
2406                 er_flags2 |= QR2_COLLABDEL;
2407         } else {
2408                 er_flags2 &= ~QR2_COLLABDEL;
2409         }
2410
2411         if (yesbstr("permanent")) {
2412                 er_flags |= QR_PERMANENT;
2413         } else {
2414                 er_flags &= ~QR_PERMANENT;
2415         }
2416
2417         if (yesbstr("subjectreq")) {
2418                 er_flags2 |= QR2_SUBJECTREQ;
2419         } else {
2420                 er_flags2 &= ~QR2_SUBJECTREQ;
2421         }
2422
2423         if (yesbstr("network")) {
2424                 er_flags |= QR_NETWORK;
2425         } else {
2426                 er_flags &= ~QR_NETWORK;
2427         }
2428
2429         if (yesbstr("directory")) {
2430                 er_flags |= QR_DIRECTORY;
2431         } else {
2432                 er_flags &= ~QR_DIRECTORY;
2433         }
2434
2435         if (yesbstr("ulallowed")) {
2436                 er_flags |= QR_UPLOAD;
2437         } else {
2438                 er_flags &= ~QR_UPLOAD;
2439         }
2440
2441         if (yesbstr("dlallowed")) {
2442                 er_flags |= QR_DOWNLOAD;
2443         } else {
2444                 er_flags &= ~QR_DOWNLOAD;
2445         }
2446
2447         if (yesbstr("visdir")) {
2448                 er_flags |= QR_VISDIR;
2449         } else {
2450                 er_flags &= ~QR_VISDIR;
2451         }
2452
2453         Ptr = sbstr("anon");
2454
2455         er_flags &= ~(QR_ANONONLY | QR_ANONOPT);
2456         if (!strcmp(ChrPtr(Ptr), "anononly"))
2457                 er_flags |= QR_ANONONLY;
2458         if (!strcmp(ChrPtr(Ptr), "anon2"))
2459                 er_flags |= QR_ANONOPT;
2460
2461         bump = yesbstr("bump");
2462
2463         er_floor = ibstr("er_floor");
2464
2465         StrBufPrintf(Buf, "SETR %s|%s|%s|%u|%d|%d|%d|%d|%u",
2466                      ChrPtr(er_name), 
2467                      ChrPtr(er_password), 
2468                      ChrPtr(er_dirname), 
2469                      er_flags, 
2470                      bump, 
2471                      er_floor,
2472                      er_listingorder, 
2473                      er_defaultview, 
2474                      er_flags2);
2475         serv_putbuf(Buf);
2476         StrBuf_ServGetln(Buf);
2477         if (GetServerStatus(Buf, NULL) != 2) {
2478                 strcpy(WC->ImportantMessage, &ChrPtr(Buf)[4]);
2479                 display_editroom();
2480                 FreeStrBuf(&Buf);
2481                 FreeStrBuf(&er_name);
2482                 FreeStrBuf(&er_password);
2483                 FreeStrBuf(&er_dirname);
2484                 FreeStrBuf(&er_roomaide);
2485                 return;
2486         }
2487         gotoroom(er_name);
2488
2489         if (StrLength(er_roomaide) > 0) {
2490                 serv_printf("SETA %s", ChrPtr(er_roomaide));
2491                 StrBuf_ServGetln(Buf);
2492                 if (GetServerStatus(Buf, NULL) != 2) {
2493                         strcpy(WC->ImportantMessage, &ChrPtr(Buf)[4]);
2494                         display_main_menu();
2495                         FreeStrBuf(&Buf);
2496                         FreeStrBuf(&er_name);
2497                         FreeStrBuf(&er_password);
2498                         FreeStrBuf(&er_dirname);
2499                         FreeStrBuf(&er_roomaide);
2500                         return;
2501                 }
2502         }
2503         gotoroom(er_name);
2504         strcpy(WC->ImportantMessage, _("Your changes have been saved."));
2505         display_editroom();
2506         FreeStrBuf(&Buf);
2507         FreeStrBuf(&er_name);
2508         FreeStrBuf(&er_password);
2509         FreeStrBuf(&er_dirname);
2510         FreeStrBuf(&er_roomaide);
2511         return;
2512 }
2513
2514
2515 /*
2516  * Display form for Invite, Kick, and show Who Knows a room
2517  */
2518 void do_invt_kick(void) {
2519         char buf[SIZ], room[SIZ], username[SIZ];
2520
2521         serv_puts("GETR");
2522         serv_getln(buf, sizeof buf);
2523
2524         if (buf[0] != '2') {
2525                 escputs(&buf[4]);
2526                 return;
2527         }
2528         extract_token(room, &buf[4], 0, '|', sizeof room);
2529
2530         strcpy(username, bstr("username"));
2531
2532         if (havebstr("kick_button")) {
2533                 sprintf(buf, "KICK %s", username);
2534                 serv_puts(buf);
2535                 serv_getln(buf, sizeof buf);
2536
2537                 if (buf[0] != '2') {
2538                         strcpy(WC->ImportantMessage, &buf[4]);
2539                 } else {
2540                         sprintf(WC->ImportantMessage,
2541                                 _("<B><I>User %s kicked out of room %s.</I></B>\n"), 
2542                                 username, room);
2543                 }
2544         }
2545
2546         if (havebstr("invite_button")) {
2547                 sprintf(buf, "INVT %s", username);
2548                 serv_puts(buf);
2549                 serv_getln(buf, sizeof buf);
2550
2551                 if (buf[0] != '2') {
2552                         strcpy(WC->ImportantMessage, &buf[4]);
2553                 } else {
2554                         sprintf(WC->ImportantMessage,
2555                                 _("<B><I>User %s invited to room %s.</I></B>\n"), 
2556                                 username, room);
2557                 }
2558         }
2559
2560         display_editroom();
2561 }
2562
2563
2564
2565 /*
2566  * Display form for Invite, Kick, and show Who Knows a room
2567  */
2568 void display_whok(void)
2569 {
2570         char buf[SIZ], room[SIZ], username[SIZ];
2571
2572         serv_puts("GETR");
2573         serv_getln(buf, sizeof buf);
2574
2575         if (buf[0] != '2') {
2576                 escputs(&buf[4]);
2577                 return;
2578         }
2579         extract_token(room, &buf[4], 0, '|', sizeof room);
2580
2581         
2582         wc_printf("<table border=0 CELLSPACING=10><tr VALIGN=TOP><td>");
2583         wc_printf(_("The users listed below have access to this room.  "
2584                   "To remove a user from the access list, select the user "
2585                   "name from the list and click 'Kick'."));
2586         wc_printf("<br /><br />");
2587         
2588         wc_printf("<CENTER><form method=\"POST\" action=\"do_invt_kick\">\n");
2589         wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
2590         wc_printf("<input type=\"hidden\" NAME=\"tab\" VALUE=\"access\">\n");
2591         wc_printf("<select NAME=\"username\" SIZE=\"10\" style=\"width:100%%\">\n");
2592         serv_puts("WHOK");
2593         serv_getln(buf, sizeof buf);
2594         if (buf[0] == '1') {
2595                 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2596                         extract_token(username, buf, 0, '|', sizeof username);
2597                         wc_printf("<OPTION>");
2598                         escputs(username);
2599                         wc_printf("\n");
2600                 }
2601         }
2602         wc_printf("</select><br />\n");
2603
2604         wc_printf("<input type=\"submit\" name=\"kick_button\" value=\"%s\">", _("Kick"));
2605         wc_printf("</form></CENTER>\n");
2606
2607         wc_printf("</td><td>");
2608         wc_printf(_("To grant another user access to this room, enter the "
2609                   "user name in the box below and click 'Invite'."));
2610         wc_printf("<br /><br />");
2611
2612         wc_printf("<CENTER><form method=\"POST\" action=\"do_invt_kick\">\n");
2613         wc_printf("<input type=\"hidden\" NAME=\"tab\" VALUE=\"access\">\n");
2614         wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
2615         wc_printf(_("Invite:"));
2616         wc_printf(" ");
2617         wc_printf("<input type=\"text\" name=\"username\" id=\"username_id\" style=\"width:100%%\"><br />\n"
2618                 "<input type=\"hidden\" name=\"invite_button\" value=\"Invite\">"
2619                 "<input type=\"submit\" value=\"%s\">"
2620                 "</form></CENTER>\n", _("Invite"));
2621         /* Pop open an address book -- begin **/
2622         wc_printf(
2623                 "<a href=\"javascript:PopOpenAddressBook('username_id|%s');\" "
2624                 "title=\"%s\">"
2625                 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
2626                 "&nbsp;%s</a>",
2627                 _("User"), 
2628                 _("Users"), _("Users")
2629                 );
2630         /* Pop open an address book -- end **/
2631
2632         wc_printf("</td></tr></table>\n");
2633         address_book_popup();
2634         wDumpContent(1);
2635 }
2636
2637
2638
2639 /*
2640  * display the form for entering a new room
2641  */
2642 void display_entroom(void)
2643 {
2644         StrBuf *Buf;
2645         int i;
2646         char buf[SIZ];
2647
2648         Buf = NewStrBuf();
2649         serv_puts("CRE8 0");
2650         serv_getln(buf, sizeof buf);
2651
2652         if (buf[0] != '2') {
2653                 strcpy(WC->ImportantMessage, &buf[4]);
2654                 display_main_menu();
2655                 FreeStrBuf(&Buf);
2656                 return;
2657         }
2658
2659         output_headers(1, 1, 1, 0, 0, 0);
2660
2661         svprintf(HKEY("BOXTITLE"), WCS_STRING, _("Create a new room"));
2662         do_template("beginbox", NULL);
2663
2664         wc_printf("<form name=\"create_room_form\" method=\"POST\" action=\"entroom\">\n");
2665         wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
2666
2667         wc_printf("<table class=\"altern\"> ");
2668
2669         wc_printf("<tr class=\"even\"><td>");
2670         wc_printf(_("Name of room: "));
2671         wc_printf("</td><td>");
2672         wc_printf("<input type=\"text\" NAME=\"er_name\" MAXLENGTH=\"127\">\n");
2673         wc_printf("</td></tr>");
2674
2675         wc_printf("<tr class=\"odd\"><td>");
2676         wc_printf(_("Resides on floor: "));
2677         wc_printf("</td><td>");
2678         load_floorlist(Buf); 
2679         wc_printf("<select name=\"er_floor\" size=\"1\">\n");
2680         for (i = 0; i < 128; ++i)
2681                 if (!IsEmptyStr(floorlist[i])) {
2682                         wc_printf("<option ");
2683                         wc_printf("value=\"%d\">", i);
2684                         escputs(floorlist[i]);
2685                         wc_printf("</option>\n");
2686                 }
2687         wc_printf("</select>\n");
2688         wc_printf("</td></tr>");
2689
2690         /*
2691          * Our clever little snippet of JavaScript automatically selects
2692          * a public room if the view is set to Bulletin Board or wiki, and
2693          * it selects a mailbox room otherwise.  The user can override this,
2694          * of course.  We also disable the floor selector for mailboxes.
2695          */
2696         wc_printf("<tr class=\"even\"><td>");
2697         wc_printf(_("Default view for room: "));
2698         wc_printf("</td><td>");
2699         wc_printf("<select name=\"er_view\" size=\"1\" OnChange=\""
2700                 "       if ( (this.form.er_view.value == 0)             "
2701                 "          || (this.form.er_view.value == 6) ) {        "
2702                 "               this.form.type[0].checked=true;         "
2703                 "               this.form.er_floor.disabled = false;    "
2704                 "       }                                               "
2705                 "       else {                                          "
2706                 "               this.form.type[4].checked=true;         "
2707                 "               this.form.er_floor.disabled = true;     "
2708                 "       }                                               "
2709                 "\">\n");
2710         for (i=0; i<(sizeof viewdefs / sizeof (char *)); ++i) {
2711                 if (is_view_allowed_as_default(i)) {
2712                         wc_printf("<option %s value=\"%d\">",
2713                                 ((i == 0) ? "selected" : ""), i );
2714                         escputs(viewdefs[i]);
2715                         wc_printf("</option>\n");
2716                 }
2717         }
2718         wc_printf("</select>\n");
2719         wc_printf("</td></tr>");
2720
2721         wc_printf("<tr class=\"even\"><td>");
2722         wc_printf(_("Type of room:"));
2723         wc_printf("</td><td>");
2724         wc_printf("<ul class=\"adminlist\">\n");
2725
2726         wc_printf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"public\" ");
2727         wc_printf("CHECKED OnChange=\""
2728                 "       if (this.form.type[0].checked == true) {        "
2729                 "               this.form.er_floor.disabled = false;    "
2730                 "       }                                               "
2731                 "\"> ");
2732         wc_printf(_("Public (automatically appears to everyone)"));
2733         wc_printf("</li>");
2734
2735         wc_printf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"hidden\" OnChange=\""
2736                 "       if (this.form.type[1].checked == true) {        "
2737                 "               this.form.er_floor.disabled = false;    "
2738                 "       }                                               "
2739                 "\"> ");
2740         wc_printf(_("Private - hidden (accessible to anyone who knows its name)"));
2741         wc_printf("</li>");
2742
2743         wc_printf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"passworded\" OnChange=\""
2744                 "       if (this.form.type[2].checked == true) {        "
2745                 "               this.form.er_floor.disabled = false;    "
2746                 "       }                                               "
2747                 "\"> ");
2748         wc_printf(_("Private - require password: "));
2749         wc_printf("<input type=\"text\" NAME=\"er_password\" MAXLENGTH=\"9\">\n");
2750         wc_printf("</li>");
2751
2752         wc_printf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"invonly\" OnChange=\""
2753                 "       if (this.form.type[3].checked == true) {        "
2754                 "               this.form.er_floor.disabled = false;    "
2755                 "       }                                               "
2756                 "\"> ");
2757         wc_printf(_("Private - invitation only"));
2758         wc_printf("</li>");
2759
2760         wc_printf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"personal\" "
2761                 "OnChange=\""
2762                 "       if (this.form.type[4].checked == true) {        "
2763                 "               this.form.er_floor.disabled = true;     "
2764                 "       }                                               "
2765                 "\"> ");
2766         wc_printf(_("Personal (mailbox for you only)"));
2767         wc_printf("</li>");
2768
2769         wc_printf("\n</ul>\n");
2770         wc_printf("</td></tr></table>\n");
2771
2772         wc_printf("<div class=\"buttons\">\n");
2773         wc_printf("<input type=\"submit\" name=\"ok_button\" value=\"%s\">", _("Create new room"));
2774         wc_printf("&nbsp;");
2775         wc_printf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">", _("Cancel"));
2776         wc_printf("</div>\n");
2777         wc_printf("</form>\n<hr />");
2778         serv_printf("MESG roomaccess");
2779         serv_getln(buf, sizeof buf);
2780         if (buf[0] == '1') {
2781                 fmout("LEFT");
2782         }
2783
2784         do_template("endbox", NULL);
2785
2786         wDumpContent(1);
2787         FreeStrBuf(&Buf);
2788 }
2789
2790
2791
2792
2793 /*
2794  * support function for entroom() -- sets the default view 
2795  */
2796 void er_set_default_view(int newview) {
2797
2798         char buf[SIZ];
2799
2800         char rm_name[SIZ];
2801         char rm_pass[SIZ];
2802         char rm_dir[SIZ];
2803         int rm_bits1;
2804         int rm_floor;
2805         int rm_listorder;
2806         int rm_bits2;
2807
2808         serv_puts("GETR");
2809         serv_getln(buf, sizeof buf);
2810         if (buf[0] != '2') return;
2811
2812         extract_token(rm_name, &buf[4], 0, '|', sizeof rm_name);
2813         extract_token(rm_pass, &buf[4], 1, '|', sizeof rm_pass);
2814         extract_token(rm_dir, &buf[4], 2, '|', sizeof rm_dir);
2815         rm_bits1 = extract_int(&buf[4], 3);
2816         rm_floor = extract_int(&buf[4], 4);
2817         rm_listorder = extract_int(&buf[4], 5);
2818         rm_bits2 = extract_int(&buf[4], 7);
2819
2820         serv_printf("SETR %s|%s|%s|%d|0|%d|%d|%d|%d",
2821                     rm_name, rm_pass, rm_dir, rm_bits1, rm_floor,
2822                     rm_listorder, newview, rm_bits2
2823                 );
2824         serv_getln(buf, sizeof buf);
2825 }
2826
2827
2828
2829 /*
2830  * Create a new room
2831  */
2832 void entroom(void)
2833 {
2834         char buf[SIZ];
2835         const StrBuf *er_name;
2836         const StrBuf *er_type;
2837         const StrBuf *er_password;
2838         int er_floor;
2839         int er_num_type;
2840         int er_view;
2841         wcsession *WCC = WC;
2842
2843         if (!havebstr("ok_button")) {
2844                 strcpy(WC->ImportantMessage,
2845                        _("Cancelled.  No new room was created."));
2846                 display_main_menu();
2847                 return;
2848         }
2849         er_name = sbstr("er_name");
2850         er_type = sbstr("type");
2851         er_password = sbstr("er_password");
2852         er_floor = ibstr("er_floor");
2853         er_view = ibstr("er_view");
2854
2855         er_num_type = 0;
2856         if (!strcmp(ChrPtr(er_type), "hidden"))
2857                 er_num_type = 1;
2858         else if (!strcmp(ChrPtr(er_type), "passworded"))
2859                 er_num_type = 2;
2860         else if (!strcmp(ChrPtr(er_type), "invonly"))
2861                 er_num_type = 3;
2862         else if (!strcmp(ChrPtr(er_type), "personal"))
2863                 er_num_type = 4;
2864
2865         serv_printf("CRE8 1|%s|%d|%s|%d|%d|%d", 
2866                     ChrPtr(er_name), 
2867                     er_num_type, 
2868                     ChrPtr(er_password), 
2869                     er_floor, 
2870                     0, 
2871                     er_view);
2872
2873         serv_getln(buf, sizeof buf);
2874         if (buf[0] != '2') {
2875                 strcpy(WCC->ImportantMessage, &buf[4]);
2876                 display_main_menu();
2877                 return;
2878         }
2879         /** TODO: Room created, now update the left hand icon bar for this user */
2880         burn_folder_cache(0);   /* burn the old folder cache */
2881         
2882         gotoroom(er_name);
2883
2884         serv_printf("VIEW %d", er_view);
2885         serv_getln(buf, sizeof buf);
2886         WCC->CurRoom.view = er_view;
2887
2888         if ( (WCC != NULL) && ( (WCC->CurRoom.RAFlags & UA_ADMINALLOWED) != 0) )  {
2889                 display_editroom ();
2890         } else {
2891                 do_change_view(er_view);                /* Now go there */
2892         }
2893
2894 }
2895
2896
2897 /**
2898  * \brief display the screen to enter a private room
2899  */
2900 void display_private(char *rname, int req_pass)
2901 {
2902         WCTemplputParams SubTP;
2903         StrBuf *Buf;
2904         output_headers(1, 1, 1, 0, 0, 0);
2905
2906         Buf = NewStrBufPlain(_("Go to a hidden room"), -1);
2907         memset(&SubTP, 0, sizeof(WCTemplputParams));
2908         SubTP.Filter.ContextType = CTX_STRBUF;
2909         SubTP.Context = Buf;
2910         DoTemplate(HKEY("beginbox"), NULL, &SubTP);
2911
2912         FreeStrBuf(&Buf);
2913
2914         wc_printf("<p>");
2915         wc_printf(_("If you know the name of a hidden (guess-name) or "
2916                   "passworded room, you can enter that room by typing "
2917                   "its name below.  Once you gain access to a private "
2918                   "room, it will appear in your regular room listings "
2919                   "so you don't have to keep returning here."));
2920         wc_printf("</p>");
2921
2922         wc_printf("<form method=\"post\" action=\"goto_private\">\n");
2923         wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
2924
2925         wc_printf("<table class=\"altern\"> "
2926                 "<tr class=\"even\"><td>");
2927         wc_printf(_("Enter room name:"));
2928         wc_printf("</td><td>"
2929                 "<input type=\"text\" name=\"gr_name\" "
2930                 "value=\"%s\" maxlength=\"128\">\n", rname);
2931
2932         if (req_pass) {
2933                 wc_printf("</td></tr><tr class=\"odd\"><td>");
2934                 wc_printf(_("Enter room password:"));
2935                 wc_printf("</td><td>");
2936                 wc_printf("<input type=\"password\" name=\"gr_pass\" maxlength=\"9\">\n");
2937         }
2938         wc_printf("</td></tr></table>\n");
2939
2940         wc_printf("<div class=\"buttons\">\n");
2941         wc_printf("<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
2942                 "&nbsp;"
2943                 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">",
2944                 _("Go there"),
2945                 _("Cancel")
2946                 );
2947         wc_printf("</div></form>\n");
2948
2949         do_template("endbox", NULL);
2950
2951         wDumpContent(1);
2952 }
2953
2954 /**
2955  * \brief goto a private room
2956  */
2957 void goto_private(void)
2958 {
2959         char hold_rm[SIZ];
2960         char buf[SIZ];
2961
2962         if (!havebstr("ok_button")) {
2963                 display_main_menu();
2964                 return;
2965         }
2966         strcpy(hold_rm, ChrPtr(WC->CurRoom.name));
2967         serv_printf("GOTO %s|%s",
2968                     bstr("gr_name"),
2969                     bstr("gr_pass"));
2970         serv_getln(buf, sizeof buf);
2971
2972         if (buf[0] == '2') {
2973                 smart_goto(sbstr("gr_name"));
2974                 return;
2975         }
2976         if (!strncmp(buf, "540", 3)) {
2977                 display_private(bstr("gr_name"), 1);
2978                 return;
2979         }
2980         output_headers(1, 1, 1, 0, 0, 0);
2981         wc_printf("%s\n", &buf[4]);
2982         wDumpContent(1);
2983         return;
2984 }
2985
2986
2987 /**
2988  * \brief display the screen to zap a room
2989  */
2990 void display_zap(void)
2991 {
2992         output_headers(1, 1, 2, 0, 0, 0);
2993
2994         wc_printf("<div id=\"banner\">\n");
2995         wc_printf("<h1>");
2996         wc_printf(_("Zap (forget/unsubscribe) the current room"));
2997         wc_printf("</h1>\n");
2998         wc_printf("</div>\n");
2999
3000         wc_printf("<div id=\"content\" class=\"service\">\n");
3001
3002         wc_printf(_("If you select this option, <em>%s</em> will "
3003                   "disappear from your room list.  Is this what you wish "
3004                   "to do?<br />\n"), ChrPtr(WC->CurRoom.name));
3005
3006         wc_printf("<form method=\"POST\" action=\"zap\">\n");
3007         wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
3008         wc_printf("<input type=\"submit\" NAME=\"ok_button\" VALUE=\"%s\">", _("Zap this room"));
3009         wc_printf("&nbsp;");
3010         wc_printf("<input type=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3011         wc_printf("</form>\n");
3012         wDumpContent(1);
3013 }
3014
3015
3016 /**
3017  * \brief zap a room
3018  */
3019 void zap(void)
3020 {
3021         char buf[SIZ];
3022         StrBuf *final_destination;
3023
3024         /**
3025          * If the forget-room routine fails for any reason, we fall back
3026          * to the current room; otherwise, we go to the Lobby
3027          */
3028         final_destination = NewStrBufDup(WC->CurRoom.name);
3029
3030         if (havebstr("ok_button")) {
3031                 serv_printf("GOTO %s", ChrPtr(WC->CurRoom.name));
3032                 serv_getln(buf, sizeof buf);
3033                 if (buf[0] == '2') {
3034                         serv_puts("FORG");
3035                         serv_getln(buf, sizeof buf);
3036                         if (buf[0] == '2') {
3037                                 FlushStrBuf(final_destination);
3038                                 StrBufAppendBufPlain(final_destination, HKEY("_BASEROOM_"), 0);
3039                         }
3040                 }
3041         }
3042         smart_goto(final_destination);
3043         FreeStrBuf(&final_destination);
3044 }
3045
3046
3047
3048 /**
3049  * \brief Delete the current room
3050  */
3051 void delete_room(void)
3052 {
3053         char buf[SIZ];
3054
3055         
3056         serv_puts("KILL 1");
3057         serv_getln(buf, sizeof buf);
3058         burn_folder_cache(0);   /* Burn the cahce of known rooms to update the icon bar */
3059         if (buf[0] != '2') {
3060                 strcpy(WC->ImportantMessage, &buf[4]);
3061                 display_main_menu();
3062                 return;
3063         } else {
3064                 StrBuf *Buf;
3065                 
3066                 Buf = NewStrBufPlain(HKEY("_BASEROOM_"));
3067                 smart_goto(Buf);
3068                 FreeStrBuf(&Buf);
3069         }
3070 }
3071
3072
3073
3074 /**
3075  * \brief Perform changes to a room's network configuration
3076  */
3077 void netedit(void) {
3078         FILE *fp;
3079         char buf[SIZ];
3080         char line[SIZ];
3081         char cmpa0[SIZ];
3082         char cmpa1[SIZ];
3083         char cmpb0[SIZ];
3084         char cmpb1[SIZ];
3085         int i, num_addrs;
3086         /*/ TODO: do line dynamic! */
3087         if (havebstr("line_pop3host")) {
3088                 strcpy(line, bstr("prefix"));
3089                 strcat(line, bstr("line_pop3host"));
3090                 strcat(line, "|");
3091                 strcat(line, bstr("line_pop3user"));
3092                 strcat(line, "|");
3093                 strcat(line, bstr("line_pop3pass"));
3094                 strcat(line, "|");
3095                 strcat(line, ibstr("line_pop3keep") ? "1" : "0" );
3096                 strcat(line, "|");
3097                 sprintf(&line[strlen(line)],"%ld", lbstr("line_pop3int"));
3098                 strcat(line, bstr("suffix"));
3099         }
3100         else if (havebstr("line")) {
3101                 strcpy(line, bstr("prefix"));
3102                 strcat(line, bstr("line"));
3103                 strcat(line, bstr("suffix"));
3104         }
3105         else {
3106                 display_editroom();
3107                 return;
3108         }
3109
3110
3111         fp = tmpfile();
3112         if (fp == NULL) {
3113                 display_editroom();
3114                 return;
3115         }
3116
3117         serv_puts("GNET");
3118         serv_getln(buf, sizeof buf);
3119         if (buf[0] != '1') {
3120                 fclose(fp);
3121                 display_editroom();
3122                 return;
3123         }
3124
3125         /** This loop works for add *or* remove.  Spiffy, eh? */
3126         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3127                 extract_token(cmpa0, buf, 0, '|', sizeof cmpa0);
3128                 extract_token(cmpa1, buf, 1, '|', sizeof cmpa1);
3129                 extract_token(cmpb0, line, 0, '|', sizeof cmpb0);
3130                 extract_token(cmpb1, line, 1, '|', sizeof cmpb1);
3131                 if ( (strcasecmp(cmpa0, cmpb0)) 
3132                      || (strcasecmp(cmpa1, cmpb1)) ) {
3133                         fprintf(fp, "%s\n", buf);
3134                 }
3135         }
3136
3137         rewind(fp);
3138         serv_puts("SNET");
3139         serv_getln(buf, sizeof buf);
3140         if (buf[0] != '4') {
3141                 fclose(fp);
3142                 display_editroom();
3143                 return;
3144         }
3145
3146         while (fgets(buf, sizeof buf, fp) != NULL) {
3147                 buf[strlen(buf)-1] = 0;
3148                 serv_puts(buf);
3149         }
3150
3151         if (havebstr("add_button")) {
3152                 num_addrs = num_tokens(bstr("line"), ',');
3153                 if (num_addrs < 2) {
3154                         /* just adding one node or address */
3155                         serv_puts(line);
3156                 }
3157                 else {
3158                         /* adding multiple addresses separated by commas */
3159                         for (i=0; i<num_addrs; ++i) {
3160                                 strcpy(line, bstr("prefix"));
3161                                 extract_token(buf, bstr("line"), i, ',', sizeof buf);
3162                                 striplt(buf);
3163                                 strcat(line, buf);
3164                                 strcat(line, bstr("suffix"));
3165                                 serv_puts(line);
3166                         }
3167                 }
3168         }
3169
3170         serv_puts("000");
3171         fclose(fp);
3172         display_editroom();
3173 }
3174
3175
3176
3177 /**
3178  * \brief Convert a room name to a folder-ish-looking name.
3179  * \param folder the folderish name
3180  * \param room the room name
3181  * \param floor the floor name
3182  * \param is_mailbox is it a mailbox?
3183  */
3184 void room_to_folder(char *folder, char *room, int floor, int is_mailbox)
3185 {
3186         int i, len;
3187
3188         /**
3189          * For mailboxes, just do it straight...
3190          */
3191         if (is_mailbox) {
3192                 sprintf(folder, "My folders|%s", room);
3193         }
3194
3195         /**
3196          * Otherwise, prefix the floor name as a "public folders" moniker
3197          */
3198         else {
3199                 if (floor > MAX_FLOORS) {
3200                         wc_backtrace ();
3201                         sprintf(folder, "%%%%%%|%s", room);
3202                 }
3203                 else {
3204                         sprintf(folder, "%s|%s", floorlist[floor], room);
3205                 }
3206         }
3207
3208         /**
3209          * Replace "\" characters with "|" for pseudo-folder-delimiting
3210          */
3211         len = strlen (folder);
3212         for (i=0; i<len; ++i) {
3213                 if (folder[i] == '\\') folder[i] = '|';
3214         }
3215 }
3216
3217
3218
3219
3220 /**
3221  * \brief Back end for change_view()
3222  * \param newview set newview???
3223  */
3224 void do_change_view(int newview) {
3225         char buf[SIZ];
3226
3227         serv_printf("VIEW %d", newview);
3228         serv_getln(buf, sizeof buf);
3229         WC->CurRoom.view = newview;
3230         smart_goto(WC->CurRoom.name);
3231 }
3232
3233
3234
3235 /**
3236  * \brief Change the view for this room
3237  */
3238 void change_view(void) {
3239         int view;
3240
3241         view = lbstr("view");
3242         do_change_view(view);
3243 }
3244
3245 /**
3246  * \brief Burn the cached folder list.  
3247  * \param age How old the cahce needs to be before we burn it.
3248  */
3249
3250 void burn_folder_cache(time_t age)
3251 {
3252         /** If our cached folder list is very old, burn it. */
3253         if (WC->cache_fold != NULL) {
3254                 if ((time(NULL) - WC->cache_timestamp) > age) {
3255                         free(WC->cache_fold);
3256                         WC->cache_fold = NULL;
3257                 }
3258         }
3259 }
3260
3261
3262
3263 /**
3264  * \brief Do either a known rooms list or a folders list, depending on the
3265  * user's preference
3266  */
3267 void knrooms(void)
3268 {
3269         StrBuf *ListView = NULL;
3270
3271         /** Determine whether the user is trying to change views */
3272         if (havebstr("view")) {
3273                 ListView = NewStrBufDup(SBSTR("view"));
3274                 set_preference("roomlistview", ListView, 1);
3275         }
3276         /** Sanitize the input so its safe */
3277         if((get_preference("roomlistview", &ListView) != 0)||
3278            ((strcasecmp(ChrPtr(ListView), "folders") != 0) &&
3279             (strcasecmp(ChrPtr(ListView), "table") != 0))) 
3280         {
3281                 if (ListView == NULL) {
3282                         ListView = NewStrBufPlain(HKEY("rooms"));
3283                         set_preference("roomlistview", ListView, 0);
3284                         ListView = NULL;
3285                 }
3286                 else {
3287                         ListView = NewStrBufPlain(HKEY("rooms"));
3288                         set_preference("roomlistview", ListView, 0);
3289                         ListView = NULL;
3290                 }
3291         }
3292         FreeStrBuf(&ListView);
3293         url_do_template();
3294 }
3295
3296
3297
3298 /**
3299  * \brief Set the message expire policy for this room and/or floor
3300  */
3301 void set_room_policy(void) {
3302         char buf[SIZ];
3303
3304         if (!havebstr("ok_button")) {
3305                 strcpy(WC->ImportantMessage,
3306                        _("Cancelled.  Changes were not saved."));
3307                 display_editroom();
3308                 return;
3309         }
3310
3311         serv_printf("SPEX room|%d|%d", ibstr("roompolicy"), ibstr("roomvalue"));
3312         serv_getln(buf, sizeof buf);
3313         strcpy(WC->ImportantMessage, &buf[4]);
3314
3315         if (WC->axlevel >= 6) {
3316                 strcat(WC->ImportantMessage, "<br />\n");
3317                 serv_printf("SPEX floor|%d|%d", ibstr("floorpolicy"), ibstr("floorvalue"));
3318                 serv_getln(buf, sizeof buf);
3319                 strcat(WC->ImportantMessage, &buf[4]);
3320         }
3321
3322         display_editroom();
3323 }
3324
3325 void tmplput_RoomName(StrBuf *Target, WCTemplputParams *TP)
3326 {
3327         StrBufAppendTemplate(Target, TP, WC->CurRoom.name, 0);
3328 }
3329
3330
3331 void _display_private(void) {
3332         display_private("", 0);
3333 }
3334
3335 void dotgoto(void) {
3336         if (!havebstr("room")) {
3337                 readloop(readnew, eUseDefault);
3338                 return;
3339         }
3340         if (WC->CurRoom.view != VIEW_MAILBOX) { /* dotgoto acts like dotskip when we're in a mailbox view */
3341                 slrp_highest();
3342         }
3343         smart_goto(sbstr("room"));
3344 }
3345
3346
3347
3348 void tmplput_current_room(StrBuf *Target, WCTemplputParams *TP)
3349 {
3350         wcsession *WCC = WC;
3351
3352         if (WCC != NULL)
3353                 StrBufAppendTemplate(Target, TP, 
3354                                      WCC->CurRoom.name, 
3355                                      0); 
3356 }
3357
3358 void tmplput_roombanner(StrBuf *Target, WCTemplputParams *TP)
3359 {
3360         wc_printf("<div id=\"banner\">\n");
3361         embed_room_banner(NULL, navbar_default);
3362         wc_printf("</div>\n");
3363 }
3364
3365
3366 void tmplput_ungoto(StrBuf *Target, WCTemplputParams *TP)
3367 {
3368         wcsession *WCC = WC;
3369
3370         if ((WCC!=NULL) && 
3371             (!IsEmptyStr(WCC->ugname)))
3372                 StrBufAppendBufPlain(Target, WCC->ugname, -1, 0);
3373 }
3374
3375 int ConditionalRoomAide(StrBuf *Target, WCTemplputParams *TP)
3376 {
3377         wcsession *WCC = WC;
3378         return (WCC != NULL)? 
3379                 ((WCC->CurRoom.RAFlags & UA_ADMINALLOWED) != 0) : 0;
3380 }
3381
3382 int ConditionalRoomAcessDelete(StrBuf *Target, WCTemplputParams *TP)
3383 {
3384         wcsession *WCC = WC;
3385         return (WCC == NULL)? 0 : 
3386                 ( ((WCC->CurRoom.RAFlags & UA_ADMINALLOWED) != 0) ||
3387                    (WCC->CurRoom.is_inbox) || 
3388                    (WCC->CurRoom.QRFlags2 & QR2_COLLABDEL) );
3389 }
3390
3391 int ConditionalHaveUngoto(StrBuf *Target, WCTemplputParams *TP)
3392 {
3393         wcsession *WCC = WC;
3394         
3395         return ((WCC!=NULL) && 
3396                 (!IsEmptyStr(WCC->ugname)) && 
3397                 (strcasecmp(WCC->ugname, ChrPtr(WCC->CurRoom.name)) == 0));
3398 }
3399
3400
3401 int ConditionalRoomHas_UAFlag(StrBuf *Target, WCTemplputParams *TP)
3402 {
3403         folder *Folder = (folder *)(TP->Context);
3404         long UA_CheckFlag;
3405                 
3406         UA_CheckFlag = GetTemplateTokenNumber(Target, TP, 2, 0);
3407         if (UA_CheckFlag == 0)
3408                 LogTemplateError(Target, "Conditional", ERR_PARM1, TP,
3409                                  "requires one of the #\"UA_*\"- defines or an integer flag 0 is invalid!");
3410
3411         return ((Folder->RAFlags & UA_CheckFlag) != 0);
3412 }
3413
3414
3415
3416 int ConditionalCurrentRoomHas_QRFlag(StrBuf *Target, WCTemplputParams *TP)
3417 {
3418         long QR_CheckFlag;
3419         wcsession *WCC = WC;
3420         
3421         QR_CheckFlag = GetTemplateTokenNumber(Target, TP, 2, 0);
3422         if (QR_CheckFlag == 0)
3423                 LogTemplateError(Target, "Conditional", ERR_PARM1, TP,
3424                                  "requires one of the #\"QR*\"- defines or an integer flag 0 is invalid!");
3425
3426         return ((WCC!=NULL) &&
3427                 ((WCC->CurRoom.QRFlags & QR_CheckFlag) != 0));
3428 }
3429
3430 int ConditionalRoomHas_QRFlag(StrBuf *Target, WCTemplputParams *TP)
3431 {
3432         long QR_CheckFlag;
3433         folder *Folder = (folder *)(TP->Context);
3434
3435         QR_CheckFlag = GetTemplateTokenNumber(Target, TP, 2, 0);
3436         if (QR_CheckFlag == 0)
3437                 LogTemplateError(Target, "Conditional", ERR_PARM1, TP,
3438                                  "requires one of the #\"QR*\"- defines or an integer flag 0 is invalid!");
3439         return ((Folder->QRFlags & QR_CheckFlag) != 0);
3440 }
3441
3442
3443 int ConditionalCurrentRoomHas_QRFlag2(StrBuf *Target, WCTemplputParams *TP)
3444 {
3445         long QR2_CheckFlag;
3446         wcsession *WCC = WC;
3447         
3448         QR2_CheckFlag = GetTemplateTokenNumber(Target, TP, 2, 0);
3449         if (QR2_CheckFlag == 0)
3450                 LogTemplateError(Target, "Conditional", ERR_PARM1, TP,
3451                                  "requires one of the #\"QR2*\"- defines or an integer flag 0 is invalid!");
3452
3453         return ((WCC!=NULL) &&
3454                 ((WCC->CurRoom.QRFlags2 & QR2_CheckFlag) != 0));
3455 }
3456
3457 int ConditionalRoomHas_QRFlag2(StrBuf *Target, WCTemplputParams *TP)
3458 {
3459         long QR2_CheckFlag;
3460         folder *Folder = (folder *)(TP->Context);
3461
3462         QR2_CheckFlag = GetTemplateTokenNumber(Target, TP, 2, 0);
3463         if (QR2_CheckFlag == 0)
3464                 LogTemplateError(Target, "Conditional", ERR_PARM1, TP,
3465                                  "requires one of the #\"QR2*\"- defines or an integer flag 0 is invalid!");
3466         return ((Folder->QRFlags2 & QR2_CheckFlag) != 0);
3467 }
3468
3469
3470 int ConditionalHaveRoomeditRights(StrBuf *Target, WCTemplputParams *TP)
3471 {
3472         wcsession *WCC = WC;
3473
3474         return ( (WCC!= NULL) && 
3475                  ((WCC->axlevel >= 6) || 
3476                   ((WCC->CurRoom.RAFlags & UA_ADMINALLOWED) != 0) ||
3477                   (WCC->CurRoom.is_inbox) ));
3478 }
3479
3480 int ConditionalIsRoomtype(StrBuf *Target, WCTemplputParams *TP)
3481 {
3482         wcsession *WCC = WC;
3483
3484         if ((WCC == NULL) ||
3485             (TP->Tokens->nParameters < 3))
3486         {
3487                 return ((WCC->CurRoom.view < VIEW_BBS) || 
3488                         (WCC->CurRoom.view > VIEW_MAX));
3489         }
3490
3491         return WCC->CurRoom.view == GetTemplateTokenNumber(Target, TP, 2, VIEW_BBS);
3492 }
3493
3494
3495 HashList *GetWhoKnowsHash(StrBuf *Target, WCTemplputParams *TP)
3496 {
3497         wcsession *WCC = WC;
3498         StrBuf *Line;
3499         StrBuf *Token;
3500         long State;
3501         HashList *Whok = NULL;
3502         int Done = 0;
3503         int n;
3504
3505         serv_puts("WHOK");
3506         Line = NewStrBuf();
3507         Token = NewStrBuf();
3508         StrBuf_ServGetln(Line);
3509         if (GetServerStatus(Line, &State) == 1) 
3510         {
3511                 Whok = NewHash(1, Flathash);
3512                 while(!Done && StrBuf_ServGetln(Line))
3513                         if ( (StrLength(Line)==3) && 
3514                              !strcmp(ChrPtr(Line), "000")) 
3515                         {
3516                                 Done = 1;
3517                         }
3518                         else
3519                         {
3520                         
3521                                 const char *Pos = NULL;
3522                                 Token = NewStrBufPlain (NULL, StrLength(Line));
3523                                 StrBufExtract_NextToken(Token, Line, &Pos, '|');
3524
3525                                 Put(Whok, 
3526                                     IKEY(n),
3527                                     Token, 
3528                                     HFreeStrBuf);
3529                         }
3530         }
3531         else if (State == 550)
3532                 StrBufAppendBufPlain(WCC->ImportantMsg,
3533                                      _("Higher access is required to access this function."), -1, 0);
3534
3535
3536         return Whok;
3537 }
3538
3539 void 
3540 InitModule_ROOMOPS
3541 (void)
3542 {
3543         initialize_viewdefs();
3544         RegisterPreference("roomlistview",
3545                            _("Room list view"),
3546                            PRF_STRING,
3547                            NULL);
3548         RegisterPreference("emptyfloors", _("Show empty floors"), PRF_YESNO, NULL);
3549
3550         RegisterNamespace("ROOMNAME", 0, 1, tmplput_RoomName, NULL, CTX_NONE);
3551
3552
3553         WebcitAddUrlHandler(HKEY("knrooms"), "", 0, knrooms, 0);
3554         WebcitAddUrlHandler(HKEY("dotgoto"), "", 0, dotgoto, NEED_URL);
3555         WebcitAddUrlHandler(HKEY("dotskip"), "", 0, dotskip, NEED_URL);
3556         WebcitAddUrlHandler(HKEY("display_private"), "", 0, _display_private, 0);
3557         WebcitAddUrlHandler(HKEY("goto_private"), "", 0, goto_private, NEED_URL);
3558         WebcitAddUrlHandler(HKEY("zapped_list"), "", 0, zapped_list, 0);
3559         WebcitAddUrlHandler(HKEY("display_zap"), "", 0, display_zap, 0);
3560         WebcitAddUrlHandler(HKEY("zap"), "", 0, zap, 0);
3561         WebcitAddUrlHandler(HKEY("display_entroom"), "", 0, display_entroom, 0);
3562         WebcitAddUrlHandler(HKEY("entroom"), "", 0, entroom, 0);
3563         WebcitAddUrlHandler(HKEY("display_whok"), "", 0, display_whok, 0);
3564         WebcitAddUrlHandler(HKEY("do_invt_kick"), "", 0, do_invt_kick, 0);
3565         WebcitAddUrlHandler(HKEY("display_editroom"), "", 0, display_editroom, 0);
3566         WebcitAddUrlHandler(HKEY("netedit"), "", 0, netedit, 0);
3567         WebcitAddUrlHandler(HKEY("editroom"), "", 0, editroom, 0);
3568         WebcitAddUrlHandler(HKEY("delete_room"), "", 0, delete_room, 0);
3569         WebcitAddUrlHandler(HKEY("set_room_policy"), "", 0, set_room_policy, 0);
3570         WebcitAddUrlHandler(HKEY("changeview"), "", 0, change_view, 0);
3571         WebcitAddUrlHandler(HKEY("toggle_self_service"), "", 0, toggle_self_service, 0);
3572         RegisterNamespace("ROOMBANNER", 0, 1, tmplput_roombanner, NULL, CTX_NONE);
3573
3574         RegisterConditional(HKEY("COND:ROOM:TYPE_IS"), 0, ConditionalIsRoomtype, CTX_NONE);
3575         RegisterConditional(HKEY("COND:THISROOM:FLAG:QR"), 0, ConditionalCurrentRoomHas_QRFlag, CTX_NONE);
3576         RegisterConditional(HKEY("COND:ROOM:FLAG:QR"), 0, ConditionalRoomHas_QRFlag, CTX_ROOMS);
3577
3578         RegisterConditional(HKEY("COND:THISROOM:FLAG:QR2"), 0, ConditionalCurrentRoomHas_QRFlag2, CTX_NONE);
3579         RegisterConditional(HKEY("COND:ROOM:FLAG:QR2"), 0, ConditionalRoomHas_QRFlag2, CTX_ROOMS);
3580         RegisterConditional(HKEY("COND:ROOM:FLAG:UA"), 0, ConditionalRoomHas_UAFlag, CTX_ROOMS);
3581
3582         RegisterIterator("ITERATE:THISROOM:WHO_KNOWS", 0, NULL, GetWhoKnowsHash, NULL, DeleteHash, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
3583         RegisterNamespace("THISROOM:MSGS:NEW", 0, 0, tmplput_CurrentRoom_nNewMessages, NULL, CTX_NONE);
3584         RegisterNamespace("THISROOM:MSGS:TOTAL", 0, 0, tmplput_CurrentRoom_nTotalMessages, NULL, CTX_NONE);
3585
3586         RegisterNamespace("THISROOM:FLOOR:NAME", 0, 1, tmplput_CurrentRoomFloorName, NULL, CTX_NONE);
3587         RegisterNamespace("THISROOM:AIDE", 0, 1, tmplput_CurrentRoomAide, NULL, CTX_NONE);
3588         RegisterNamespace("THISROOM:PASS", 0, 1, tmplput_CurrentRoomPass, NULL, CTX_NONE);
3589         RegisterNamespace("THISROOM:DIRECTORY", 0, 1, tmplput_CurrentRoomDirectory, NULL, CTX_NONE);
3590         RegisterNamespace("THISROOM:ORDER", 0, 0, tmplput_CurrentRoomOrder, NULL, CTX_NONE);
3591         RegisterNamespace("THISROOM:DEFAULT_VIEW", 0, 0, tmplput_CurrentRoomDefView, NULL, CTX_NONE);
3592         RegisterConditional(HKEY("COND:THISROOM:HAVE_VIEW"), 0, ConditionalThisRoomHaveView, CTX_NONE);
3593         RegisterNamespace("THISROOM:VIEW_STRING", 0, 1, tmplput_CurrentRoomViewString, NULL, CTX_NONE);
3594         RegisterNamespace("ROOM:VIEW_STRING", 1, 2, tmplput_RoomViewString, NULL, CTX_NONE);
3595
3596         RegisterNamespace("THISROOM:INFOTEXT", 1, 2, tmplput_CurrentRoomInfoText, NULL, CTX_NONE);
3597         RegisterConditional(HKEY("COND:THISROOM:ORDER"), 0, ConditionalThisRoomOrder, CTX_NONE);
3598         RegisterConditional(HKEY("COND:THISROOM:DEFAULT_VIEW"), 0, ConditionalThisRoomDefView, CTX_NONE);
3599         RegisterConditional(HKEY("COND:THISROOM:HAVE_PIC"), 0, ConditionalThisRoomXHavePic, CTX_NONE);
3600         RegisterConditional(HKEY("COND:THISROOM:HAVE_INFOTEXT"), 0, ConditionalThisRoomXHaveInfoText, CTX_NONE);
3601         RegisterNamespace("THISROOM:FILES:N", 0, 1, tmplput_CurrentRoomXNFiles, NULL, CTX_NONE);
3602         RegisterNamespace("THISROOM:FILES:STR", 0, 1, tmplput_CurrentRoomX_FileString, NULL, CTX_NONE);
3603
3604         REGISTERTokenParamDefine(QR_PERMANENT);
3605         REGISTERTokenParamDefine(QR_INUSE);
3606         REGISTERTokenParamDefine(QR_PRIVATE);
3607         REGISTERTokenParamDefine(QR_PASSWORDED);
3608         REGISTERTokenParamDefine(QR_GUESSNAME);
3609         REGISTERTokenParamDefine(QR_DIRECTORY);
3610         REGISTERTokenParamDefine(QR_UPLOAD);
3611         REGISTERTokenParamDefine(QR_DOWNLOAD);
3612         REGISTERTokenParamDefine(QR_VISDIR);
3613         REGISTERTokenParamDefine(QR_ANONONLY);
3614         REGISTERTokenParamDefine(QR_ANONOPT);
3615         REGISTERTokenParamDefine(QR_NETWORK);
3616         REGISTERTokenParamDefine(QR_PREFONLY);
3617         REGISTERTokenParamDefine(QR_READONLY);
3618         REGISTERTokenParamDefine(QR_MAILBOX);
3619         REGISTERTokenParamDefine(QR2_SYSTEM);
3620         REGISTERTokenParamDefine(QR2_SELFLIST);
3621         REGISTERTokenParamDefine(QR2_COLLABDEL);
3622         REGISTERTokenParamDefine(QR2_SUBJECTREQ);
3623         REGISTERTokenParamDefine(QR2_SMTP_PUBLIC);
3624         REGISTERTokenParamDefine(QR2_MODERATED);
3625
3626         REGISTERTokenParamDefine(UA_KNOWN);
3627         REGISTERTokenParamDefine(UA_GOTOALLOWED);
3628         REGISTERTokenParamDefine(UA_HASNEWMSGS);
3629         REGISTERTokenParamDefine(UA_ZAPPED);
3630         REGISTERTokenParamDefine(UA_POSTALLOWED);
3631         REGISTERTokenParamDefine(UA_ADMINALLOWED);
3632         REGISTERTokenParamDefine(UA_DELETEALLOWED);
3633         REGISTERTokenParamDefine(UA_ISTRASH);
3634
3635         REGISTERTokenParamDefine(US_NEEDVALID);
3636         REGISTERTokenParamDefine(US_PERM);
3637         REGISTERTokenParamDefine(US_LASTOLD);
3638         REGISTERTokenParamDefine(US_EXPERT);
3639         REGISTERTokenParamDefine(US_UNLISTED);
3640         REGISTERTokenParamDefine(US_NOPROMPT);
3641         REGISTERTokenParamDefine(US_PROMPTCTL);
3642         REGISTERTokenParamDefine(US_DISAPPEAR);
3643         REGISTERTokenParamDefine(US_REGIS);
3644         REGISTERTokenParamDefine(US_PAGINATOR);
3645         REGISTERTokenParamDefine(US_INTERNET);
3646         REGISTERTokenParamDefine(US_FLOORS);
3647         REGISTERTokenParamDefine(US_COLOR);
3648         REGISTERTokenParamDefine(US_USER_SET);
3649
3650         REGISTERTokenParamDefine(VIEW_BBS);
3651         REGISTERTokenParamDefine(VIEW_MAILBOX); 
3652         REGISTERTokenParamDefine(VIEW_ADDRESSBOOK);
3653         REGISTERTokenParamDefine(VIEW_CALENDAR);        
3654         REGISTERTokenParamDefine(VIEW_TASKS);   
3655         REGISTERTokenParamDefine(VIEW_NOTES);           
3656         REGISTERTokenParamDefine(VIEW_WIKI);            
3657         REGISTERTokenParamDefine(VIEW_CALBRIEF);
3658         REGISTERTokenParamDefine(VIEW_JOURNAL);
3659         REGISTERTokenParamDefine(VIEW_BLOG);
3660
3661         /* GNET types: */
3662         REGISTERTokenParamDefine(ignet_push_share);
3663         { /* these are the parts of an IGNET push config */
3664                 REGISTERTokenParamDefine(GNET_IGNET_NODE);
3665                 REGISTERTokenParamDefine(GNET_IGNET_ROOM);
3666         }
3667         REGISTERTokenParamDefine(listrecp);
3668         REGISTERTokenParamDefine(digestrecp);
3669         REGISTERTokenParamDefine(pop3client);
3670         { /* These are the parts of a pop3 client line... */
3671                 REGISTERTokenParamDefine(GNET_POP3_HOST);
3672                 REGISTERTokenParamDefine(GNET_POP3_USER);
3673                 REGISTERTokenParamDefine(GNET_POP3_DONT_DELETE_REMOTE);
3674                 REGISTERTokenParamDefine(GNET_POP3_INTERVAL);
3675         }
3676         REGISTERTokenParamDefine(rssclient);
3677         REGISTERTokenParamDefine(participate);
3678
3679         RegisterConditional(HKEY("COND:ROOMAIDE"), 2, ConditionalRoomAide, CTX_NONE);
3680         RegisterConditional(HKEY("COND:ACCESS:DELETE"), 2, ConditionalRoomAcessDelete, CTX_NONE);
3681
3682         RegisterConditional(HKEY("COND:UNGOTO"), 0, ConditionalHaveUngoto, CTX_NONE);
3683         RegisterConditional(HKEY("COND:ROOM:EDITACCESS"), 0, ConditionalHaveRoomeditRights, CTX_NONE);
3684
3685         RegisterNamespace("CURRENT_ROOM", 0, 1, tmplput_current_room, NULL, CTX_NONE);
3686         RegisterNamespace("ROOM:UNGOTO", 0, 0, tmplput_ungoto, NULL, CTX_NONE);
3687         RegisterIterator("FLOORS", 0, NULL, GetFloorListHash, NULL, NULL, CTX_FLOORS, CTX_NONE, IT_NOFLAG);
3688
3689
3690 }
3691
3692
3693 void 
3694 SessionDestroyModule_ROOMOPS
3695 (wcsession *sess)
3696 {
3697         FlushFolder(&sess->CurRoom);
3698         if (sess->cache_fold != NULL) {
3699                 free(sess->cache_fold);
3700         }
3701         
3702         free_march_list(sess);
3703         DeleteHash(&sess->Floors);
3704         DeleteHash(&sess->Rooms);
3705         DeleteHash(&sess->FloorsByName);
3706 }
3707
3708
3709 /*@}*/