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