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