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