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