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