File: roomops.c

package info (click to toggle)
webcit 7.37-dfsg-7
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 6,972 kB
  • ctags: 2,344
  • sloc: ansic: 23,301; sh: 3,618; makefile: 239
file content (3619 lines) | stat: -rw-r--r-- 94,477 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
/*
 * $Id: roomops.c 6384 2008-06-16 03:22:25Z ajc $
 * Lots of different room-related operations.
 */

#include "webcit.h"
#include "webserver.h"
#define MAX_FLOORS 128
char floorlist[MAX_FLOORS][SIZ]; /**< list of our floor names */

char *viewdefs[9]; /**< the different kinds of available views */

/*
 * Initialize the viewdefs with localized strings
 */
void initialize_viewdefs(void) {
	viewdefs[0] = _("Bulletin Board");
	viewdefs[1] = _("Mail Folder");
	viewdefs[2] = _("Address Book");
	viewdefs[3] = _("Calendar");
	viewdefs[4] = _("Task List");
	viewdefs[5] = _("Notes List");
	viewdefs[6] = _("Wiki");
	viewdefs[7] = _("Calendar List");
	viewdefs[8] = _("Journal");
}

/*
 * Determine which views are allowed as the default for creating a new room.
 */
int is_view_allowed_as_default(int which_view)
{
	switch(which_view) {
		case VIEW_BBS:		return(1);
		case VIEW_MAILBOX:	return(1);
		case VIEW_ADDRESSBOOK:	return(1);
		case VIEW_CALENDAR:	return(1);
		case VIEW_TASKS:	return(1);
		case VIEW_NOTES:	return(1);

#ifdef TECH_PREVIEW
		case VIEW_WIKI:		return(1);
#else /* TECH_PREVIEW */
		case VIEW_WIKI:		return(0);	/* because it isn't finished yet */
#endif /* TECH_PREVIEW */

		case VIEW_CALBRIEF:	return(0);
		case VIEW_JOURNAL:	return(0);
		default:		return(0);	/* should never get here */
	}
}


/*
 * load the list of floors
 */
void load_floorlist(void)
{
	int a;
	char buf[SIZ];

	for (a = 0; a < MAX_FLOORS; ++a)
		floorlist[a][0] = 0;

	serv_puts("LFLR");
	serv_getln(buf, sizeof buf);
	if (buf[0] != '1') {
		strcpy(floorlist[0], "Main Floor");
		return;
	}
	while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
		extract_token(floorlist[extract_int(buf, 0)], buf, 1, '|', sizeof floorlist[0]);
	}
}


/*
 * Free a session's march list
 */
void free_march_list(struct wcsession *wcf)
{
	struct march *mptr;

	while (wcf->march != NULL) {
		mptr = wcf->march->next;
		free(wcf->march);
		wcf->march = mptr;
	}

}



/*
 * remove a room from the march list
 */
void remove_march(char *aaa)
{
	struct march *mptr, *mptr2;

	if (WC->march == NULL)
		return;

	if (!strcasecmp(WC->march->march_name, aaa)) {
		mptr = WC->march->next;
		free(WC->march);
		WC->march = mptr;
		return;
	}
	mptr2 = WC->march;
	for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
		if (!strcasecmp(mptr->march_name, aaa)) {
			mptr2->next = mptr->next;
			free(mptr);
			mptr = mptr2;
		} else {
			mptr2 = mptr;
		}
	}
}




/*
 * display rooms in tree structure
 */
void room_tree_list(struct roomlisting *rp)
{
	char rmname[64];
	int f;

	if (rp == NULL) {
		return;
	}

	room_tree_list(rp->lnext);

	strcpy(rmname, rp->rlname);
	f = rp->rlflags;

	wprintf("<a href=\"dotgoto&room=");
	urlescputs(rmname);
	wprintf("\"");
	wprintf(">");
	escputs1(rmname, 1, 1);
	if ((f & QR_DIRECTORY) && (f & QR_NETWORK))
		wprintf("}");
	else if (f & QR_DIRECTORY)
		wprintf("]");
	else if (f & QR_NETWORK)
		wprintf(")");
	else
		wprintf("&gt;");
	wprintf("</a><tt> </tt>\n");

	room_tree_list(rp->rnext);
	free(rp);
}


/** 
 * \brief Room ordering stuff (compare first by floor, then by order)
 * \param r1 first roomlist to compare
 * \param r2 second roomlist co compare
 * \return are they the same???
 */
int rordercmp(struct roomlisting *r1, struct roomlisting *r2)
{
	if ((r1 == NULL) && (r2 == NULL))
		return (0);
	if (r1 == NULL)
		return (-1);
	if (r2 == NULL)
		return (1);
	if (r1->rlfloor < r2->rlfloor)
		return (-1);
	if (r1->rlfloor > r2->rlfloor)
		return (1);
	if (r1->rlorder < r2->rlorder)
		return (-1);
	if (r1->rlorder > r2->rlorder)
		return (1);
	return (0);
}


/**
 * \brief Common code for all room listings
 * \param variety what???
 */
void listrms(char *variety)
{
	char buf[SIZ];
	int num_rooms = 0;

	struct roomlisting *rl = NULL;
	struct roomlisting *rp;
	struct roomlisting *rs;

	/** Ask the server for a room list */
	serv_puts(variety);
	serv_getln(buf, sizeof buf);
	if (buf[0] != '1') {
		wprintf("&nbsp;");
		return;
	}

	while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
		++num_rooms;
		rp = malloc(sizeof(struct roomlisting));
		extract_token(rp->rlname, buf, 0, '|', sizeof rp->rlname);
		rp->rlflags = extract_int(buf, 1);
		rp->rlfloor = extract_int(buf, 2);
		rp->rlorder = extract_int(buf, 3);
		rp->lnext = NULL;
		rp->rnext = NULL;

		rs = rl;
		if (rl == NULL) {
			rl = rp;
		} else
			while (rp != NULL) {
				if (rordercmp(rp, rs) < 0) {
					if (rs->lnext == NULL) {
						rs->lnext = rp;
						rp = NULL;
					} else {
						rs = rs->lnext;
					}
				} else {
					if (rs->rnext == NULL) {
						rs->rnext = rp;
						rp = NULL;
					} else {
						rs = rs->rnext;
					}
				}
			}
	}

	room_tree_list(rl);

	/**
	 * If no rooms were listed, print an nbsp to make the cell
	 * borders show up anyway.
	 */
	if (num_rooms == 0) wprintf("&nbsp;");
}


/**
 * \brief list all forgotten rooms
 */
void zapped_list(void)
{
	output_headers(1, 1, 1, 0, 0, 0);

	svput("BOXTITLE", WCS_STRING, _("Zapped (forgotten) rooms"));
	do_template("beginbox");

	listrms("LZRM -1");

	wprintf("<br /><br />\n");
	wprintf(_("Click on any room to un-zap it and goto that room.\n"));
	do_template("endbox");
	wDumpContent(1);
}


/**
 * \brief read this room's info file (set v to 1 for verbose mode)
 */
void readinfo(void)
{
	char buf[256];
	char briefinfo[128];
	char fullinfo[8192];
	int fullinfo_len = 0;

	serv_puts("RINF");
	serv_getln(buf, sizeof buf);
	if (buf[0] == '1') {

		while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
			if (fullinfo_len < (sizeof fullinfo - sizeof buf)) {
				strcpy(&fullinfo[fullinfo_len], buf);
				fullinfo_len += strlen(buf);
			}
		}

		safestrncpy(briefinfo, fullinfo, sizeof briefinfo);
		strcpy(&briefinfo[50], "...");

                wprintf("<div class=\"infos\" "
                "onclick=\"javascript:Effect.Appear('room_infos', { duration: 0.5 });\" "
                ">");
		escputs(briefinfo);
                wprintf("</div><div id=\"room_infos\" style=\"display:none;\">");
		wprintf("<img class=\"close_infos\" "
                	"onclick=\"javascript:Effect.Fade('room_infos', { duration: 0.5 });\" "
			"src=\"static/closewindow.gif\" alt=\"%s\">",
			_("Close window")
		);
		escputs(fullinfo);
                wprintf("</div>");
	}
	else {
		wprintf("&nbsp;");
	}
}




/**
 * \brief Display room banner icon.  
 * The server doesn't actually
 * need the room name, but we supply it in order to
 * keep the browser from using a cached icon from 
 * another room.
 */
void embed_room_graphic(void) {
	char buf[SIZ];

	serv_puts("OIMG _roompic_");
	serv_getln(buf, sizeof buf);
	if (buf[0] == '2') {
		wprintf("<img height=\"64px\" src=\"image&name=_roompic_&room=");
		urlescputs(WC->wc_roomname);
		wprintf("\">");
		serv_puts("CLOS");
		serv_getln(buf, sizeof buf);
	}
	else if (WC->wc_view == VIEW_ADDRESSBOOK) {
		wprintf("<img class=\"roompic\" alt=\"\" src=\""
			"static/viewcontacts_48x.gif"
			"\">"
		);
	}
	else if ( (WC->wc_view == VIEW_CALENDAR) || (WC->wc_view == VIEW_CALBRIEF) ) {
		wprintf("<img class=\"roompic\" alt=\"\" src=\""
			"static/calarea_48x.gif"
			"\">"
		);
	}
	else if (WC->wc_view == VIEW_TASKS) {
		wprintf("<img class=\"roompic\" alt=\"\" src=\""
			"static/taskmanag_48x.gif"
			"\">"
		);
	}
	else if (WC->wc_view == VIEW_NOTES) {
		wprintf("<img class=\"roompic\" alt=\"\" src=\""
			"static/storenotes_48x.gif"
			"\">"
		);
	}
	else if (WC->wc_view == VIEW_MAILBOX) {
		wprintf("<img class=\"roompic\" alt=\"\" src=\""
			"static/privatemess_48x.gif"
			"\">"
		);
	}
	else {
		wprintf("<img class=\"roompic\" alt=\"\" src=\""
			"static/chatrooms_48x.gif"
			"\">"
		);
	}

}



/**
 * \brief Display the current view and offer an option to change it
 */
void embed_view_o_matic(void) {
	int i;

	wprintf("<form name=\"viewomatic\" action=\"changeview\">\n");
	wprintf("\t<div style=\"display: inline;\">\n\t<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
	wprintf("<label for=\"view_name\">");
	wprintf(_("View as:"));
	wprintf("</label> "
		"<select name=\"newview\" size=\"1\" "
		"id=\"view_name\" class=\"selectbox\" "
		"OnChange=\"location.href=viewomatic.newview.options"
		"[selectedIndex].value\">\n");

	for (i=0; i<(sizeof viewdefs / sizeof (char *)); ++i) {
		/**
		 * Only offer the views that make sense, given the default
		 * view for the room.  For example, don't offer a Calendar
		 * view in a non-Calendar room.
		 */
		if (
			(i == WC->wc_view)
			||	(i == WC->wc_default_view)			/**< default */
			||	( (i == 0) && (WC->wc_default_view == 1) )	/**< mail or bulletin */
			||	( (i == 1) && (WC->wc_default_view == 0) )	/**< mail or bulletin */
			/** ||	( (i == 7) && (WC->wc_default_view == 3) )	(calendar list temporarily disabled) */
		) {

			wprintf("<option %s value=\"changeview?view=%d\">",
				((i == WC->wc_view) ? "selected" : ""),
				i );
			escputs(viewdefs[i]);
			wprintf("</option>\n");
		}
	}
	wprintf("</select></div></form>\n");
}


/**
 * \brief Display a search box
 */
void embed_search_o_matic(void) {
	wprintf("<form name=\"searchomatic\" action=\"do_search\">\n");
	wprintf("<div style=\"display: inline;\"><input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
	wprintf("<label for=\"search_name\">");
	wprintf(_("Search: "));
	wprintf("</label><input ");
	wprintf("%s", serv_info.serv_fulltext_enabled ? "" : "disabled ");
	wprintf("type=\"text\" name=\"query\" size=\"15\" maxlength=\"128\" "
		"id=\"search_name\" class=\"inputbox\">\n"
	);
	wprintf("</div></form>\n");
}


/**
 * \brief		Embed the room banner
 *
 * \param got		The information returned from a GOTO server command
 * \param navbar_style 	Determines which navigation buttons to display
 *
 */

void embed_room_banner(char *got, int navbar_style) {
	char buf[256];
	char buf2[1024];
	char sanitized_roomname[256];
	char with_files[256];
	int file_count=0;
	
	/**
	 * We need to have the information returned by a GOTO server command.
	 * If it isn't supplied, we fake it by issuing our own GOTO.
	 */
	if (got == NULL) {
		serv_printf("GOTO %s", WC->wc_roomname);
		serv_getln(buf, sizeof buf);
		got = buf;
	}

	/** The browser needs some information for its own use */
	wprintf("<script type=\"text/javascript\">	\n"
		"	room_is_trash = %d;		\n"
		"</script>\n",
		WC->wc_is_trash
	);

	/**
	 * If the user happens to select the "make this my start page" link,
	 * we want it to remember the URL as a "/dotskip" one instead of
	 * a "skip" or "gotonext" or something like that.
	 */
	snprintf(WC->this_page, sizeof(WC->this_page), "dotskip&room=%s",
		WC->wc_roomname);

	/** Check for new mail. */
	WC->new_mail = extract_int(&got[4], 9);
	WC->wc_view = extract_int(&got[4], 11);

	/* Is this a directory room and does it contain files and how many? */
	if ((WC->room_flags & QR_DIRECTORY) && (WC->room_flags & QR_VISDIR))
	{
		serv_puts("RDIR");
		serv_getln(buf2, sizeof buf2);
		if (buf2[0] == '1') while (serv_getln(buf2, sizeof buf2), strcmp(buf2, "000"))
			file_count++;
		snprintf (with_files, sizeof with_files, 
			  "; <a href=\"display_room_directory\"> %d %s </a>", 
			  file_count, 
			  ((file_count>1) || (file_count == 0)  ? _("files") : _("file")));
	}
	else
		strcpy (with_files, "");
		
	stresc(sanitized_roomname, 256, WC->wc_roomname, 1, 1);
	svprintf(HKEY("ROOMNAME"), WCS_STRING, "%s", sanitized_roomname);
	svprintf(HKEY("NUMMSGS"), WCS_STRING,
		_("%d new of %d messages%s"),
		extract_int(&got[4], 1),
		extract_int(&got[4], 2),
		with_files
	);
	svcallback("ROOMPIC", embed_room_graphic);
	svcallback("ROOMINFO", readinfo);
	svcallback("VIEWOMATIC", embed_view_o_matic);
	svcallback("SEARCHOMATIC", embed_search_o_matic);
	svcallback("START", offer_start_page);

	do_template("roombanner");
	if (navbar_style != navbar_none) {

		wprintf("<div id=\"navbar\"><ul>");

		if (navbar_style == navbar_default) wprintf(
			"<li class=\"ungoto\">"
			"<a href=\"ungoto\">"
			"<img src=\"static/ungoto2_24x.gif\" alt=\"\">"
			"<span class=\"navbar_link\">%s</span></A>"
			"</li>\n", _("Ungoto")
		);

		if ( (navbar_style == navbar_default) && (WC->wc_view == VIEW_BBS) ) {
			wprintf(
				"<li class=\"newmess\">"
				"<a href=\"readnew\">"
				"<img src=\"static/newmess2_24x.gif\" alt=\"\">"
				"<span class=\"navbar_link\">%s</span></A>"
				"</li>\n", _("Read new messages")
			);
		}

		if (navbar_style == navbar_default) {
			switch(WC->wc_view) {
				case VIEW_ADDRESSBOOK:
					wprintf(
						"<li class=\"viewcontacts\">"
						"<a href=\"readfwd\">"
						"<img src=\"static/viewcontacts_24x.gif\" "
						"alt=\"\">"
						"<span class=\"navbar_link\">"
						"%s"
						"</span></a></li>\n", _("View contacts")
					);
					break;
				case VIEW_CALENDAR:
					wprintf(
						"<li class=\"staskday\">"
						"<a href=\"readfwd?calview=day\">"
						"<img src=\"static/taskday2_24x.gif\" "
						"alt=\"\">"
						"<span class=\"navbar_link\">"
						"%s"
						"</span></a></li>\n", _("Day view")
					);
					wprintf(
						"<li class=\"monthview\">"
						"<a href=\"readfwd?calview=month\">"
						"<img src=\"static/monthview2_24x.gif\" "
						"alt=\"\">"
						"<span class=\"navbar_link\">"
						"%s"
						"</span></a></li>\n", _("Month view")
					);
					break;
				case VIEW_CALBRIEF:
					wprintf(
						"<li class=\"monthview\">"
						"<a href=\"readfwd?calview=month\">"
						"<img src=\"static/monthview2_24x.gif\" "
						"alt=\"\">"
						"<span class=\"navbar_link\">"
						"%s"
						"</span></a></li>\n", _("Calendar list")
					);
					break;
				case VIEW_TASKS:
					wprintf(
						"<li class=\"taskmanag\">"
						"<a href=\"readfwd\">"
						"<img src=\"static/taskmanag_24x.gif\" "
						"alt=\"\">"
						"<span class=\"navbar_link\">"
						"%s"
						"</span></a></li>\n", _("View tasks")
					);
					break;
				case VIEW_NOTES:
					wprintf(
						"<li class=\"viewnotes\">"
						"<a href=\"readfwd\">"
						"<img src=\"static/viewnotes_24x.gif\" "
						"alt=\"\">"
						"<span class=\"navbar_link\">"
						"%s"
						"</span></a></li>\n", _("View notes")
					);
					break;
				case VIEW_MAILBOX:
					wprintf(
						"<li class=\"readallmess\">"
						"<a href=\"readfwd\">"
						"<img src=\"static/readallmess3_24x.gif\" "
						"alt=\"\">"
						"<span class=\"navbar_link\">"
						"%s"
						"</span></a></li>\n", _("View message list")
					);
					break;
				case VIEW_WIKI:
					wprintf(
						"<li class=\"readallmess\">"
						"<a href=\"readfwd\">"
						"<img src=\"static/readallmess3_24x.gif\" "
						"alt=\"\">"
						"<span class=\"navbar_link\">"
						"%s"
						"</span></a></li>\n", _("Wiki home")
					);
					break;
				default:
					wprintf(
						"<li class=\"readallmess\">"
						"<a href=\"readfwd\">"
						"<img src=\"static/readallmess3_24x.gif\" "
						"alt=\"\">"
						"<span class=\"navbar_link\">"
						"%s"
						"</span></a></li>\n", _("Read all messages")
					);
					break;
			}
		}

		if (navbar_style == navbar_default) {
			switch(WC->wc_view) {
				case VIEW_ADDRESSBOOK:
					wprintf(
						"<li class=\"addnewcontact\">"
						"<a href=\"display_enter\">"
						"<img src=\"static/addnewcontact_24x.gif\" "
						"alt=\"\"><span class=\"navbar_link\">"
						"%s"
						"</span></a></li>\n", _("Add new contact")
					);
					break;
				case VIEW_CALENDAR:
				case VIEW_CALBRIEF:
					wprintf("<li class=\"addevent\"><a href=\"display_enter");
					if (havebstr("year" )) wprintf("?year=%s", bstr("year"));
					if (havebstr("month")) wprintf("?month=%s", bstr("month"));
					if (havebstr("day"  )) wprintf("?day=%s", bstr("day"));
					wprintf("\">"
						"<img  src=\"static/addevent_24x.gif\" "
						"alt=\"\"><span class=\"navbar_link\">"
						"%s"
						"</span></a></li>\n", _("Add new event")
					);
					break;
				case VIEW_TASKS:
					wprintf(
						"<li class=\"newmess\">"
						"<a href=\"display_enter\">"
						"<img  src=\"static/newmess3_24x.gif\" "
						"alt=\"\"><span class=\"navbar_link\">"
						"%s"
						"</span></a></li>\n", _("Add new task")
					);
					break;
				case VIEW_NOTES:
					wprintf(
						"<li class=\"enternewnote\">"
						"<a href=\"add_new_note\">"
						"<img  src=\"static/enternewnote_24x.gif\" "
						"alt=\"\"><span class=\"navbar_link\">"
						"%s"
						"</span></a></li>\n", _("Add new note")
					);
					break;
				case VIEW_WIKI:
					safestrncpy(buf, bstr("page"), sizeof buf);
					str_wiki_index(buf);
					wprintf(
						"<li class=\"newmess\">"
						"<a href=\"display_enter?wikipage=%s\">"
						"<img  src=\"static/newmess3_24x.gif\" "
						"alt=\"\"><span class=\"navbar_link\">"
						"%s"
						"</span></a></li>\n", buf, _("Edit this page")
					);
					break;
				case VIEW_MAILBOX:
					wprintf(
						"<li class=\"newmess\">"
						"<a href=\"display_enter\">"
						"<img  src=\"static/newmess3_24x.gif\" "
						"alt=\"\"><span class=\"navbar_link\">"
						"%s"
						"</span></a></li>\n", _("Write mail")
					);
					break;
				default:
					wprintf(
						"<li class=\"newmess\">"
						"<a href=\"display_enter\">"
						"<img  src=\"static/newmess3_24x.gif\" "
						"alt=\"\"><span class=\"navbar_link\">"
						"%s"
						"</span></a></li>\n", _("Enter a message")
					);
					break;
			}
		}

		if (navbar_style == navbar_default) wprintf(
			"<li class=\"skipthisroom\">"
			"<a href=\"skip\" "
			"title=\"%s\">"
			"<img  src=\"static/skipthisroom_24x.gif\" alt=\"\">"
			"<span class=\"navbar_link\">%s</span></a>"
			"</li>\n",
			_("Leave all messages marked as unread, go to next room with unread messages"),
			_("Skip this room")
		);

		if (navbar_style == navbar_default) wprintf(
			"<li class=\"markngo\">"
			"<a href=\"gotonext\" "
			"title=\"%s\">"
			"<img  src=\"static/markngo_24x.gif\" alt=\"\">"
			"<span class=\"navbar_link\">%s</span></a>"
			"</li>\n",
			_("Mark all messages as read, go to next room with unread messages"),
			_("Goto next room")
		);

		wprintf("</ul></div>\n");
	}

}


/*
 * back end routine to take the session to a new room
 */
int gotoroom(char *gname)
{
	char buf[SIZ];
	static long ls = (-1L);
	int err = 0;

	/* store ungoto information */
	strcpy(WC->ugname, WC->wc_roomname);
	WC->uglsn = ls;

	/** move to the new room */
	serv_printf("GOTO %s", gname);
	serv_getln(buf, sizeof buf);
	if (buf[0] != '2') {
		buf[3] = 0;
		err = atoi(buf);
		serv_puts("GOTO _BASEROOM_");
		serv_getln(buf, sizeof buf);
	}
	if (buf[0] != '2') {
		buf[3] = 0;
		err = atoi(buf);
		return err;
	}
	extract_token(WC->wc_roomname, &buf[4], 0, '|', sizeof WC->wc_roomname);
	WC->room_flags = extract_int(&buf[4], 4);
	/* highest_msg_read = extract_int(&buf[4],6);
	   maxmsgnum = extract_int(&buf[4],5);
	 */
	WC->is_mailbox = extract_int(&buf[4],7);
	ls = extract_long(&buf[4], 6);
	WC->wc_floor = extract_int(&buf[4], 10);
	WC->wc_view = extract_int(&buf[4], 11);
	WC->wc_default_view = extract_int(&buf[4], 12);
	WC->wc_is_trash = extract_int(&buf[4], 13);
	WC->room_flags2 = extract_int(&buf[4], 14);

	if (WC->is_aide)
		WC->is_room_aide = WC->is_aide;
	else
		WC->is_room_aide = (char) extract_int(&buf[4], 8);

	remove_march(WC->wc_roomname);
	if (!strcasecmp(gname, "_BASEROOM_"))
		remove_march(gname);

	return err;
}


/**
 * \brief Locate the room on the march list which we most want to go to.  
 * Each room
 * is measured given a "weight" of preference based on various factors.
 * \param desired_floor the room number on the citadel server
 * \return the roomname
 */
char *pop_march(int desired_floor)
{
	static char TheRoom[128];
	int TheFloor = 0;
	int TheOrder = 32767;
	int TheWeight = 0;
	int weight;
	struct march *mptr = NULL;

	strcpy(TheRoom, "_BASEROOM_");
	if (WC->march == NULL)
		return (TheRoom);

	for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
		weight = 0;
		if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
			weight = weight + 10000;
		if (mptr->march_floor == desired_floor)
			weight = weight + 5000;

		weight = weight + ((128 - (mptr->march_floor)) * 128);
		weight = weight + (128 - (mptr->march_order));

		if (weight > TheWeight) {
			TheWeight = weight;
			strcpy(TheRoom, mptr->march_name);
			TheFloor = mptr->march_floor;
			TheOrder = mptr->march_order;
		}
	}
	return (TheRoom);
}



/*
 * Goto next room having unread messages.
 *
 * We want to skip over rooms that the user has already been to, and take the
 * user back to the lobby when done.  The room we end up in is placed in
 * newroom - which is set to 0 (the lobby) initially.
 * We start the search in the current room rather than the beginning to prevent
 * two or more concurrent users from dragging each other back to the same room.
 */
void gotonext(void)
{
	char buf[256];
	struct march *mptr = NULL;
	struct march *mptr2 = NULL;
	char room_name[128];
	char next_room[128];
	int ELoop = 0;

	/*
	 * First check to see if the march-mode list is already allocated.
	 * If it is, pop the first room off the list and go there.
	 */

	if (WC->march == NULL) {
		serv_puts("LKRN");
		serv_getln(buf, sizeof buf);
		if (buf[0] == '1')
			while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
				if (IsEmptyStr(buf)) {
					if (ELoop > 10000)
						return;
					if (ELoop % 100 == 0)
						sleeeeeeeeeep(1);
					ELoop ++;
					continue;					
				}
				extract_token(room_name, buf, 0, '|', sizeof room_name);
				if (strcasecmp(room_name, WC->wc_roomname)) {
					mptr = (struct march *) malloc(sizeof(struct march));
					mptr->next = NULL;
					safestrncpy(mptr->march_name, room_name, sizeof mptr->march_name);
					mptr->march_floor = extract_int(buf, 2);
					mptr->march_order = extract_int(buf, 3);
					if (WC->march == NULL) 
						WC->march = mptr;
					else 
						mptr2->next = mptr;
					mptr2 = mptr;
				}
				buf[0] = '\0';
			}
		/*
		 * add _BASEROOM_ to the end of the march list, so the user will end up
		 * in the system base room (usually the Lobby>) at the end of the loop
		 */
		mptr = (struct march *) malloc(sizeof(struct march));
		mptr->next = NULL;
		mptr->march_order = 0;
	    	mptr->march_floor = 0;
		strcpy(mptr->march_name, "_BASEROOM_");
		if (WC->march == NULL) {
			WC->march = mptr;
		} else {
			mptr2 = WC->march;
			while (mptr2->next != NULL)
				mptr2 = mptr2->next;
			mptr2->next = mptr;
		}
		/*
		 * ...and remove the room we're currently in, so a <G>oto doesn't make us
		 * walk around in circles
		 */
		remove_march(WC->wc_roomname);
	}
	if (WC->march != NULL) {
		strcpy(next_room, pop_march(-1));
	} else {
		strcpy(next_room, "_BASEROOM_");
	}


	smart_goto(next_room);
}


/*
 * goto next room
 */
void smart_goto(char *next_room) {
	gotoroom(next_room);
	readloop("readnew");
}



/*
 * mark all messages in current room as having been read
 */
void slrp_highest(void)
{
	char buf[256];

	serv_puts("SLRP HIGHEST");
	serv_getln(buf, sizeof buf);
}


/*
 * un-goto the previous room
 */
void ungoto(void)
{
	char buf[SIZ];

	if (!strcmp(WC->ugname, "")) {
		smart_goto(WC->wc_roomname);
		return;
	}
	serv_printf("GOTO %s", WC->ugname);
	serv_getln(buf, sizeof buf);
	if (buf[0] != '2') {
		smart_goto(WC->wc_roomname);
		return;
	}
	if (WC->uglsn >= 0L) {
		serv_printf("SLRP %ld", WC->uglsn);
		serv_getln(buf, sizeof buf);
	}
	strcpy(buf, WC->ugname);
	strcpy(WC->ugname, "");
	smart_goto(buf);
}

typedef struct __room_states {
	char password[SIZ];
	char dirname[SIZ];
	char name[SIZ];
	int flags;
	int floor;
	int order;
	int view;
	int flags2;
} room_states;




/*
 * Set/clear/read the "self-service list subscribe" flag for a room
 * 
 * set newval to 0 to clear, 1 to set, any other value to leave unchanged.
 * returns the new value.
 */

int self_service(int newval) {
	int current_value = 0;
	char buf[SIZ];
	
	char name[SIZ];
	char password[SIZ];
	char dirname[SIZ];
        int flags, floor, order, view, flags2;

	serv_puts("GETR");
	serv_getln(buf, sizeof buf);
	if (buf[0] != '2') return(0);

	extract_token(name, &buf[4], 0, '|', sizeof name);
	extract_token(password, &buf[4], 1, '|', sizeof password);
	extract_token(dirname, &buf[4], 2, '|', sizeof dirname);
	flags = extract_int(&buf[4], 3);
	floor = extract_int(&buf[4], 4);
	order = extract_int(&buf[4], 5);
	view = extract_int(&buf[4], 6);
	flags2 = extract_int(&buf[4], 7);

	if (flags2 & QR2_SELFLIST) {
		current_value = 1;
	}
	else {
		current_value = 0;
	}

	if (newval == 1) {
		flags2 = flags2 | QR2_SELFLIST;
	}
	else if (newval == 0) {
		flags2 = flags2 & ~QR2_SELFLIST;
	}
	else {
		return(current_value);
	}

	if (newval != current_value) {
		serv_printf("SETR %s|%s|%s|%d|0|%d|%d|%d|%d",
			name, password, dirname, flags,
			floor, order, view, flags2);
		serv_getln(buf, sizeof buf);
	}

	return(newval);

}

int is_selflist(room_states *RoomFlags)
{
	return ((RoomFlags->flags2 & QR2_SELFLIST) != 0);
}

int is_publiclist(room_states *RoomFlags)
{
	return ((RoomFlags->flags2 & QR2_SMTP_PUBLIC) != 0);
}

int is_moderatedlist(room_states *RoomFlags)
{
	return ((RoomFlags->flags2 & QR2_MODERATED) != 0);
}

/*
 * Set/clear/read the "self-service list subscribe" flag for a room
 * 
 * set newval to 0 to clear, 1 to set, any other value to leave unchanged.
 * returns the new value.
 */

int get_roomflags(room_states *RoomOps) 
{
	char buf[SIZ];
	
	serv_puts("GETR");
	serv_getln(buf, sizeof buf);
	if (buf[0] != '2') return(0);

	extract_token(RoomOps->name, &buf[4], 0, '|', sizeof RoomOps->name);
	extract_token(RoomOps->password, &buf[4], 1, '|', sizeof RoomOps->password);
	extract_token(RoomOps->dirname, &buf[4], 2, '|', sizeof RoomOps->dirname);
	RoomOps->flags = extract_int(&buf[4], 3);
	RoomOps->floor = extract_int(&buf[4], 4);
	RoomOps->order = extract_int(&buf[4], 5);
	RoomOps->view = extract_int(&buf[4], 6);
	RoomOps->flags2 = extract_int(&buf[4], 7);
	return (1);
}

int set_roomflags(room_states *RoomOps)
{
	char buf[SIZ];

	serv_printf("SETR %s|%s|%s|%d|0|%d|%d|%d|%d",
		    RoomOps->name, 
		    RoomOps->password, 
		    RoomOps->dirname, 
		    RoomOps->flags,
		    RoomOps->floor, 
		    RoomOps->order, 
		    RoomOps->view, 
		    RoomOps->flags2);
	serv_getln(buf, sizeof buf);
	return (1);
}






/*
 * display the form for editing a room
 */
void display_editroom(void)
{
	char buf[SIZ];
	char cmd[1024];
	char node[256];
	char remote_room[128];
	char recp[1024];
	char er_name[128];
	char er_password[10];
	char er_dirname[15];
	char er_roomaide[26];
	unsigned er_flags;
	unsigned er_flags2;
	int er_floor;
	int i, j;
	char *tab;
	char *shared_with;
	char *not_shared_with;
	int roompolicy = 0;
	int roomvalue = 0;
	int floorpolicy = 0;
	int floorvalue = 0;
	char pop3_host[128];
	char pop3_user[32];
	int bg = 0;

	tab = bstr("tab");
	if (IsEmptyStr(tab)) tab = "admin";

	load_floorlist();
	output_headers(1, 1, 1, 0, 0, 0);

	wprintf("<div class=\"fix_scrollbar_bug\">");

	/** print the tabbed dialog */
	wprintf("<ul class=\"tabbed_dialog\">\n");

	wprintf("<li class=\"tablabel ");
	if (!strcmp(tab, "admin")) {
		wprintf(" tab_cell_label\">");
		wprintf(_("Administration"));
	}
	else {
		wprintf("< tab_cell_edit\"><a href=\"display_editroom&tab=admin\">");
		wprintf(_("Administration"));
		wprintf("</a>");
	}
	wprintf("</li>\n");

	if ( (WC->axlevel >= 6) || (WC->is_room_aide) ) {

		wprintf("<li class=\"tablabel ");
		if (!strcmp(tab, "config")) {
			wprintf(" tab_cell_label\">");
			wprintf(_("Configuration"));
		}
		else {
			wprintf(" tab_cell_edit\"><a href=\"display_editroom&tab=config\">");
			wprintf(_("Configuration"));
			wprintf("</a>");
		}
		wprintf("</li>\n");

		wprintf("<li class=\"tablabel ");
		if (!strcmp(tab, "expire")) {
			wprintf(" tab_cell_label\">");
			wprintf(_("Message expire policy"));
		}
		else {
			wprintf(" tab_cell_edit\"><a href=\"display_editroom&tab=expire\">");
			wprintf(_("Message expire policy"));
			wprintf("</a>");
		}
		wprintf("</li>\n");
	
		wprintf("<li class=\"tablabel ");
		if (!strcmp(tab, "access")) {
			wprintf(" tab_cell_label\">");
			wprintf(_("Access controls"));
		}
		else {
			wprintf(" tab_cell_edit\"><a href=\"display_editroom&tab=access\">");
			wprintf(_("Access controls"));
			wprintf("</a>");
		}
		wprintf("</li>\n");

		wprintf("<li class=\"tablabel ");
		if (!strcmp(tab, "sharing")) {
			wprintf(" tab_cell_label\">");
			wprintf(_("Sharing"));
		}
		else {
			wprintf(" tab_cell_edit\"><a href=\"display_editroom&tab=sharing\">");
			wprintf(_("Sharing"));
			wprintf("</a>");
		}
		wprintf("</li>\n");

		wprintf("<li class=\"tablabel ");
		if (!strcmp(tab, "listserv")) {
			wprintf(" tab_cell_label\">");
			wprintf(_("Mailing list service"));
		}
		else {
			wprintf("< tab_cell_edit\"><a href=\"display_editroom&tab=listserv\">");
			wprintf(_("Mailing list service"));
			wprintf("</a>");
		}
		wprintf("</li>\n");

	}

	wprintf("<li class=\"tablabel ");
	if (!strcmp(tab, "feeds")) {
		wprintf(" tab_cell_label\">");
		wprintf(_("Remote retrieval"));
	}
	else {
		wprintf("< tab_cell_edit\"><a href=\"display_editroom&tab=feeds\">");
		wprintf(_("Remote retrieval"));
		wprintf("</a>");
	}
	wprintf("</li>\n");

	wprintf("</ul>\n");
	/* end tabbed dialog */	

	/* begin content of whatever tab is open now */

	if (!strcmp(tab, "admin")) {
		wprintf("<div class=\"tabcontent\">");
		wprintf("<ul>"
			"<li><a href=\"delete_room\" "
			"onClick=\"return confirm('");
		wprintf(_("Are you sure you want to delete this room?"));
		wprintf("');\">\n");
		wprintf(_("Delete this room"));
		wprintf("</a>\n"
			"<li><a href=\"display_editroompic\">\n");
		wprintf(_("Set or change the icon for this room's banner"));
		wprintf("</a>\n"
			"<li><a href=\"display_editinfo\">\n");
		wprintf(_("Edit this room's Info file"));
		wprintf("</a>\n"
			"</ul>");
		wprintf("</div>");
	}

	if (!strcmp(tab, "config")) {
		wprintf("<div class=\"tabcontent\">");
		serv_puts("GETR");
		serv_getln(buf, sizeof buf);

		if (!strncmp(buf, "550", 3)) {
			wprintf("<br><br><div align=center>%s</div><br><br>\n",
				_("Higher access is required to access this function.")
			);
		}
		else if (buf[0] != '2') {
			wprintf("<br><br><div align=center>%s</div><br><br>\n", &buf[4]);
		}
		else {
			extract_token(er_name, &buf[4], 0, '|', sizeof er_name);
			extract_token(er_password, &buf[4], 1, '|', sizeof er_password);
			extract_token(er_dirname, &buf[4], 2, '|', sizeof er_dirname);
			er_flags = extract_int(&buf[4], 3);
			er_floor = extract_int(&buf[4], 4);
			er_flags2 = extract_int(&buf[4], 7);
	
			wprintf("<form method=\"POST\" action=\"editroom\">\n");
			wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
		
			wprintf("<ul><li>");
			wprintf(_("Name of room: "));
			wprintf("<input type=\"text\" NAME=\"er_name\" VALUE=\"%s\" MAXLENGTH=\"%d\">\n",
				er_name,
				(sizeof(er_name)-1)
			);
		
			wprintf("<li>");
			wprintf(_("Resides on floor: "));
			wprintf("<select NAME=\"er_floor\" SIZE=\"1\"");
			if (er_flags & QR_MAILBOX)
				wprintf("disabled >\n");
			for (i = 0; i < 128; ++i)
				if (!IsEmptyStr(floorlist[i])) {
					wprintf("<OPTION ");
					if (i == er_floor )
						wprintf("SELECTED ");
					wprintf("VALUE=\"%d\">", i);
					escputs(floorlist[i]);
					wprintf("</OPTION>\n");
				}
			wprintf("</select>\n");

			wprintf("<li>");
			wprintf(_("Type of room:"));
			wprintf("<ul>\n");
	
			wprintf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"public\" ");
			if ((er_flags & (QR_PRIVATE + QR_MAILBOX)) == 0)
				wprintf("CHECKED ");
			wprintf("OnChange=\""
				"	if (this.form.type[0].checked == true) {	"
				"		this.form.er_floor.disabled = false;	"
				"	}						"
				"\"> ");
			wprintf(_("Public (automatically appears to everyone)"));
			wprintf("\n");
	
			wprintf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"hidden\" ");
			if ((er_flags & QR_PRIVATE) &&
		    	(er_flags & QR_GUESSNAME))
				wprintf("CHECKED ");
			wprintf(" OnChange=\""
				"	if (this.form.type[1].checked == true) {	"
				"		this.form.er_floor.disabled = false;	"
				"	}						"
				"\"> ");
			wprintf(_("Private - hidden (accessible to anyone who knows its name)"));
		
			wprintf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
			if ((er_flags & QR_PRIVATE) &&
		    	(er_flags & QR_PASSWORDED))
				wprintf("CHECKED ");
			wprintf(" OnChange=\""
				"	if (this.form.type[2].checked == true) {	"
				"		this.form.er_floor.disabled = false;	"
				"	}						"
				"\"> ");
			wprintf(_("Private - require password: "));
			wprintf("\n<input type=\"text\" NAME=\"er_password\" VALUE=\"%s\" MAXLENGTH=\"9\">\n",
				er_password);
		
			wprintf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
			if ((er_flags & QR_PRIVATE)
		    	&& ((er_flags & QR_GUESSNAME) == 0)
		    	&& ((er_flags & QR_PASSWORDED) == 0))
				wprintf("CHECKED ");
			wprintf(" OnChange=\""
				"	if (this.form.type[3].checked == true) {	"
				"		this.form.er_floor.disabled = false;	"
				"	}						"
				"\"> ");
			wprintf(_("Private - invitation only"));
		
			wprintf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"personal\" ");
			if (er_flags & QR_MAILBOX)
				wprintf("CHECKED ");
			wprintf (" OnChange=\""
				"	if (this.form.type[4].checked == true) {	"
				"		this.form.er_floor.disabled = true;	"
				"	}						"
				"\"> ");
			wprintf(_("Personal (mailbox for you only)"));
			
			wprintf("\n<li><input type=\"checkbox\" NAME=\"bump\" VALUE=\"yes\" ");
			wprintf("> ");
			wprintf(_("If private, cause current users to forget room"));
		
			wprintf("\n</ul>\n");
		
			wprintf("<li><input type=\"checkbox\" NAME=\"prefonly\" VALUE=\"yes\" ");
			if (er_flags & QR_PREFONLY)
				wprintf("CHECKED ");
			wprintf("> ");
			wprintf(_("Preferred users only"));
		
			wprintf("\n<li><input type=\"checkbox\" NAME=\"readonly\" VALUE=\"yes\" ");
			if (er_flags & QR_READONLY)
				wprintf("CHECKED ");
			wprintf("> ");
			wprintf(_("Read-only room"));
		
			wprintf("\n<li><input type=\"checkbox\" NAME=\"collabdel\" VALUE=\"yes\" ");
			if (er_flags2 & QR2_COLLABDEL)
				wprintf("CHECKED ");
			wprintf("> ");
			wprintf(_("All users allowed to post may also delete messages"));
		
			/** directory stuff */
			wprintf("\n<li><input type=\"checkbox\" NAME=\"directory\" VALUE=\"yes\" ");
			if (er_flags & QR_DIRECTORY)
				wprintf("CHECKED ");
			wprintf("> ");
			wprintf(_("File directory room"));
	
			wprintf("\n<ul><li>");
			wprintf(_("Directory name: "));
			wprintf("<input type=\"text\" NAME=\"er_dirname\" VALUE=\"%s\" MAXLENGTH=\"14\">\n",
				er_dirname);
	
			wprintf("<li><input type=\"checkbox\" NAME=\"ulallowed\" VALUE=\"yes\" ");
			if (er_flags & QR_UPLOAD)
			wprintf("CHECKED ");
			wprintf("> ");
			wprintf(_("Uploading allowed"));
		
			wprintf("\n<li><input type=\"checkbox\" NAME=\"dlallowed\" VALUE=\"yes\" ");
			if (er_flags & QR_DOWNLOAD)
				wprintf("CHECKED ");
			wprintf("> ");
			wprintf(_("Downloading allowed"));
		
			wprintf("\n<li><input type=\"checkbox\" NAME=\"visdir\" VALUE=\"yes\" ");
			if (er_flags & QR_VISDIR)
				wprintf("CHECKED ");
			wprintf("> ");
			wprintf(_("Visible directory"));
			wprintf("</ul>\n");
		
			/** end of directory stuff */
	
			wprintf("<li><input type=\"checkbox\" NAME=\"network\" VALUE=\"yes\" ");
			if (er_flags & QR_NETWORK)
				wprintf("CHECKED ");
			wprintf("> ");
			wprintf(_("Network shared room"));
	
			wprintf("\n<li><input type=\"checkbox\" NAME=\"permanent\" VALUE=\"yes\" ");
			if (er_flags & QR_PERMANENT)
				wprintf("CHECKED ");
			wprintf("> ");
			wprintf(_("Permanent (does not auto-purge)"));
	
			wprintf("\n<li><input type=\"checkbox\" NAME=\"subjectreq\" VALUE=\"yes\" ");
			if (er_flags2 & QR2_SUBJECTREQ)
				wprintf("CHECKED ");
			wprintf("> ");
			wprintf(_("Subject Required (Force users to specify a message subject)"));
	
			/** start of anon options */
		
			wprintf("\n<li>");
			wprintf(_("Anonymous messages"));
			wprintf("<ul>\n");
		
			wprintf("<li><input type=\"radio\" NAME=\"anon\" VALUE=\"no\" ");
			if (((er_flags & QR_ANONONLY) == 0)
		    	&& ((er_flags & QR_ANONOPT) == 0))
				wprintf("CHECKED ");
			wprintf("> ");
			wprintf(_("No anonymous messages"));
	
			wprintf("\n<li><input type=\"radio\" NAME=\"anon\" VALUE=\"anononly\" ");
			if (er_flags & QR_ANONONLY)
				wprintf("CHECKED ");
			wprintf("> ");
			wprintf(_("All messages are anonymous"));
		
			wprintf("\n<li><input type=\"radio\" NAME=\"anon\" VALUE=\"anon2\" ");
			if (er_flags & QR_ANONOPT)
				wprintf("CHECKED ");
			wprintf("> ");
			wprintf(_("Prompt user when entering messages"));
			wprintf("</ul>\n");
		
		/* end of anon options */
		
			wprintf("<li>");
			wprintf(_("Room aide: "));
			serv_puts("GETA");
			serv_getln(buf, sizeof buf);
			if (buf[0] != '2') {
				wprintf("<em>%s</em>\n", &buf[4]);
			} else {
				extract_token(er_roomaide, &buf[4], 0, '|', sizeof er_roomaide);
				wprintf("<input type=\"text\" NAME=\"er_roomaide\" VALUE=\"%s\" MAXLENGTH=\"25\">\n", er_roomaide);
			}
		
			wprintf("</ul><CENTER>\n");
			wprintf("<input type=\"hidden\" NAME=\"tab\" VALUE=\"config\">\n"
				"<input type=\"submit\" NAME=\"ok_button\" VALUE=\"%s\">"
				"&nbsp;"
				"<input type=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">"
				"</CENTER>\n",
				_("Save changes"),
				_("Cancel")
			);
		}
		wprintf("</div>");
	}


	/* Sharing the room with other Citadel nodes... */
	if (!strcmp(tab, "sharing")) {
		wprintf("<div class=\"tabcontent\">");

		shared_with = strdup("");
		not_shared_with = strdup("");

		/** Learn the current configuration */
		serv_puts("CONF getsys|application/x-citadel-ignet-config");
		serv_getln(buf, sizeof buf);
		if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
			extract_token(node, buf, 0, '|', sizeof node);
			not_shared_with = realloc(not_shared_with,
					strlen(not_shared_with) + 32);
			strcat(not_shared_with, node);
			strcat(not_shared_with, "\n");
		}

		serv_puts("GNET");
		serv_getln(buf, sizeof buf);
		if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
			extract_token(cmd, buf, 0, '|', sizeof cmd);
			extract_token(node, buf, 1, '|', sizeof node);
			extract_token(remote_room, buf, 2, '|', sizeof remote_room);
			if (!strcasecmp(cmd, "ignet_push_share")) {
				shared_with = realloc(shared_with,
						strlen(shared_with) + 32);
				strcat(shared_with, node);
				if (!IsEmptyStr(remote_room)) {
					strcat(shared_with, "|");
					strcat(shared_with, remote_room);
				}
				strcat(shared_with, "\n");
			}
		}

		for (i=0; i<num_tokens(shared_with, '\n'); ++i) {
			extract_token(buf, shared_with, i, '\n', sizeof buf);
			extract_token(node, buf, 0, '|', sizeof node);
			for (j=0; j<num_tokens(not_shared_with, '\n'); ++j) {
				extract_token(cmd, not_shared_with, j, '\n', sizeof cmd);
				if (!strcasecmp(node, cmd)) {
					remove_token(not_shared_with, j, '\n');
				}
			}
		}

		/* Display the stuff */
		wprintf("<CENTER><br />"
			"<table border=1 cellpadding=5><tr>"
			"<td><B><I>");
		wprintf(_("Shared with"));
		wprintf("</I></B></td>"
			"<td><B><I>");
		wprintf(_("Not shared with"));
		wprintf("</I></B></td></tr>\n"
			"<tr><td VALIGN=TOP>\n");

		wprintf("<table border=0 cellpadding=5><tr class=\"tab_cell\"><td>");
		wprintf(_("Remote node name"));
		wprintf("</td><td>");
		wprintf(_("Remote room name"));
		wprintf("</td><td>");
		wprintf(_("Actions"));
		wprintf("</td></tr>\n");

		for (i=0; i<num_tokens(shared_with, '\n'); ++i) {
			extract_token(buf, shared_with, i, '\n', sizeof buf);
			extract_token(node, buf, 0, '|', sizeof node);
			extract_token(remote_room, buf, 1, '|', sizeof remote_room);
			if (!IsEmptyStr(node)) {
				wprintf("<form method=\"POST\" action=\"netedit\">");
				wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
				wprintf("<tr><td>%s</td>\n", node);

				wprintf("<td>");
				if (!IsEmptyStr(remote_room)) {
					escputs(remote_room);
				}
				wprintf("</td>");

				wprintf("<td>");
		
				wprintf("<input type=\"hidden\" NAME=\"line\" "
					"VALUE=\"ignet_push_share|");
				urlescputs(node);
				if (!IsEmptyStr(remote_room)) {
					wprintf("|");
					urlescputs(remote_room);
				}
				wprintf("\">");
				wprintf("<input type=\"hidden\" NAME=\"tab\" VALUE=\"sharing\">\n");
				wprintf("<input type=\"hidden\" NAME=\"cmd\" VALUE=\"remove\">\n");
				wprintf("<input type=\"submit\" "
					"NAME=\"unshare_button\" VALUE=\"%s\">", _("Unshare"));
				wprintf("</td></tr></form>\n");
			}
		}

		wprintf("</table>\n");
		wprintf("</td><td VALIGN=TOP>\n");
		wprintf("<table border=0 cellpadding=5><tr class=\"tab_cell\"><td>");
		wprintf(_("Remote node name"));
		wprintf("</td><td>");
		wprintf(_("Remote room name"));
		wprintf("</td><td>");
		wprintf(_("Actions"));
		wprintf("</td></tr>\n");

		for (i=0; i<num_tokens(not_shared_with, '\n'); ++i) {
			extract_token(node, not_shared_with, i, '\n', sizeof node);
			if (!IsEmptyStr(node)) {
				wprintf("<form method=\"POST\" action=\"netedit\">");
				wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
				wprintf("<tr><td>");
				escputs(node);
				wprintf("</td><td>"
					"<input type=\"INPUT\" "
					"NAME=\"suffix\" "
					"MAXLENGTH=128>"
					"</td><td>");
				wprintf("<input type=\"hidden\" "
					"NAME=\"line\" "
					"VALUE=\"ignet_push_share|");
				urlescputs(node);
				wprintf("|\">");
				wprintf("<input type=\"hidden\" NAME=\"tab\" "
					"VALUE=\"sharing\">\n");
				wprintf("<input type=\"hidden\" NAME=\"cmd\" "
					"VALUE=\"add\">\n");
				wprintf("<input type=\"submit\" "
					"NAME=\"add_button\" VALUE=\"%s\">", _("Share"));
				wprintf("</td></tr></form>\n");
			}
		}

		wprintf("</table>\n");
		wprintf("</td></tr>"
			"</table></CENTER><br />\n"
			"<I><B>%s</B><ul><li>", _("Notes:"));
		wprintf(_("When sharing a room, "
			"it must be shared from both ends.  Adding a node to "
			"the 'shared' list sends messages out, but in order to"
			" receive messages, the other nodes must be configured"
			" to send messages out to your system as well. "
			"<li>If the remote room name is blank, it is assumed "
			"that the room name is identical on the remote node."
			"<li>If the remote room name is different, the remote "
			"node must also configure the name of the room here."
			"</ul></I><br />\n"
		));

		wprintf("</div>");
	}

	/* Mailing list management */
	if (!strcmp(tab, "listserv")) {
		room_states RoomFlags;
		wprintf("<div class=\"tabcontent\">");

		wprintf("<br /><center>"
			"<table BORDER=0 WIDTH=100%% CELLPADDING=5>"
			"<tr><td VALIGN=TOP>");

		wprintf(_("<i>The contents of this room are being "
			"mailed <b>as individual messages</b> "
			"to the following list recipients:"
			"</i><br /><br />\n"));

		serv_puts("GNET");
		serv_getln(buf, sizeof buf);
		if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
			extract_token(cmd, buf, 0, '|', sizeof cmd);
			if (!strcasecmp(cmd, "listrecp")) {
				extract_token(recp, buf, 1, '|', sizeof recp);
			
				escputs(recp);
				wprintf(" <a href=\"netedit&cmd=remove&tab=listserv&line=listrecp|");
				urlescputs(recp);
				wprintf("\">");
				wprintf(_("(remove)"));
				wprintf("</A><br />");
			}
		}
		wprintf("<br /><form method=\"POST\" action=\"netedit\">\n"
			"<input type=\"hidden\" NAME=\"tab\" VALUE=\"listserv\">\n"
			"<input type=\"hidden\" NAME=\"prefix\" VALUE=\"listrecp|\">\n");
		wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
		wprintf("<input type=\"text\" id=\"add_as_listrecp\" NAME=\"line\">\n");
		wprintf("<input type=\"submit\" NAME=\"add_button\" VALUE=\"%s\">", _("Add"));
		wprintf("</form>\n");

		wprintf("</td><td VALIGN=TOP>\n");
		
		wprintf(_("<i>The contents of this room are being "
			"mailed <b>in digest form</b> "
			"to the following list recipients:"
			"</i><br /><br />\n"));

		serv_puts("GNET");
		serv_getln(buf, sizeof buf);
		if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
			extract_token(cmd, buf, 0, '|', sizeof cmd);
			if (!strcasecmp(cmd, "digestrecp")) {
				extract_token(recp, buf, 1, '|', sizeof recp);
			
				escputs(recp);
				wprintf(" <a href=\"netedit&cmd=remove&tab=listserv&line="
					"digestrecp|");
				urlescputs(recp);
				wprintf("\">");
				wprintf(_("(remove)"));
				wprintf("</A><br />");
			}
		}
		wprintf("<br /><form method=\"POST\" action=\"netedit\">\n"
			"<input type=\"hidden\" NAME=\"tab\" VALUE=\"listserv\">\n"
			"<input type=\"hidden\" NAME=\"prefix\" VALUE=\"digestrecp|\">\n");
		wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
		wprintf("<input type=\"text\" id=\"add_as_digestrecp\" NAME=\"line\">\n");
		wprintf("<input type=\"submit\" NAME=\"add_button\" VALUE=\"%s\">", _("Add"));
		wprintf("</form>\n");
		
		wprintf("</td></tr></table>\n");

		/** Pop open an address book -- begin **/
		wprintf("<div align=right>"
			"<a href=\"javascript:PopOpenAddressBook('add_as_listrecp|%s|add_as_digestrecp|%s');\" "
			"title=\"%s\">"
			"<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
			"&nbsp;%s</a>"
			"</div>",
			_("List"),
			_("Digest"),
			_("Add recipients from Contacts or other address books"),
			_("Add recipients from Contacts or other address books")
		);
		/* Pop open an address book -- end **/

		wprintf("<br />\n<form method=\"GET\" action=\"toggle_self_service\">\n");

		get_roomflags (&RoomFlags);
		
		/* Self Service subscription? */
		wprintf("<table><tr><td>\n");
		wprintf(_("Allow self-service subscribe/unsubscribe requests."));
		wprintf("</td><td><input type=\"checkbox\" name=\"QR2_SelfList\" value=\"yes\" %s></td></tr>\n"
			" <tr><td colspan=\"2\">\n",
			(is_selflist(&RoomFlags))?"checked":"");
		wprintf(_("The URL for subscribe/unsubscribe is: "));
		wprintf("<TT>%s://%s/listsub</TT></td></tr>\n",
			(is_https ? "https" : "http"),
			WC->http_host);
		/* Public posting? */
		wprintf("<tr><td>");
		wprintf(_("Allow non-subscribers to mail to this room."));
		wprintf("</td><td><input type=\"checkbox\" name=\"QR2_SubsOnly\" value=\"yes\" %s></td></tr>\n",
			(is_publiclist(&RoomFlags))?"checked":"");
		
		/* Moderated List? */
		wprintf("<tr><td>");
		wprintf(_("Room post publication needs Aide permission."));
		wprintf("</td><td><input type=\"checkbox\" name=\"QR2_Moderated\" value=\"yes\" %s></td></tr>\n",
			(is_moderatedlist(&RoomFlags))?"checked":"");


		wprintf("<tr><td colspan=\"2\" align=\"center\">"
			"<input type=\"submit\" NAME=\"add_button\" VALUE=\"%s\"></td></tr>", _("Save changes"));
		wprintf("</table></form>");
			

		wprintf("</CENTER>\n");
		wprintf("</div>");
	}


	/* Configuration of The Dreaded Auto-Purger */
	if (!strcmp(tab, "expire")) {
		wprintf("<div class=\"tabcontent\">");

		serv_puts("GPEX room");
		serv_getln(buf, sizeof buf);
		if (!strncmp(buf, "550", 3)) {
			wprintf("<br><br><div align=center>%s</div><br><br>\n",
				_("Higher access is required to access this function.")
			);
		}
		else if (buf[0] != '2') {
			wprintf("<br><br><div align=center>%s</div><br><br>\n", &buf[4]);
		}
		else {
			roompolicy = extract_int(&buf[4], 0);
			roomvalue = extract_int(&buf[4], 1);
		
			serv_puts("GPEX floor");
			serv_getln(buf, sizeof buf);
			if (buf[0] == '2') {
				floorpolicy = extract_int(&buf[4], 0);
				floorvalue = extract_int(&buf[4], 1);
			}
			
			wprintf("<br /><form method=\"POST\" action=\"set_room_policy\">\n");
			wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
			wprintf("<table border=0 cellspacing=5>\n");
			wprintf("<tr><td>");
			wprintf(_("Message expire policy for this room"));
			wprintf("<br />(");
			escputs(WC->wc_roomname);
			wprintf(")</td><td>");
			wprintf("<input type=\"radio\" NAME=\"roompolicy\" VALUE=\"0\" %s>",
				((roompolicy == 0) ? "CHECKED" : "") );
			wprintf(_("Use the default policy for this floor"));
			wprintf("<br />\n");
			wprintf("<input type=\"radio\" NAME=\"roompolicy\" VALUE=\"1\" %s>",
				((roompolicy == 1) ? "CHECKED" : "") );
			wprintf(_("Never automatically expire messages"));
			wprintf("<br />\n");
			wprintf("<input type=\"radio\" NAME=\"roompolicy\" VALUE=\"2\" %s>",
				((roompolicy == 2) ? "CHECKED" : "") );
			wprintf(_("Expire by message count"));
			wprintf("<br />\n");
			wprintf("<input type=\"radio\" NAME=\"roompolicy\" VALUE=\"3\" %s>",
				((roompolicy == 3) ? "CHECKED" : "") );
			wprintf(_("Expire by message age"));
			wprintf("<br />");
			wprintf(_("Number of messages or days: "));
			wprintf("<input type=\"text\" NAME=\"roomvalue\" MAXLENGTH=\"5\" VALUE=\"%d\">", roomvalue);
			wprintf("</td></tr>\n");
	
			if (WC->axlevel >= 6) {
				wprintf("<tr><td COLSPAN=2><hr /></td></tr>\n");
				wprintf("<tr><td>");
				wprintf(_("Message expire policy for this floor"));
				wprintf("<br />(");
				escputs(floorlist[WC->wc_floor]);
				wprintf(")</td><td>");
				wprintf("<input type=\"radio\" NAME=\"floorpolicy\" VALUE=\"0\" %s>",
					((floorpolicy == 0) ? "CHECKED" : "") );
				wprintf(_("Use the system default"));
				wprintf("<br />\n");
				wprintf("<input type=\"radio\" NAME=\"floorpolicy\" VALUE=\"1\" %s>",
					((floorpolicy == 1) ? "CHECKED" : "") );
				wprintf(_("Never automatically expire messages"));
				wprintf("<br />\n");
				wprintf("<input type=\"radio\" NAME=\"floorpolicy\" VALUE=\"2\" %s>",
					((floorpolicy == 2) ? "CHECKED" : "") );
				wprintf(_("Expire by message count"));
				wprintf("<br />\n");
				wprintf("<input type=\"radio\" NAME=\"floorpolicy\" VALUE=\"3\" %s>",
					((floorpolicy == 3) ? "CHECKED" : "") );
				wprintf(_("Expire by message age"));
				wprintf("<br />");
				wprintf(_("Number of messages or days: "));
				wprintf("<input type=\"text\" NAME=\"floorvalue\" MAXLENGTH=\"5\" VALUE=\"%d\">",
					floorvalue);
			}
	
			wprintf("<CENTER>\n");
			wprintf("<tr><td COLSPAN=2><hr /><CENTER>\n");
			wprintf("<input type=\"submit\" NAME=\"ok_button\" VALUE=\"%s\">", _("Save changes"));
			wprintf("&nbsp;");
			wprintf("<input type=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
			wprintf("</CENTER></td><tr>\n");
	
			wprintf("</table>\n"
				"<input type=\"hidden\" NAME=\"tab\" VALUE=\"expire\">\n"
				"</form>\n"
			);
		}

		wprintf("</div>");
	}

	/* Access controls */
	if (!strcmp(tab, "access")) {
		wprintf("<div class=\"tabcontent\">");
		display_whok();
		wprintf("</div>");
	}

	/* Fetch messages from remote locations */
	if (!strcmp(tab, "feeds")) {
		wprintf("<div class=\"tabcontent\">");

		wprintf("<i>");
		wprintf(_("Retrieve messages from these remote POP3 accounts and store them in this room:"));
		wprintf("</i><br />\n");

		wprintf("<table class=\"altern\" border=0 cellpadding=5>"
			"<tr class=\"even\"><th>");
		wprintf(_("Remote host"));
		wprintf("</th><th>");
		wprintf(_("User name"));
		wprintf("</th><th>");
		wprintf(_("Password"));
		wprintf("</th><th>");
		wprintf(_("Keep messages on server?"));
		wprintf("</th><th>");
		wprintf(_("Interval"));
		wprintf("</th><th> </th></tr>");

		serv_puts("GNET");
		serv_getln(buf, sizeof buf);
		bg = 1;
		if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
			extract_token(cmd, buf, 0, '|', sizeof cmd);
			if (!strcasecmp(cmd, "pop3client")) {
				safestrncpy(recp, &buf[11], sizeof recp);

                                bg = 1 - bg;
                                wprintf("<tr class=\"%s\">",
                                        (bg ? "even" : "odd")
                                );

				wprintf("<td>");
				extract_token(pop3_host, buf, 1, '|', sizeof pop3_host);
				escputs(pop3_host);
				wprintf("</td>");

				wprintf("<td>");
				extract_token(pop3_user, buf, 2, '|', sizeof pop3_user);
				escputs(pop3_user);
				wprintf("</td>");

				wprintf("<td>*****</td>");		/* Don't show the password */

				wprintf("<td>%s</td>", extract_int(buf, 4) ? _("Yes") : _("No"));

				wprintf("<td>%ld</td>", extract_long(buf, 5));	// Fetching interval
			
				wprintf("<td class=\"button_link\">");
				wprintf(" <a href=\"netedit&cmd=remove&tab=feeds&line=pop3client|");
				urlescputs(recp);
				wprintf("\">");
				wprintf(_("(remove)"));
				wprintf("</a></td>");
			
				wprintf("</tr>");
			}
		}

		wprintf("<form method=\"POST\" action=\"netedit\">\n"
			"<tr>"
			"<input type=\"hidden\" name=\"tab\" value=\"feeds\">"
			"<input type=\"hidden\" name=\"prefix\" value=\"pop3client|\">\n");
		wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
		wprintf("<td>");
		wprintf("<input type=\"text\" id=\"add_as_pop3host\" NAME=\"line_pop3host\">\n");
		wprintf("</td>");
		wprintf("<td>");
		wprintf("<input type=\"text\" id=\"add_as_pop3user\" NAME=\"line_pop3user\">\n");
		wprintf("</td>");
		wprintf("<td>");
		wprintf("<input type=\"password\" id=\"add_as_pop3pass\" NAME=\"line_pop3pass\">\n");
		wprintf("</td>");
		wprintf("<td>");
		wprintf("<input type=\"checkbox\" id=\"add_as_pop3keep\" NAME=\"line_pop3keep\" VALUE=\"1\">");
		wprintf("</td>");
		wprintf("<td>");
		wprintf("<input type=\"text\" id=\"add_as_pop3int\" NAME=\"line_pop3int\" MAXLENGTH=\"5\">");
		wprintf("</td>");
		wprintf("<td>");
		wprintf("<input type=\"submit\" NAME=\"add_button\" VALUE=\"%s\">", _("Add"));
		wprintf("</td></tr>");
		wprintf("</form></table>\n");

		wprintf("<hr>\n");

		wprintf("<i>");
		wprintf(_("Fetch the following RSS feeds and store them in this room:"));
		wprintf("</i><br />\n");

		wprintf("<table class=\"altern\" border=0 cellpadding=5>"
			"<tr class=\"even\"><th>");
		wprintf("<img src=\"static/rss_16x.png\" width=\"16\" height=\"16\" alt=\" \"> ");
		wprintf(_("Feed URL"));
		wprintf("</th><th>");
		wprintf("</th></tr>");

		serv_puts("GNET");
		serv_getln(buf, sizeof buf);
		bg = 1;
		if (buf[0]=='1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
			extract_token(cmd, buf, 0, '|', sizeof cmd);
			if (!strcasecmp(cmd, "rssclient")) {
				safestrncpy(recp, &buf[10], sizeof recp);

                                bg = 1 - bg;
                                wprintf("<tr class=\"%s\">",
                                        (bg ? "even" : "odd")
                                );

				wprintf("<td>");
				extract_token(pop3_host, buf, 1, '|', sizeof pop3_host);
				escputs(pop3_host);
				wprintf("</td>");

				wprintf("<td class=\"button_link\">");
				wprintf(" <a href=\"netedit&cmd=remove&tab=feeds&line=rssclient|");
				urlescputs(recp);
				wprintf("\">");
				wprintf(_("(remove)"));
				wprintf("</a></td>");
			
				wprintf("</tr>");
			}
		}

		wprintf("<form method=\"POST\" action=\"netedit\">\n"
			"<tr>"
			"<input type=\"hidden\" name=\"tab\" value=\"feeds\">"
			"<input type=\"hidden\" name=\"prefix\" value=\"rssclient|\">\n");
		wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
		wprintf("<td>");
		wprintf("<input type=\"text\" id=\"add_as_pop3host\" size=\"72\" "
			"maxlength=\"256\" name=\"line_pop3host\">\n");
		wprintf("</td>");
		wprintf("<td>");
		wprintf("<input type=\"submit\" name=\"add_button\" value=\"%s\">", _("Add"));
		wprintf("</td></tr>");
		wprintf("</form></table>\n");

		wprintf("</div>");
	}


	/* end content of whatever tab is open now */
	wprintf("</div>\n");

	address_book_popup();
	wDumpContent(1);
}


/* 
 * Toggle self-service list subscription
 */
void toggle_self_service(void) {
	room_states RoomFlags;

	get_roomflags (&RoomFlags);

	if (yesbstr("QR2_SelfList")) 
		RoomFlags.flags2 = RoomFlags.flags2 | QR2_SELFLIST;
	else 
		RoomFlags.flags2 = RoomFlags.flags2 & ~QR2_SELFLIST;

	if (yesbstr("QR2_SMTP_PUBLIC")) 
		RoomFlags.flags2 = RoomFlags.flags2 | QR2_SMTP_PUBLIC;
	else
		RoomFlags.flags2 = RoomFlags.flags2 & ~QR2_SMTP_PUBLIC;

	if (yesbstr("QR2_Moderated")) 
		RoomFlags.flags2 = RoomFlags.flags2 | QR2_MODERATED;
	else
		RoomFlags.flags2 = RoomFlags.flags2 & ~QR2_MODERATED;
	if (yesbstr("QR2_SubsOnly")) 
		RoomFlags.flags2 = RoomFlags.flags2 | QR2_SMTP_PUBLIC;
	else
		RoomFlags.flags2 = RoomFlags.flags2 & ~QR2_SMTP_PUBLIC;

	set_roomflags (&RoomFlags);
	
	display_editroom();
}



/*
 * save new parameters for a room
 */
void editroom(void)
{
	char buf[SIZ];
	char er_name[128];
	char er_password[10];
	char er_dirname[15];
	char er_roomaide[26];
	int er_floor;
	unsigned er_flags;
	int er_listingorder;
	int er_defaultview;
	unsigned er_flags2;
	int bump;


	if (!havebstr("ok_button")) {
		strcpy(WC->ImportantMessage,
			_("Cancelled.  Changes were not saved."));
		display_editroom();
		return;
	}
	serv_puts("GETR");
	serv_getln(buf, sizeof buf);

	if (buf[0] != '2') {
		strcpy(WC->ImportantMessage, &buf[4]);
		display_editroom();
		return;
	}
	extract_token(er_name, &buf[4], 0, '|', sizeof er_name);
	extract_token(er_password, &buf[4], 1, '|', sizeof er_password);
	extract_token(er_dirname, &buf[4], 2, '|', sizeof er_dirname);
	er_flags = extract_int(&buf[4], 3);
	er_listingorder = extract_int(&buf[4], 5);
	er_defaultview = extract_int(&buf[4], 6);
	er_flags2 = extract_int(&buf[4], 7);

	strcpy(er_roomaide, bstr("er_roomaide"));
	if (IsEmptyStr(er_roomaide)) {
		serv_puts("GETA");
		serv_getln(buf, sizeof buf);
		if (buf[0] != '2') {
			strcpy(er_roomaide, "");
		} else {
			extract_token(er_roomaide, &buf[4], 0, '|', sizeof er_roomaide);
		}
	}
	strcpy(buf, bstr("er_name"));
	buf[128] = 0;
	if (!IsEmptyStr(buf)) {
		strcpy(er_name, buf);
	}

	strcpy(buf, bstr("er_password"));
	buf[10] = 0;
	if (!IsEmptyStr(buf))
		strcpy(er_password, buf);

	strcpy(buf, bstr("er_dirname"));
	buf[15] = 0;
	if (!IsEmptyStr(buf))
		strcpy(er_dirname, buf);

	strcpy(buf, bstr("type"));
	er_flags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);

	if (!strcmp(buf, "invonly")) {
		er_flags |= (QR_PRIVATE);
	}
	if (!strcmp(buf, "hidden")) {
		er_flags |= (QR_PRIVATE | QR_GUESSNAME);
	}
	if (!strcmp(buf, "passworded")) {
		er_flags |= (QR_PRIVATE | QR_PASSWORDED);
	}
	if (!strcmp(buf, "personal")) {
		er_flags |= QR_MAILBOX;
	} else {
		er_flags &= ~QR_MAILBOX;
	}
	
	if (yesbstr("prefonly")) {
		er_flags |= QR_PREFONLY;
	} else {
		er_flags &= ~QR_PREFONLY;
	}

	if (yesbstr("readonly")) {
		er_flags |= QR_READONLY;
	} else {
		er_flags &= ~QR_READONLY;
	}

	
	if (yesbstr("collabdel")) {
		er_flags2 |= QR2_COLLABDEL;
	} else {
		er_flags2 &= ~QR2_COLLABDEL;
	}

	if (yesbstr("permanent")) {
		er_flags |= QR_PERMANENT;
	} else {
		er_flags &= ~QR_PERMANENT;
	}

	if (yesbstr("subjectreq")) {
		er_flags2 |= QR2_SUBJECTREQ;
	} else {
		er_flags2 &= ~QR2_SUBJECTREQ;
	}

	if (yesbstr("network")) {
		er_flags |= QR_NETWORK;
	} else {
		er_flags &= ~QR_NETWORK;
	}

	if (yesbstr("directory")) {
		er_flags |= QR_DIRECTORY;
	} else {
		er_flags &= ~QR_DIRECTORY;
	}

	if (yesbstr("ulallowed")) {
		er_flags |= QR_UPLOAD;
	} else {
		er_flags &= ~QR_UPLOAD;
	}

	if (yesbstr("dlallowed")) {
		er_flags |= QR_DOWNLOAD;
	} else {
		er_flags &= ~QR_DOWNLOAD;
	}

	if (yesbstr("visdir")) {
		er_flags |= QR_VISDIR;
	} else {
		er_flags &= ~QR_VISDIR;
	}

	strcpy(buf, bstr("anon"));

	er_flags &= ~(QR_ANONONLY | QR_ANONOPT);
	if (!strcmp(buf, "anononly"))
		er_flags |= QR_ANONONLY;
	if (!strcmp(buf, "anon2"))
		er_flags |= QR_ANONOPT;

	bump = 0;
	if (!strcmp(bstr("bump"), "yes"))
		bump = 1;

	er_floor = ibstr("er_floor");

	sprintf(buf, "SETR %s|%s|%s|%u|%d|%d|%d|%d|%u",
		er_name, er_password, er_dirname, er_flags, bump, er_floor,
		er_listingorder, er_defaultview, er_flags2);
	serv_puts(buf);
	serv_getln(buf, sizeof buf);
	if (buf[0] != '2') {
		strcpy(WC->ImportantMessage, &buf[4]);
		display_editroom();
		return;
	}
	gotoroom(er_name);

	if (!IsEmptyStr(er_roomaide)) {
		sprintf(buf, "SETA %s", er_roomaide);
		serv_puts(buf);
		serv_getln(buf, sizeof buf);
		if (buf[0] != '2') {
			strcpy(WC->ImportantMessage, &buf[4]);
			display_main_menu();
			return;
		}
	}
	gotoroom(er_name);
	strcpy(WC->ImportantMessage, _("Your changes have been saved."));
	display_editroom();
	return;
}


/*
 * Display form for Invite, Kick, and show Who Knows a room
 */
void do_invt_kick(void) {
        char buf[SIZ], room[SIZ], username[SIZ];

        serv_puts("GETR");
        serv_getln(buf, sizeof buf);

        if (buf[0] != '2') {
		escputs(&buf[4]);
		return;
        }
        extract_token(room, &buf[4], 0, '|', sizeof room);

        strcpy(username, bstr("username"));

        if (havebstr("kick_button")) {
                sprintf(buf, "KICK %s", username);
                serv_puts(buf);
                serv_getln(buf, sizeof buf);

                if (buf[0] != '2') {
                        strcpy(WC->ImportantMessage, &buf[4]);
                } else {
                        sprintf(WC->ImportantMessage,
				_("<B><I>User %s kicked out of room %s.</I></B>\n"), 
                                username, room);
                }
        }

	if (havebstr("invite_button")) {
                sprintf(buf, "INVT %s", username);
                serv_puts(buf);
                serv_getln(buf, sizeof buf);

                if (buf[0] != '2') {
                        strcpy(WC->ImportantMessage, &buf[4]);
                } else {
                        sprintf(WC->ImportantMessage,
                        	_("<B><I>User %s invited to room %s.</I></B>\n"), 
                                username, room);
                }
        }

	display_editroom();
}



/*
 * Display form for Invite, Kick, and show Who Knows a room
 */
void display_whok(void)
{
        char buf[SIZ], room[SIZ], username[SIZ];

        serv_puts("GETR");
        serv_getln(buf, sizeof buf);

        if (buf[0] != '2') {
		escputs(&buf[4]);
		return;
        }
        extract_token(room, &buf[4], 0, '|', sizeof room);

        
	wprintf("<table border=0 CELLSPACING=10><tr VALIGN=TOP><td>");
	wprintf(_("The users listed below have access to this room.  "
		"To remove a user from the access list, select the user "
		"name from the list and click 'Kick'."));
	wprintf("<br /><br />");
	
        wprintf("<CENTER><form method=\"POST\" action=\"do_invt_kick\">\n");
	wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
	wprintf("<input type=\"hidden\" NAME=\"tab\" VALUE=\"access\">\n");
        wprintf("<select NAME=\"username\" SIZE=\"10\" style=\"width:100%%\">\n");
        serv_puts("WHOK");
        serv_getln(buf, sizeof buf);
        if (buf[0] == '1') {
                while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
                        extract_token(username, buf, 0, '|', sizeof username);
                        wprintf("<OPTION>");
                        escputs(username);
                        wprintf("\n");
                }
        }
        wprintf("</select><br />\n");

        wprintf("<input type=\"submit\" name=\"kick_button\" value=\"%s\">", _("Kick"));
        wprintf("</form></CENTER>\n");

	wprintf("</td><td>");
	wprintf(_("To grant another user access to this room, enter the "
		"user name in the box below and click 'Invite'."));
	wprintf("<br /><br />");

        wprintf("<CENTER><form method=\"POST\" action=\"do_invt_kick\">\n");
	wprintf("<input type=\"hidden\" NAME=\"tab\" VALUE=\"access\">\n");
	wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
        wprintf(_("Invite:"));
	wprintf(" ");
        wprintf("<input type=\"text\" name=\"username\" id=\"username_id\" style=\"width:100%%\"><br />\n"
        	"<input type=\"hidden\" name=\"invite_button\" value=\"Invite\">"
        	"<input type=\"submit\" value=\"%s\">"
		"</form></CENTER>\n", _("Invite"));
		/* Pop open an address book -- begin **/
		wprintf(
			"<a href=\"javascript:PopOpenAddressBook('username_id|%s');\" "
			"title=\"%s\">"
			"<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
			"&nbsp;%s</a>",
			_("User"), 
			_("Users"), _("Users")
		);
		/* Pop open an address book -- end **/

	wprintf("</td></tr></table>\n");
	address_book_popup();
        wDumpContent(1);
}



/*
 * display the form for entering a new room
 */
void display_entroom(void)
{
	int i;
	char buf[SIZ];

	serv_puts("CRE8 0");
	serv_getln(buf, sizeof buf);

	if (buf[0] != '2') {
		strcpy(WC->ImportantMessage, &buf[4]);
		display_main_menu();
		return;
	}

	output_headers(1, 1, 1, 0, 0, 0);

	svprintf(HKEY("BOXTITLE"), WCS_STRING, _("Create a new room"));
	do_template("beginbox");

	wprintf("<form name=\"create_room_form\" method=\"POST\" action=\"entroom\">\n");
	wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);

	wprintf("<table class=\"altern\"> ");

	wprintf("<tr class=\"even\"><td>");
	wprintf(_("Name of room: "));
	wprintf("</td><td>");
	wprintf("<input type=\"text\" NAME=\"er_name\" MAXLENGTH=\"127\">\n");
        wprintf("</td></tr>");

	wprintf("<tr class=\"odd\"><td>");
	wprintf(_("Resides on floor: "));
	wprintf("</td><td>");
        load_floorlist(); 
        wprintf("<select name=\"er_floor\" size=\"1\">\n");
        for (i = 0; i < 128; ++i)
                if (!IsEmptyStr(floorlist[i])) {
                        wprintf("<option ");
                        wprintf("value=\"%d\">", i);
                        escputs(floorlist[i]);
                        wprintf("</option>\n");
                }
        wprintf("</select>\n");
        wprintf("</td></tr>");

		/*
		 * Our clever little snippet of JavaScript automatically selects
		 * a public room if the view is set to Bulletin Board or wiki, and
		 * it selects a mailbox room otherwise.  The user can override this,
		 * of course.  We also disable the floor selector for mailboxes.
		 */
	wprintf("<tr class=\"even\"><td>");
	wprintf(_("Default view for room: "));
	wprintf("</td><td>");
        wprintf("<select name=\"er_view\" size=\"1\" OnChange=\""
		"	if ( (this.form.er_view.value == 0)		"
		"	   || (this.form.er_view.value == 6) ) {	"
		"		this.form.type[0].checked=true;		"
		"		this.form.er_floor.disabled = false;	"
		"	}						"
		"	else {						"
		"		this.form.type[4].checked=true;		"
		"		this.form.er_floor.disabled = true;	"
		"	}						"
		"\">\n");
	for (i=0; i<(sizeof viewdefs / sizeof (char *)); ++i) {
		if (is_view_allowed_as_default(i)) {
			wprintf("<option %s value=\"%d\">",
				((i == 0) ? "selected" : ""), i );
			escputs(viewdefs[i]);
			wprintf("</option>\n");
		}
	}
	wprintf("</select>\n");
	wprintf("</td></tr>");

	wprintf("<tr class=\"even\"><td>");
	wprintf(_("Type of room:"));
	wprintf("</td><td>");
	wprintf("<ul class=\"adminlist\">\n");

	wprintf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"public\" ");
	wprintf("CHECKED OnChange=\""
		"	if (this.form.type[0].checked == true) {	"
		"		this.form.er_floor.disabled = false;	"
		"	}						"
		"\"> ");
	wprintf(_("Public (automatically appears to everyone)"));
	wprintf("</li>");

	wprintf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"hidden\" OnChange=\""
		"	if (this.form.type[1].checked == true) {	"
		"		this.form.er_floor.disabled = false;	"
		"	}						"
		"\"> ");
	wprintf(_("Private - hidden (accessible to anyone who knows its name)"));
	wprintf("</li>");

	wprintf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"passworded\" OnChange=\""
		"	if (this.form.type[2].checked == true) {	"
		"		this.form.er_floor.disabled = false;	"
		"	}						"
		"\"> ");
	wprintf(_("Private - require password: "));
	wprintf("<input type=\"text\" NAME=\"er_password\" MAXLENGTH=\"9\">\n");
	wprintf("</li>");

	wprintf("<li><input type=\"radio\" NAME=\"type\" VALUE=\"invonly\" OnChange=\""
		"	if (this.form.type[3].checked == true) {	"
		"		this.form.er_floor.disabled = false;	"
		"	}						"
		"\"> ");
	wprintf(_("Private - invitation only"));
	wprintf("</li>");

	wprintf("\n<li><input type=\"radio\" NAME=\"type\" VALUE=\"personal\" "
		"OnChange=\""
		"	if (this.form.type[4].checked == true) {	"
		"		this.form.er_floor.disabled = true;	"
		"	}						"
		"\"> ");
	wprintf(_("Personal (mailbox for you only)"));
	wprintf("</li>");

	wprintf("\n</ul>\n");
	wprintf("</td></tr></table>\n");

	wprintf("<div class=\"buttons\">\n");
	wprintf("<input type=\"submit\" name=\"ok_button\" value=\"%s\">", _("Create new room"));
	wprintf("&nbsp;");
	wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">", _("Cancel"));
	wprintf("</div>\n");
	wprintf("</form>\n<hr />");
	serv_printf("MESG roomaccess");
	serv_getln(buf, sizeof buf);
	if (buf[0] == '1') {
		fmout("LEFT");
	}

	do_template("endbox");

	wDumpContent(1);
}




/*
 * support function for entroom() -- sets the default view 
 */
void er_set_default_view(int newview) {

	char buf[SIZ];

	char rm_name[SIZ];
	char rm_pass[SIZ];
	char rm_dir[SIZ];
	int rm_bits1;
	int rm_floor;
	int rm_listorder;
	int rm_bits2;

	serv_puts("GETR");
	serv_getln(buf, sizeof buf);
	if (buf[0] != '2') return;

	extract_token(rm_name, &buf[4], 0, '|', sizeof rm_name);
	extract_token(rm_pass, &buf[4], 1, '|', sizeof rm_pass);
	extract_token(rm_dir, &buf[4], 2, '|', sizeof rm_dir);
	rm_bits1 = extract_int(&buf[4], 3);
	rm_floor = extract_int(&buf[4], 4);
	rm_listorder = extract_int(&buf[4], 5);
	rm_bits2 = extract_int(&buf[4], 7);

	serv_printf("SETR %s|%s|%s|%d|0|%d|%d|%d|%d",
		rm_name, rm_pass, rm_dir, rm_bits1, rm_floor,
		rm_listorder, newview, rm_bits2
	);
	serv_getln(buf, sizeof buf);
}



/*
 * Create a new room
 */
void entroom(void)
{
	char buf[SIZ];
	char er_name[SIZ];
	char er_type[SIZ];
	char er_password[SIZ];
	int er_floor;
	int er_num_type;
	int er_view;

	if (!havebstr("ok_button")) {
		strcpy(WC->ImportantMessage,
			_("Cancelled.  No new room was created."));
		display_main_menu();
		return;
	}
	strcpy(er_name, bstr("er_name"));
	strcpy(er_type, bstr("type"));
	strcpy(er_password, bstr("er_password"));
	er_floor = ibstr("er_floor");
	er_view = ibstr("er_view");

	er_num_type = 0;
	if (!strcmp(er_type, "hidden"))
		er_num_type = 1;
	if (!strcmp(er_type, "passworded"))
		er_num_type = 2;
	if (!strcmp(er_type, "invonly"))
		er_num_type = 3;
	if (!strcmp(er_type, "personal"))
		er_num_type = 4;

	sprintf(buf, "CRE8 1|%s|%d|%s|%d|%d|%d", 
		er_name, er_num_type, er_password, er_floor, 0, er_view);
	serv_puts(buf);
	serv_getln(buf, sizeof buf);
	if (buf[0] != '2') {
		strcpy(WC->ImportantMessage, &buf[4]);
		display_main_menu();
		return;
	}
	/** TODO: Room created, now udate the left hand icon bar for this user */
	burn_folder_cache(0);	/* burn the old folder cache */
	
	
	gotoroom(er_name);
	do_change_view(er_view);		/* Now go there */
}


/**
 * \brief display the screen to enter a private room
 */
void display_private(char *rname, int req_pass)
{
	output_headers(1, 1, 1, 0, 0, 0);

	svprintf(HKEY("BOXTITLE"), WCS_STRING, _("Go to a hidden room"));
	do_template("beginbox");

	wprintf("<p>");
	wprintf(_("If you know the name of a hidden (guess-name) or "
		"passworded room, you can enter that room by typing "
		"its name below.  Once you gain access to a private "
		"room, it will appear in your regular room listings "
		"so you don't have to keep returning here."));
	wprintf("</p>");

	wprintf("<form method=\"post\" action=\"goto_private\">\n");
	wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);

	wprintf("<table class=\"altern\"> "
		"<tr class=\"even\"><td>");
	wprintf(_("Enter room name:"));
	wprintf("</td><td>"
		"<input type=\"text\" name=\"gr_name\" "
		"value=\"%s\" maxlength=\"128\">\n", rname);

	if (req_pass) {
		wprintf("</td></tr><tr class=\"odd\"><td>");
		wprintf(_("Enter room password:"));
		wprintf("</td><td>");
		wprintf("<input type=\"password\" name=\"gr_pass\" maxlength=\"9\">\n");
	}
	wprintf("</td></tr></table>\n");

	wprintf("<div class=\"buttons\">\n");
	wprintf("<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
		"&nbsp;"
		"<input type=\"submit\" name=\"cancel_button\" value=\"%s\">",
		_("Go there"),
		_("Cancel")
	);
	wprintf("</div></form>\n");

	do_template("endbox");

	wDumpContent(1);
}

/**
 * \brief goto a private room
 */
void goto_private(void)
{
	char hold_rm[SIZ];
	char buf[SIZ];

	if (!havebstr("ok_button")) {
		display_main_menu();
		return;
	}
	strcpy(hold_rm, WC->wc_roomname);
	strcpy(buf, "GOTO ");
	strcat(buf, bstr("gr_name"));
	strcat(buf, "|");
	strcat(buf, bstr("gr_pass"));
	serv_puts(buf);
	serv_getln(buf, sizeof buf);

	if (buf[0] == '2') {
		smart_goto(bstr("gr_name"));
		return;
	}
	if (!strncmp(buf, "540", 3)) {
		display_private(bstr("gr_name"), 1);
		return;
	}
	output_headers(1, 1, 1, 0, 0, 0);
	wprintf("%s\n", &buf[4]);
	wDumpContent(1);
	return;
}


/**
 * \brief display the screen to zap a room
 */
void display_zap(void)
{
	output_headers(1, 1, 2, 0, 0, 0);

	wprintf("<div id=\"banner\">\n");
	wprintf("<h1>");
	wprintf(_("Zap (forget/unsubscribe) the current room"));
	wprintf("</h1>\n");
	wprintf("</div>\n");

	wprintf("<div id=\"content\" class=\"service\">\n");

	wprintf(_("If you select this option, <em>%s</em> will "
		"disappear from your room list.  Is this what you wish "
		"to do?<br />\n"), WC->wc_roomname);

	wprintf("<form method=\"POST\" action=\"zap\">\n");
	wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
	wprintf("<input type=\"submit\" NAME=\"ok_button\" VALUE=\"%s\">", _("Zap this room"));
	wprintf("&nbsp;");
	wprintf("<input type=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
	wprintf("</form>\n");
	wDumpContent(1);
}


/**
 * \brief zap a room
 */
void zap(void)
{
	char buf[SIZ];
	char final_destination[SIZ];

	/**
	 * If the forget-room routine fails for any reason, we fall back
	 * to the current room; otherwise, we go to the Lobby
	 */
	strcpy(final_destination, WC->wc_roomname);

	if (havebstr("ok_button")) {
		serv_printf("GOTO %s", WC->wc_roomname);
		serv_getln(buf, sizeof buf);
		if (buf[0] == '2') {
			serv_puts("FORG");
			serv_getln(buf, sizeof buf);
			if (buf[0] == '2') {
				strcpy(final_destination, "_BASEROOM_");
			}
		}
	}
	smart_goto(final_destination);
}



/**
 * \brief Delete the current room
 */
void delete_room(void)
{
	char buf[SIZ];

	
	serv_puts("KILL 1");
	serv_getln(buf, sizeof buf);
	burn_folder_cache(0);	/* Burn the cahce of known rooms to update the icon bar */
	if (buf[0] != '2') {
		strcpy(WC->ImportantMessage, &buf[4]);
		display_main_menu();
		return;
	} else {
		smart_goto("_BASEROOM_");
	}
}



/**
 * \brief Perform changes to a room's network configuration
 */
void netedit(void) {
	FILE *fp;
	char buf[SIZ];
	char line[SIZ];
	char cmpa0[SIZ];
	char cmpa1[SIZ];
	char cmpb0[SIZ];
	char cmpb1[SIZ];
	int i, num_addrs;
	// TODO: do line dynamic!
	if (havebstr("line_pop3host")) {
		strcpy(line, bstr("prefix"));
		strcat(line, bstr("line_pop3host"));
		strcat(line, "|");
		strcat(line, bstr("line_pop3user"));
		strcat(line, "|");
		strcat(line, bstr("line_pop3pass"));
		strcat(line, "|");
		strcat(line, ibstr("line_pop3keep") ? "1" : "0" );
		strcat(line, "|");
		sprintf(&line[strlen(line)],"%ld", lbstr("line_pop3int"));
		strcat(line, bstr("suffix"));
	}
	else if (havebstr("line")) {
		strcpy(line, bstr("prefix"));
		strcat(line, bstr("line"));
		strcat(line, bstr("suffix"));
	}
	else {
		display_editroom();
		return;
	}


	fp = tmpfile();
	if (fp == NULL) {
		display_editroom();
		return;
	}

	serv_puts("GNET");
	serv_getln(buf, sizeof buf);
	if (buf[0] != '1') {
		fclose(fp);
		display_editroom();
		return;
	}

	/** This loop works for add *or* remove.  Spiffy, eh? */
	while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
		extract_token(cmpa0, buf, 0, '|', sizeof cmpa0);
		extract_token(cmpa1, buf, 1, '|', sizeof cmpa1);
		extract_token(cmpb0, line, 0, '|', sizeof cmpb0);
		extract_token(cmpb1, line, 1, '|', sizeof cmpb1);
		if ( (strcasecmp(cmpa0, cmpb0)) 
		   || (strcasecmp(cmpa1, cmpb1)) ) {
			fprintf(fp, "%s\n", buf);
		}
	}

	rewind(fp);
	serv_puts("SNET");
	serv_getln(buf, sizeof buf);
	if (buf[0] != '4') {
		fclose(fp);
		display_editroom();
		return;
	}

	while (fgets(buf, sizeof buf, fp) != NULL) {
		buf[strlen(buf)-1] = 0;
		serv_puts(buf);
	}

	if (havebstr("add_button")) {
		num_addrs = num_tokens(bstr("line"), ',');
		if (num_addrs < 2) {
			/* just adding one node or address */
			serv_puts(line);
		}
		else {
			/* adding multiple addresses separated by commas */
			for (i=0; i<num_addrs; ++i) {
				strcpy(line, bstr("prefix"));
				extract_token(buf, bstr("line"), i, ',', sizeof buf);
				striplt(buf);
				strcat(line, buf);
				strcat(line, bstr("suffix"));
				serv_puts(line);
			}
		}
	}

	serv_puts("000");
	fclose(fp);
	display_editroom();
}



/**
 * \brief Convert a room name to a folder-ish-looking name.
 * \param folder the folderish name
 * \param room the room name
 * \param floor the floor name
 * \param is_mailbox is it a mailbox?
 */
void room_to_folder(char *folder, char *room, int floor, int is_mailbox)
{
	int i, len;

	/**
	 * For mailboxes, just do it straight...
	 */
	if (is_mailbox) {
		sprintf(folder, "My folders|%s", room);
	}

	/**
	 * Otherwise, prefix the floor name as a "public folders" moniker
	 */
	else {
		if (floor > MAX_FLOORS) {
			wc_backtrace ();
			sprintf(folder, "%%%%%%|%s", room);
		}
		else {
			sprintf(folder, "%s|%s", floorlist[floor], room);
		}
	}

	/**
	 * Replace "\" characters with "|" for pseudo-folder-delimiting
	 */
	len = strlen (folder);
	for (i=0; i<len; ++i) {
		if (folder[i] == '\\') folder[i] = '|';
	}
}




/**
 * \brief Back end for change_view()
 * \param newview set newview???
 */
void do_change_view(int newview) {
	char buf[SIZ];

	serv_printf("VIEW %d", newview);
	serv_getln(buf, sizeof buf);
	WC->wc_view = newview;
	smart_goto(WC->wc_roomname);
}



/**
 * \brief Change the view for this room
 */
void change_view(void) {
	int view;

	view = lbstr("view");
	do_change_view(view);
}


/**
 * \brief One big expanded tree list view --- like a folder list
 * \param fold the folder to view
 * \param max_folders how many folders???
 * \param num_floors hom many floors???
 */
void do_folder_view(struct folder *fold, int max_folders, int num_floors) {
	char buf[SIZ];
	int levels;
	int i;
	int has_subfolders = 0;
	int *parents;

	parents = malloc(max_folders * sizeof(int));

	/** BEGIN TREE MENU */
	wprintf("<div id=\"roomlist_div\">Loading folder list...</div>\n");

	/** include NanoTree */
	wprintf("<script type=\"text/javascript\" src=\"static/nanotree.js\"></script>\n");

	/** initialize NanoTree */
	wprintf("<script type=\"text/javascript\">			\n"
		"	showRootNode = false;				\n"
		"	sortNodes = false;				\n"
		"	dragable = false;				\n"
		"							\n"
		"	function standardClick(treeNode) {		\n"
		"	}						\n"
		"							\n"
		"	var closedGif = 'static/folder_closed.gif';	\n"
		"	var openGif = 'static/folder_open.gif';		\n"
		"							\n"
		"	rootNode = new TreeNode(1, 'root node - hide');	\n"
	);

	levels = 0;
	for (i=0; i<max_folders; ++i) {

		has_subfolders = 0;
		if ((i+1) < max_folders) {
			int len;
			len = strlen(fold[i].name);
			if ( (!strncasecmp(fold[i].name, fold[i+1].name, len))
			   && (fold[i+1].name[len] == '|') ) {
				has_subfolders = 1;
			}
		}

		levels = num_tokens(fold[i].name, '|');
		parents[levels] = i;

		wprintf("var node%d = new TreeNode(%d, '", i, i);

		if (fold[i].selectable) {
			wprintf("<a href=\"dotgoto?room=");
			urlescputs(fold[i].room);
			wprintf("\">");
		}

		if (levels == 1) {
			wprintf("<span class=\"roomlist_floor\">");
		}
		else if (fold[i].hasnewmsgs) {
			wprintf("<span class=\"roomlist_new\">");
		}
		else {
			wprintf("<span class=\"roomlist_old\">");
		}
		extract_token(buf, fold[i].name, levels-1, '|', sizeof buf);
		escputs(buf);
		wprintf("</span>");

		wprintf("</a>', ");
		if (has_subfolders) {
			wprintf("new Array(closedGif, openGif)");
		}
		else if (fold[i].view == VIEW_ADDRESSBOOK) {
			wprintf("'static/viewcontacts_16x.gif'");
		}
		else if (fold[i].view == VIEW_CALENDAR) {
			wprintf("'static/calarea_16x.gif'");
		}
		else if (fold[i].view == VIEW_CALBRIEF) {
			wprintf("'static/calarea_16x.gif'");
		}
		else if (fold[i].view == VIEW_TASKS) {
			wprintf("'static/taskmanag_16x.gif'");
		}
		else if (fold[i].view == VIEW_NOTES) {
			wprintf("'static/storenotes_16x.gif'");
		}
		else if (fold[i].view == VIEW_MAILBOX) {
			wprintf("'static/privatemess_16x.gif'");
		}
		else {
			wprintf("'static/chatrooms_16x.gif'");
		}
		wprintf(", '");
		urlescputs(fold[i].name);
		wprintf("');\n");

		if (levels < 2) {
			wprintf("rootNode.addChild(node%d);\n", i);
		}
		else {
			wprintf("node%d.addChild(node%d);\n", parents[levels-1], i);
		}
	}

	wprintf("container = document.getElementById('roomlist_div');	\n"
		"showTree('');	\n"
		"</script>\n"
	);

	free(parents);
	/** END TREE MENU */
}

/**
 * \brief Boxes and rooms and lists ... oh my!
 * \param fold the folder to view
 * \param max_folders how many folders???
 * \param num_floors hom many floors???
 */
void do_rooms_view(struct folder *fold, int max_folders, int num_floors) {
	char buf[256];
	char floor_name[256];
	char old_floor_name[256];
	char boxtitle[256];
	int levels, oldlevels;
	int i, t;
	int num_boxes = 0;
	static int columns = 3;
	int boxes_per_column = 0;
	int current_column = 0;
	int nf;

	strcpy(floor_name, "");
	strcpy(old_floor_name, "");

	nf = num_floors;
	while (nf % columns != 0) ++nf;
	boxes_per_column = (nf / columns);
	if (boxes_per_column < 1) boxes_per_column = 1;

	/** Outer table (for columnization) */
	wprintf("<table BORDER=0 WIDTH=96%% CELLPADDING=5>"
		"<tr><td valign=top>");

	levels = 0;
	oldlevels = 0;
	for (i=0; i<max_folders; ++i) {

		levels = num_tokens(fold[i].name, '|');
		extract_token(floor_name, fold[i].name, 0,
			'|', sizeof floor_name);

		if ( (strcasecmp(floor_name, old_floor_name))
		   && (!IsEmptyStr(old_floor_name)) ) {
			/* End inner box */
			do_template("endbox");
			wprintf("<br>");

			++num_boxes;
			if ((num_boxes % boxes_per_column) == 0) {
				++current_column;
				if (current_column < columns) {
					wprintf("</td><td valign=top>\n");
				}
			}
		}
		strcpy(old_floor_name, floor_name);

		if (levels == 1) {
			/** Begin inner box */
			stresc(boxtitle, 256, floor_name, 1, 0);
			svprintf(HKEY("BOXTITLE"), WCS_STRING, boxtitle);
			do_template("beginbox");
		}

		oldlevels = levels;

		if (levels > 1) {
			wprintf("&nbsp;");
			if (levels>2) for (t=0; t<(levels-2); ++t) wprintf("&nbsp;&nbsp;&nbsp;");
			if (fold[i].selectable) {
				wprintf("<a href=\"dotgoto?room=");
				urlescputs(fold[i].room);
				wprintf("\">");
			}
			else {
				wprintf("<i>");
			}
			if (fold[i].hasnewmsgs) {
				wprintf("<span class=\"roomlist_new\">");
			}
			else {
				wprintf("<span class=\"roomlist_old\">");
			}
			extract_token(buf, fold[i].name, levels-1, '|', sizeof buf);
			escputs(buf);
			wprintf("</span>");
			if (fold[i].selectable) {
				wprintf("</A>");
			}
			else {
				wprintf("</i>");
			}
			if (!strcasecmp(fold[i].name, "My Folders|Mail")) {
				wprintf(" (INBOX)");
			}
			wprintf("<br />\n");
		}
	}
	/** End the final inner box */
	do_template("endbox");

	wprintf("</td></tr></table>\n");
}

/**
 * \brief print a floor div???
 * \param which_floordiv name of the floordiv???
 */
void set_floordiv_expanded(char *which_floordiv) {
	begin_ajax_response();
	safestrncpy(WC->floordiv_expanded, which_floordiv, sizeof WC->floordiv_expanded);
	end_ajax_response();
}

/**
 * \brief view the iconbar
 * \param fold the folder to view
 * \param max_folders how many folders???
 * \param num_floors hom many floors???
 */
void do_iconbar_view(struct folder *fold, int max_folders, int num_floors) {
	char buf[256];
	char floor_name[256];
	char old_floor_name[256];
	char floordivtitle[256];
	char floordiv_id[32];
	int levels, oldlevels;
	int i, t;
	int num_drop_targets = 0;
	char *icon = NULL;

	strcpy(floor_name, "");
	strcpy(old_floor_name, "");

	levels = 0;
	oldlevels = 0;
	for (i=0; i<max_folders; ++i) {

		levels = num_tokens(fold[i].name, '|');
		extract_token(floor_name, fold[i].name, 0,
			'|', sizeof floor_name);

		if ( (strcasecmp(floor_name, old_floor_name))
		   && (!IsEmptyStr(old_floor_name)) ) {
			/** End inner box */
			wprintf("<br>\n");
			wprintf("</div>\n");	/** floordiv */
		}
		strcpy(old_floor_name, floor_name);

		if (levels == 1) {
			/** Begin floor */
			stresc(floordivtitle, 256, floor_name, 0, 0);
			sprintf(floordiv_id, "floordiv%d", i);
			wprintf("<span class=\"ib_roomlist_floor\" "
				"onClick=\"expand_floor('%s')\">"
				"%s</span><br>\n", floordiv_id, floordivtitle);
			wprintf("<div id=\"%s\" style=\"display:%s\">",
				floordiv_id,
				(!strcasecmp(floordiv_id, WC->floordiv_expanded) ? "block" : "none")
			);
		}

		oldlevels = levels;

		if (levels > 1) {
			wprintf("<div id=\"roomdiv%d\">", i);
			wprintf("&nbsp;");
			if (levels>2) for (t=0; t<(levels-2); ++t) wprintf("&nbsp;");

			/** choose the icon */
			if (fold[i].view == VIEW_ADDRESSBOOK) {
				icon = "viewcontacts_16x.gif" ;
			}
			else if (fold[i].view == VIEW_CALENDAR) {
				icon = "calarea_16x.gif" ;
			}
			else if (fold[i].view == VIEW_CALBRIEF) {
				icon = "calarea_16x.gif" ;
			}
			else if (fold[i].view == VIEW_TASKS) {
				icon = "taskmanag_16x.gif" ;
			}
			else if (fold[i].view == VIEW_NOTES) {
				icon = "storenotes_16x.gif" ;
			}
			else if (fold[i].view == VIEW_MAILBOX) {
				icon = "privatemess_16x.gif" ;
			}
			else {
				icon = "chatrooms_16x.gif" ;
			}

			if (fold[i].selectable) {
				wprintf("<a href=\"dotgoto?room=");
				urlescputs(fold[i].room);
				wprintf("\">");
				wprintf("<img  border=0 src=\"static/%s\" alt=\"\"> ", icon);
			}
			else {
				wprintf("<i>");
			}
			if (fold[i].hasnewmsgs) {
				wprintf("<span class=\"ib_roomlist_new\">");
			}
			else {
				wprintf("<span class=\"ib_roomlist_old\">");
			}
			extract_token(buf, fold[i].name, levels-1, '|', sizeof buf);
			escputs(buf);
			if (!strcasecmp(fold[i].name, "My Folders|Mail")) {
				wprintf(" (INBOX)");
			}
			wprintf("</span>");
			if (fold[i].selectable) {
				wprintf("</A>");
			}
			else {
				wprintf("</i>");
			}
			wprintf("<br />");
			wprintf("</div>\n");	/** roomdiv */
		}
	}
	wprintf("</div>\n");	/** floordiv */


	/** BEGIN: The old invisible pixel trick, to get our JavaScript to initialize */
	wprintf("<img src=\"static/blank.gif\" onLoad=\"\n");

	num_drop_targets = 0;

	for (i=0; i<max_folders; ++i) {
		levels = num_tokens(fold[i].name, '|');
		if (levels > 1) {
			wprintf("drop_targets_elements[%d]=$('roomdiv%d');\n", num_drop_targets, i);
			wprintf("drop_targets_roomnames[%d]='", num_drop_targets);
			jsescputs(fold[i].room);
			wprintf("';\n");
			++num_drop_targets;
		}
	}

	wprintf("num_drop_targets = %d;\n", num_drop_targets);
	if ((WC->floordiv_expanded[0] != '\0')&&
	    (WC->floordiv_expanded[1] != '\0')){
		wprintf("which_div_expanded = '%s';\n", WC->floordiv_expanded);
	}

	wprintf("\">\n");
	/** END: The old invisible pixel trick, to get our JavaScript to initialize */
}



/**
 * \brief Burn the cached folder list.  
 * \param age How old the cahce needs to be before we burn it.
 */

void burn_folder_cache(time_t age)
{
	/** If our cached folder list is very old, burn it. */
	if (WC->cache_fold != NULL) {
		if ((time(NULL) - WC->cache_timestamp) > age) {
			free(WC->cache_fold);
			WC->cache_fold = NULL;
		}
	}
}




/**
 * \brief Show the room list.  
 * (only should get called by
 * knrooms() because that's where output_headers() is called from)
 * \param viewpref the view preferences???
 */

void list_all_rooms_by_floor(char *viewpref) {
	char buf[SIZ];
	int swap = 0;
	struct folder *fold = NULL;
	struct folder ftmp;
	int max_folders = 0;
	int alloc_folders = 0;
	int *floor_mapping;
	int IDMax;
	int i, j;
	int ra_flags = 0;
	int flags = 0;
	int num_floors = 1;	/** add an extra one for private folders */
	char buf2[SIZ];
	char buf3[SIZ];
	
	/** If our cached folder list is very old, burn it. */
	burn_folder_cache(300);
	
	/** Can we do the iconbar roomlist from cache? */
	if ((WC->cache_fold != NULL) && (!strcasecmp(viewpref, "iconbar"))) {
		do_iconbar_view(WC->cache_fold, WC->cache_max_folders, WC->cache_num_floors);
		return;
	}

	/** Grab the floor table so we know how to build the list... */
	load_floorlist();

	/** Start with the mailboxes */
	max_folders = 1;
	alloc_folders = 1;
	fold = malloc(sizeof(struct folder));
	memset(fold, 0, sizeof(struct folder));
	strcpy(fold[0].name, "My folders");
	fold[0].is_mailbox = 1;

	/** Then add floors */
	serv_puts("LFLR");
	serv_getln(buf, sizeof buf);
	if (buf[0]=='1') while(serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
		if (max_folders >= alloc_folders) {
			alloc_folders = max_folders + 100;
			fold = realloc(fold,
				alloc_folders * sizeof(struct folder));
		}
		memset(&fold[max_folders], 0, sizeof(struct folder));
		extract_token(fold[max_folders].name, buf, 1, '|', sizeof fold[max_folders].name);
		extract_token(buf3, buf, 0, '|', SIZ);
		fold[max_folders].floor = atol (buf3);
		++max_folders;
		++num_floors;
	}
	IDMax = 0;
	for (i=0; i<num_floors; i++)
		if (IDMax < fold[i].floor)
			IDMax = fold[i].floor;
	floor_mapping = malloc (sizeof (int) * (IDMax + 1));
	memset (floor_mapping, 0, sizeof (int) * (IDMax + 1));
	for (i=0; i<num_floors; i++)
		floor_mapping[fold[i].floor]=i;
	
	/** refresh the messages index for this room */
//	serv_puts("GOTO ");
//	while (serv_getln(buf, sizeof buf), strcmp(buf, "000"));
	/** Now add rooms */
	serv_puts("LKRA");
	serv_getln(buf, sizeof buf);
	if (buf[0]=='1') while(serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
		if (max_folders >= alloc_folders) {
			alloc_folders = max_folders + 100;
			fold = realloc(fold,
				alloc_folders * sizeof(struct folder));
		}
		memset(&fold[max_folders], 0, sizeof(struct folder));
		extract_token(fold[max_folders].room, buf, 0, '|', sizeof fold[max_folders].room);
		ra_flags = extract_int(buf, 5);
		flags = extract_int(buf, 1);
		fold[max_folders].floor = extract_int(buf, 2);
		fold[max_folders].hasnewmsgs =
			((ra_flags & UA_HASNEWMSGS) ? 1 : 0 );
		if (flags & QR_MAILBOX) {
			fold[max_folders].is_mailbox = 1;
		}
		fold[max_folders].view = extract_int(buf, 6);
		room_to_folder(fold[max_folders].name,
				fold[max_folders].room,
				fold[max_folders].floor,
				fold[max_folders].is_mailbox);
		fold[max_folders].selectable = 1;
		/* Increase the room count for the associtaed floor */
		if (fold[max_folders].is_mailbox) {
			fold[0].num_rooms++;
		}
		else {
			i = floor_mapping[fold[max_folders].floor];
			fold[i].num_rooms++;
		}
		++max_folders;
	}
	
	/*
	 * Remove any floors that don't have rooms
	 */
	get_preference("emptyfloors", buf2, sizeof buf2);
	if (buf2[0]==0 || (strcasecmp(buf2, "no") == 0))
	{
		for (i=0; i<num_floors; i++)
		{
        		if (fold[i].num_rooms == 0) {
                		for (j=i; j<max_folders; j++) {
                        		memcpy(&fold[j], &fold[j+1], sizeof(struct folder));
                		}
                		max_folders--;
                		num_floors--;
                		i--;
        		}
		}
	}
	
	/** Bubble-sort the folder list */
	for (i=0; i<max_folders; ++i) {
		for (j=0; j<(max_folders-1)-i; ++j) {
			if (fold[j].is_mailbox == fold[j+1].is_mailbox) {
				swap = strcasecmp(fold[j].name, fold[j+1].name);
			}
			else {
				if ( (fold[j+1].is_mailbox)
				   && (!fold[j].is_mailbox)) {
					swap = 1;
				}
				else {
					swap = 0;
				}
			}
			if (swap > 0) {
				memcpy(&ftmp, &fold[j], sizeof(struct folder));
				memcpy(&fold[j], &fold[j+1],
							sizeof(struct folder));
				memcpy(&fold[j+1], &ftmp,
							sizeof(struct folder));
			}
		}
	}


	if (!strcasecmp(viewpref, "folders")) {
		do_folder_view(fold, max_folders, num_floors);
	}
	else if (!strcasecmp(viewpref, "hackish_view")) {
		for (i=0; i<max_folders; ++i) {
			escputs(fold[i].name);
			wprintf("<br />\n");
		}
	}
	else if (!strcasecmp(viewpref, "iconbar")) {
		do_iconbar_view(fold, max_folders, num_floors);
	}
	else {
		do_rooms_view(fold, max_folders, num_floors);
	}

	/* Don't free the folder list ... cache it for future use! */
	if (WC->cache_fold != NULL) {
		free(WC->cache_fold);
	}
	WC->cache_fold = fold;
	WC->cache_max_folders = max_folders;
	WC->cache_num_floors = num_floors;
	WC->cache_timestamp = time(NULL);
	free(floor_mapping);
}


/**
 * \brief Do either a known rooms list or a folders list, depending on the
 * user's preference
 */
void knrooms(void)
{
	char listviewpref[SIZ];

	output_headers(1, 1, 2, 0, 0, 0);

	/** Determine whether the user is trying to change views */
	if (bstr("view") != NULL) {
		if (havebstr("view")) {
			set_preference("roomlistview", bstr("view"), 1);
		}
	}

	get_preference("roomlistview", listviewpref, sizeof listviewpref);

	if ( (strcasecmp(listviewpref, "folders"))
	   && (strcasecmp(listviewpref, "table")) ) {
		strcpy(listviewpref, "rooms");
	}

	/** title bar */
	wprintf("<div id=\"banner\">\n");
	wprintf("<div class=\"room_banner\">");
	wprintf("<h1>");
	if (!strcasecmp(listviewpref, "rooms")) {
		wprintf(_("Room list"));
	}
	if (!strcasecmp(listviewpref, "folders")) {
		wprintf(_("Folder list"));
	}
	if (!strcasecmp(listviewpref, "table")) {
		wprintf(_("Room list"));
	}
	wprintf("</h1></div>\n");

	/** offer the ability to switch views */
	wprintf("<ul class=\"room_actions\">\n");
	wprintf("<li class=\"start_page\">");
	offer_start_page();
	wprintf("</li>");
	wprintf("<li><form name=\"roomlistomatic\">\n"
		"<select name=\"newview\" size=\"1\" "
		"OnChange=\"location.href=roomlistomatic.newview.options"
		"[selectedIndex].value\">\n");

	wprintf("<option %s value=\"knrooms&view=rooms\">"
		"View as room list"
		"</option>\n",
		( !strcasecmp(listviewpref, "rooms") ? "SELECTED" : "" )
	);

	wprintf("<option %s value=\"knrooms&view=folders\">"
		"View as folder list"
		"</option>\n",
		( !strcasecmp(listviewpref, "folders") ? "SELECTED" : "" )
	);

	wprintf("</select>");
	wprintf("</form></li>");
	wprintf("</ul></div>\n");

	wprintf("<div id=\"content\" class=\"service\">\n");

	/** Display the room list in the user's preferred format */
	list_all_rooms_by_floor(listviewpref);
	wDumpContent(1);
}



/**
 * \brief Set the message expire policy for this room and/or floor
 */
void set_room_policy(void) {
	char buf[SIZ];

	if (!havebstr("ok_button")) {
		strcpy(WC->ImportantMessage,
			_("Cancelled.  Changes were not saved."));
		display_editroom();
		return;
	}

	serv_printf("SPEX room|%d|%d", ibstr("roompolicy"), ibstr("roomvalue"));
	serv_getln(buf, sizeof buf);
	strcpy(WC->ImportantMessage, &buf[4]);

	if (WC->axlevel >= 6) {
		strcat(WC->ImportantMessage, "<br />\n");
		serv_printf("SPEX floor|%d|%d", ibstr("floorpolicy"), bstr("floorvalue"));
		serv_getln(buf, sizeof buf);
		strcat(WC->ImportantMessage, &buf[4]);
	}

	display_editroom();
}

/*@}*/