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