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