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