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