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