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