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