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