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