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