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