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