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