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