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