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