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