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