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