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