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