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