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