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