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