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