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