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