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