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