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