mmc /core/web/includes/PageGenerator.php

Language PHP Lines 2654
MD5 Hash a01120f2c9a1486fc1cd1071a8463751
Repository https://github.com/vmasilva/mmc.git View Raw File
   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
<?php
/**
 * (c) 2004-2007 Linbox / Free&ALter Soft, http://linbox.com
 * (c) 2007-2010 Mandriva, http://www.mandriva.com
 *
 * $Id$
 *
 * This file is part of Mandriva Management Console (MMC).
 *
 * MMC is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * MMC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with MMC.  If not, see <http://www.gnu.org/licenses/>.
 */

require ("FormGenerator.php");

/**
 * return an uniqId (use full for javascript auto generation
 */
function getUniqId() {
    global $__uniqID;
    $__uniqID++;
    return $__uniqID;
}

/**
 * can echo obj and string with the same function
 * similar to "echo" in PHP5
 */
function echo_obj($obj) {

   if (is_object($obj)){
        echo $obj->__toString();
   }
   else if(is_bool($obj)) {
        if($obj)
            echo '<img src="img/common/icn_yes.gif" alt="yes" />';
   }
   else {
        echo ($obj);
   }

}

/**
 * class for action encapsulation
 * Abstract class for the moment
 * @see EditInPlace
 */
class ActionEncapsulator {
    function ActionEncapsulator() {

    }

    function __toString() {
        return "default action encapsulator";
    }
}

/**
 * AutoGenerate an EditInPlace text
 * based on scriptaculous javascript
 */
class EditInPlace extends ActionEncapsulator{

    var $origText;
    var $url;
    var $param;

    function EditInPlace($origText,$url,$param) {
        $this->origText = $origText;
        $this->url = $url;
        $this->param = $param;

    }

    function __toString() {

        $param = array();

        foreach ($this->param as $key=>$value) {
            $param[] = "$key=$value";
        }

        $urlparam = implode("&",$param);

        if ($this->origText== '') {
            $this->origText= "n/a";
        }

        $idx = getUniqId();

        $str = '';
        $str.= "<span id=\"id$idx\" class=\"editinplace\">".$this->origText."</span>";


       $str .= '<script type="text/javascript">';
       $str .= "     new Ajax.InPlaceEditor($('id$idx'),'".$this->url."', {\n
                okButton: true, cancelLink: true, cancelText : '"._('Cancel')."',
                highlightcolor : '#FF9966',
                ajaxOptions: {method: 'get' },\n
                callback: function(form,value) {\n
                    return '$urlparam&value='+value\n
                }\n
            });\n
        </script>\n";
      return $str;
    }

}

/**
 *  class for action in various application
 */
class ActionItem {
    var $desc;
    var $action;
    var $classCss;
    var $paramString;
    var $mod;

    /**
     *  Constructor
     * @param $desc description
     * @param $action string include in the url
     * @param $classCss class for CSS like "supprimer" or other class define
     *    in the CSS global.css
     * @param $paramString add "&$param=" at the very end of the url
     */
    function ActionItem($desc, $action, $classCss, $paramString, $module = null, $submod = null, $tab = null, $mod = false) {
        $this->desc=$desc;
        $this->action=$action;
        $this->classCss=$classCss;
        $this->paramString=$paramString;
        if ($module == null) $this->module = $_GET["module"];
        else $this->module = $module;
        if ($submod == null) $this->submod = $_GET["submod"];
        else $this->submod = $submod;
        $this->tab = $tab;
        $this->mod = $mod;
        $this->path = $this->module . "/" . $this->submod . "/" . $this->action;
        if ($this->tab != null) {
            $this->path .= "/" . $this->tab;
        }
    }

    /**
     *  display a link for the action
     *  @param add &$this->param=$param at the very end of the url
     *  display "displayWithRight" if you have correct right
     */
    function display($param, $extraParams = array()) {
        if (hasCorrectAcl($this->module,$this->submod,$this->action)) {
            $this->displayWithRight($param, $extraParams);
        } else {
            $this->displayWithNoRight($param, $extraParams);
        }
    }

    /**
     * display function if you have correct right on this action
     */
    function displayWithRight($param, $extraParams = array()) {
        /* add special param for actionItem */
        if (is_array($extraParams)) {
            $extraParams['mod'] = $this->mod;
        }
        echo "<li class=\"".$this->classCss."\">";
        if (is_array($extraParams) & !empty($extraParams)) $urlChunk = $this->buildUrlChunk($extraParams);
        else $urlChunk = "&amp;" . $this->paramString."=" . rawurlencode($extraParams);
        echo "<a title=\"".$this->desc."\" href=\"" . urlStr($this->path) . $urlChunk . "\">&nbsp;</a>";
        echo "</li>";
    }

    /**
     * display function if you don't have the right for this action
     */
    function displayWithNoRight($param, $extraParams = array()) {
        echo "<li class=\"".$this->classCss."\" style=\"opacity: 0.30;\">";
        echo "<a title=\"".$this->desc."\" href=\"#\" onclick='return false;'>&nbsp;</a>";
        echo "</li>";
    }

    /**
     * transform $obj param in link for this action
     */
    function encapsulate($obj, $extraParams = Array()) {
        if (hasCorrectAcl($this->module,$this->submod,$this->action)) {
            if (is_array($extraParams) & !empty($extraParams)) {
                $urlChunk = $this->buildUrlChunk($extraParams);
            } else {
                $urlChunk = "&amp;" . $this->paramString."=" . rawurlencode($obj);
            }
            $str= "<a title=\"".$this->desc."\" href=\"main.php?module=".$this->module."&amp;submod=".$this->submod."&amp;action=".$this->action . $urlChunk ."\">";
            $str.= trim($obj);
            $str.= "</a>";
            return $str;
        } else {
            $str= "<a title=\"".$this->desc."\" href=\"#\">";
            $str.= "$obj";
            $str.=" </a>";
            return $str;
        }
    }

    /**
     * Build an URL chunk using a array of option => value
     */
    function buildUrlChunk($arr) {
        $urlChunk = "";
        foreach($arr as $option => $value) {
            $urlChunk .= "&amp;" . $option . "=" . urlencode($value);
        }
        return $urlChunk;
    }


    /**
     * display help (not use for the moment)
     */
    function strHelp() {
        $str = "";
        $str.= "<li class=\"".$this->classCss."\">";
        $str.= "<a title=\"".$this->desc."\" href=\"#\">";
        $str.= " </a>".$this->desc."</li>";
        return $str;
    }
}

/**
 * display action in a JavaScript popup
 *
 * @see ActionItem
 * @see showPopup (js)
 */
class ActionPopupItem extends ActionItem {

    function ActionPopupItem($desc, $action, $classCss, $paramString, $module = null, $submod = null, $tab = null, $width = 300, $mod = false) {
        $this->ActionItem($desc, $action, $classCss, $paramString, $module, $submod, $tab, $mod);
        $this->setWidth($width);
    }

    /**
     * Set the JavaScript popup width.
     * The default width value is 300px.
     */
    function setWidth($width) {
        $this->width = $width;
    }

    function displayWithRight($param, $extraParams = array()) {
        /* Add special param for actionPopupItem */
        $extraParams['mod'] = $this->mod;
        if (is_array($extraParams) & !empty($extraParams)) {
            $urlChunk = $this->buildUrlChunk($extraParams);
        } else {
            $urlChunk = "&amp;" . $this->paramString."=" . rawurlencode($param);
        }
        echo "<li class=\"".$this->classCss."\">";
        echo "<a title=\"".$this->desc."\" href=\"main.php?module=".$this->module."&amp;submod=".$this->submod."&amp;action=" . $this->action . $urlChunk . "\"";
        echo " onclick=\"PopupWindow(event,'main.php?module=".$this->module."&amp;submod=".$this->submod."&amp;action=" .$this->action . $urlChunk . "', " . $this->width . "); return false;\">&nbsp;</a>";
        echo "</li>";
    }

    function encapsulate($obj, $extraParams = array()) {
        if (is_array($extraParams) & !empty($extraParams)) {
            $urlChunk = $this->buildUrlChunk($extraParams);
        } else {
            $urlChunk = "&amp;" . $this->paramString."=" . rawurlencode($obj);
        }
        $str= "<a title=\"".$this->desc."\" href=\"main.php?module=".$this->module."&amp;submod=".$this->submod."&amp;action=".$this->action . $urlChunk . "\" ";
        $str.= "  onclick=\"showPopup(event,'main.php?module=".$this->module."&amp;submod=".$this->submod."&amp;action=".$this->action . $urlChunk . "', " . $this->width . "); return false;\">";
        $str.= "$obj";
        $str.=" </a>";
        return $str;
    }
}

class EmptyActionItem extends ActionItem {

    function EmptyActionItem() {
    }

    function display($param = null) {
        print '<li class="empty"><a href="#" onclick="return false;">&nbsp;</a></li>';
    }

}

/**
 *  class who maintain array presentation of information
 */
class ListInfos extends HtmlElement {
    var $arrInfo; /**< main list */
    var $extraInfo;
    var $paramInfo;
    var $name;
    var $arrAction; /**< list of possible action */
    var $end, $start;

    var $description; /**< list of description (not an obligation) */
    var $col_width; /**< Contains the columns width */
    var $tooltip; /**< Contains the tooltip for column label */

    /**
     * constructor
     * @param $tab must be an array of array
     */
    function ListInfos($tab, $description ="", $extranavbar = "") {
        $this->arrInfo=$tab;
        $this->arrAction=array();
        $this->description[] = $description;
        $this->extranavbar = $extranavbar;
        $this->initVar();
        $this->col_width = array();
        $this->tooltip = array();
        $this->tooltip[] = "";
        $this->firstColumnActionLink = True;
        $this->_addInfo = array();
    }

    function setAdditionalInfo($addinfo) {
        $this->_addInfo = $addinfo;
    }

    /**
     * Set the number of rows to display per ListInfos page.
     * It overrides the default value defined by $conf["global"]["maxperpage"].
     *
     * @param $value The number of rows
     */
    function setRowsPerPage($value) {
        $this->end = $value;
    }

    /**
     *  add an ActionItem
     *  @param $objActionItem object ActionItem
     */
    function addActionItem($objActionItem) {
        $this->arrAction[] = &$objActionItem;
    }

    /**
     * Add an array of ActionItem
     * Useful if all action items are not the same for each row of the list
     *
     */
    function addActionItemArray($objActionItemArray) {
        assert(is_array($objActionItemArray));
        $this->arrAction[] = &$objActionItemArray;
    }


    /**
     *  add an array String to display
     *  @param $arrString an Array String to display
     *  @param description Table column name
     *  @param width Table column width
     *  @param tooltip Tooltip to display on the column name
     */
    function addExtraInfo($arrString, $description= "", $width="", $tooltip = "") {
        assert(is_array($arrString));
        $this->extraInfo[] = &$arrString;
        $this->description[] = $description;
        $this->col_width[] = $width;
        $this->tooltip[] = $tooltip;
    }

    /**
     *  set parameters array for main action
     *  @param $arrString an Array of string to be used as parameters for the main action
     */
    function setParamInfo($arrString) {
        assert(is_array($arrString));
        $this->paramInfo = $arrString;
    }

    /**
     * Set the left padding of the table header.
     * It will be set to 32 by default
     * @param $padding an integer
     */
    function setTableHeaderPadding($padding) {
        $this->first_elt_padding = $padding;
    }

    /**
     * Disable the link to the first available action in the table
     * This link is always done by default
     */
    function disableFirstColumnActionLink() {
        $this->firstColumnActionLink = False;
    }

    /**
     *  init class' vars
     */
    function initVar() {

        $this->name="Elements";

        global $conf;

	$this->maxperpage = (isset($_REQUEST['maxperpage'])) ? $_REQUEST['maxperpage'] : $conf['global']['maxperpage'];

        if (!isset($_GET["start"])) {
            if (!isset($_POST["start"])) {
                $this->start = 0;

                if (count($this->arrInfo) > 0) {
                    $this->end = $this->maxperpage - 1;
                } else {
                    $this->end = 0;
                }
            }
        } else {
            $this->start = $_GET["start"];
            $this->end = $_GET["end"];
        }
        /* Set a basic navigation bar */
        $this->setNavBar(new SimpleNavBar($this->start, $this->end, count($this->arrInfo), $this->extranavbar));
    }


    /**
     *  set the name of the array (for CSS)
     */
    function setName($name) {
        $this->name=$name;
    }

    /**
     *  set the cssclass of a row
     */
    function setCssClass($name) {
        $this->cssClass=$name;
    }

    /**
     * set a cssclass for each row
     */
    function setCssClasses($a_names) {
        $this->cssClasses = $a_names;
    }

    /**
     * Set the ListInfos navigation bar
     */
    function setNavBar($navbar) {
        $this->navbar = $navbar;
    }

    /**
     *
     * Display the widget navigation bar if $navbar is True
     *
     * @param $navbar: if $navbar is true the navigation bar is displayed
     */
    function displayNavbar($navbar) {
        if ($navbar) $this->navbar->display();
    }

    /**
     *  draw number of page etc...
     */
    function drawHeader($navbar = 1) {

        $this->displayNavbar($navbar);
        echo "<p class=\"listInfos\">";

        /*
         * Management of the numbers "start" and "end" to display depending on the maxperpage set in the selector
         * These numbers are more user-friendly and do not begin with 0
         */
        echo $this->name." <strong>".min($this->start + 1, count($this->arrInfo)) . "</strong>\n ";
        echo _("to")." <strong>".min($this->end + 1, count($this->arrInfo))."</strong>\n";

        printf (_(" - Total <b>%s </b>")."\n",count($this->arrInfo));
        /* Display page counter only when possible */
        if ($this->maxperpage >= ($this->end - $this->start)) {
            echo "("._("page")." ";
            printf("%.0f", ($this->end + 1) / $this->maxperpage);
            echo " / ";
            $pages = intval((count($this->arrInfo) / $this->maxperpage)) ;
            if ((count($this->arrInfo) % $this->maxperpage > 0) && (count($this->arrInfo) > $this->maxperpage))
                $pages++;
            else if ((count($this->arrInfo) > 0) && ($pages < 1))
                $pages = 1;
            else if ($pages < 0)
                $pages = 0;
            printf("%.0f", $pages);
            echo ")\n";
        }
        echo "</p>";
    }

    /**
     * display main action (first action
     */
    function drawMainAction($idx) {
        if (!empty($this->cssClass)) {
            echo "<td class=\"".$this->cssClass."\">";
        } else {
            echo "<td>";
        }
        if (is_a($this->arrAction[0], 'ActionItem')) {
            $firstAction = $this->arrAction[0];
        } else if (is_array($this->arrAction[0])) {
            $firstAction = $this->arrAction[0][$idx];
        }
        echo $firstAction->encapsulate($this->arrInfo[$idx], $this->paramInfo[$idx]);
        if (isset($this->_addInfo[$idx])) {
            print " " . $this->_addInfo[$idx];
        }
        echo "</td>";
    }

    function drawTable($navbar = 1) {
        echo "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\" class=\"listinfos\">\n";
        echo "<thead><tr>";
        $first = False;
        foreach ($this->description as $key => $desc) {
            if (isset($this->col_width[$key])) {
                $width_styl = 'width: '.$this->col_width[$key].';';
            } else {
                $width_styl = '';
            }
            if (!$first) {

                if (!isset($this->first_elt_padding)) {
                    $this->first_elt_padding = 32;
                }
                echo "<td style=\"$width_styl\"><span style=\"color: #777; padding-left: ".$this->first_elt_padding."px;\">$desc</span></td>";
                $first = True;

            } else {
                /* Draw table header line */
                /* Add a tooltip to the column name if there is one set */
                if (!empty($this->tooltip[$key])) {
                    $tooltipbegin = "<a href=\"#\" class=\"tooltip\">";
                    $tooltipend = "<span>" . $this->tooltip[$key] . "</span></a>";
                } else {
                    $tooltipbegin = "";
                    $tooltipend = "";
                }
                echo "<td style=\"$width_styl\"><span style=\"color: #777;\">$tooltipbegin$desc$tooltipend</span></td>";
            }
        }

        if (count($this->arrAction)!=0) { //if we have actions
            if (!empty($this->col_width)) {
                $width_styl = $this->col_width[count($this->col_width) - 1];
            }
            $width_styl = isset($width_styl) ? sprintf('width: %s;', $width_styl) : '';
            echo "<td style=\"text-align: right; $width_styl\"><span style=\"color: #AAA;\" >Actions</span></td>";
        }

        echo "</tr></thead>";

        for ( $idx = $this->start; ($idx < count($this->arrInfo)) && ($idx <= $this->end); $idx++) {
            if (($this->start - $idx) % 2) {
                echo "<tr";
                if (!empty($this->cssClasses[$idx])) {
                    echo " class=\"".$this->cssClasses[$idx]."\"";
                }
                echo ">";
            } else {
                echo "<tr class=\"alternate";
                if (!empty($this->cssClasses[$idx])) {
                    echo " ".$this->cssClasses[$idx];
                }
                echo "\">";
            }

            //link to first action (if we have an action)
            if (count($this->arrAction) && $this->firstColumnActionLink) {
                $this->drawMainAction($idx);
            } else {
                if (!empty($this->cssClass)) {
                    echo "<td class=\"".$this->cssClass."\">";
                } else {
                    echo "<td>";
                }
                echo $this->arrInfo[$idx];
                echo "</td>";
            }

            if ($this->extraInfo)
                foreach ($this->extraInfo as $arrayTMP) {
                    echo "<td>";
                    if(trim($arrayTMP[$idx]) != "") {
                        echo_obj($arrayTMP[$idx]);
                    }
                    else {
                        echo "&nbsp;";
                    }
                    echo "</td>";
                }
            if (count($this->arrAction)!=0) {
                echo "<td class=\"action\">";
                echo "<ul class=\"action\">";
                foreach ($this->arrAction as $objActionItem) {
                    if (is_a($objActionItem, 'ActionItem')) {
                        $objActionItem->display($this->arrInfo[$idx], $this->paramInfo[$idx]);
                    } else if (is_array($objActionItem)) {
                        $obj = $objActionItem[$idx];
                        $obj->display($this->arrInfo[$idx], $this->paramInfo[$idx]);
                    }
                }
                echo "</ul>";
                echo "</td>";
            }
            echo "</tr>\n";
        }


        echo "</table>\n";

        $this->displayNavbar($navbar);

        if (false) {
            /* Code disabled because not used and make javavascript errors */
            print '<script type="text/javascript"><!--';
            print '$(\'help\').innerHTML=\'\''."\n";
            print '$(\'help\').innerHTML+=\'<ul>\''."\n";
            print '$(\'help\').innerHTML+=\'<li><h3>Aide contextuelle</h3></li>\''."\n";
            foreach ($this->arrAction as $objActionItem) {
                $content = $objActionItem->strHelp();
                print '$(\'help\').innerHTML+=\''.$content.'\';'."\n";
            }
            print '$(\'help\').innerHTML+=\'</ul>\''."\n";
            print '--></script>';
        }

    }

    function display($navbar = 1, $header =1 ) {
        if (!isset($this->paramInfo)) {
            $this->paramInfo = $this->arrInfo;
        }

        if ($header == 1) {
            $this->drawHeader($navbar);
        }
        $n = new NotifyWidget();
        if (isset($_SESSION['__notify'])) {
            $n->showJS();
        }
        $this->drawTable($navbar);
    }
}


/**
 * A modified version of Listinfos
 */
class OptimizedListInfos extends ListInfos {

    /**
     * Allow to set another item count
     */
    function setItemCount($count) {
        $this->itemCount = $count;
    }

    function getItemCount() {
        return $this->itemCount;
    }

    /**
     *  init class' vars
     */
    function initVar() {
        $this->name="Elements";
        global $conf;
        if (!isset($_GET["start"])) {
            if (!isset($_POST["start"])) {
                $this->start = 0;
                if (count($this->arrInfo) > 0) {
                    $this->end = (isset($_REQUEST['maxperpage'])) ? ($_REQUEST['maxperpage'] - 1) : ($conf["global"]["maxperpage"] - 1);
                } else {
                    $this->end = 0;
                }
            }
        } else {
            $this->start = $_GET["start"];
            $this->end = $_GET["end"];
        }
        $this->maxperpage = (isset($_REQUEST['maxperpage'])) ? $_REQUEST['maxperpage'] : $conf["global"]["maxperpage"];
        $this->setItemCount(count($this->arrInfo));
        $this->startreal = $this->start;
        $this->endreal = $this->end;
    }

    /**
     *  draw number of page etc...
     */
    function drawHeader($navbar=1) {
        $count = $this->getItemCount();
        $this->displayNavbar($navbar);
        echo "<p class=\"listInfos\">";

        /*
         * Management of the numbers "start" and "end" to display depending on the maxperpage set in the selector
         * These numbers are more user-friendly and do not begin with 0
         */
        echo $this->name." <strong>".min($this->startreal + 1, $count) . "</strong>\n ";
        echo _("to")." <strong>".min($this->endreal + 1, $count)."</strong>\n";

        printf (_(" - Total <b>%s </b>")."\n", $count);
        /* Display page counter only when possible */
        if ($this->maxperpage >= ($this->endreal - $this->startreal)) {
            echo "("._("page")." ";
            printf("%.0f", ($this->endreal + 1) / $this->maxperpage);
            echo " / ";
            $pages = intval(($count / $this->maxperpage)) ;
            if (($count % $this->maxperpage > 0) && ($count > $this->maxperpage))
                $pages++;
            else if (($count > 0) && ($pages < 1))
                $pages = 1;
            else if ($pages < 0)
                $pages = 0;
            printf("%.0f", $pages);
            echo ")\n";
        }
        echo "</p>";
    }
}

/**
 * specific class for UserDisplay
 */
class UserInfos extends OptimizedListInfos {
    var $css = array(); //css for first column

    function drawMainAction($idx) {
        echo "<td class=\"".$this->css[$idx]."\">";
        echo $this->arrAction[0]->encapsulate($this->arrInfo[$idx], $this->paramInfo[$idx]);
        echo "</td>";
    }

}


/**
 *
 *  Display a previous/next navigation bar for ListInfos widget
 *
 */
class SimpleNavBar extends HtmlElement {

    /**
     * @param $curstart: the first item index to display
     * @param $curent: the last item index
     * @param $itemcount: total number of item
     * @param $filter: the current list filter
     * @param $max: max quantity of elements in a page
     * @param $paginator: boolean which enable the selector of the number of results in a page
     */
    function SimpleNavBar($curstart, $curend, $itemcount, $extra = "", $max = "", $paginator = false) {
        global $conf;
        if(isset($max) && $max != "") {
            $this->max = $max;
        } else {
            $this->max = $conf["global"]["maxperpage"];
        }
        $this->curstart = $curstart;
        $this->curend = $curend;
        $this->itemcount = $itemcount;
        $this->extra = $extra;
        $this->paginator = $paginator;
        # number of pages
        $this->nbpages = ceil($this->itemcount / $this->max);
        # number of current page
        $this->curpage = floor(($this->curend + 1) / $this->max);
    }

    function display() {
        echo '<form method="post">';
        echo "<ul class=\"navList\">\n";

        if ($this->curstart == 0 || ($this->curstart - $this->max < 0))
            echo "<li class=\"previousListInactive\">"._("Previous")."</li>\n";
        else {
            $start = $this->curstart - $this->max;
            $end = $this->curstart - 1;
            echo "<li class=\"previousList\"><a href=\"".$_SERVER["SCRIPT_NAME"];
            /* FIXME: maybe we can get rid of $_GET["filter"] ? */
            printf("?module=%s&amp;submod=%s&amp;action=%s&amp;start=%d&amp;end=%d&amp;filter=%s%s", $_GET["module"],$_GET["submod"],$_GET["action"],$start, $end, $_GET["filter"], $this->extra);
            echo "\">"._("Previous")."</a></li>\n";
        }

        if($this->paginator) {
            // Display the maxperpage selector
            $this->displaySelectMax();
        }

        if (($this->curend + 1) >= $this->itemcount)
            echo "<li class=\"nextListInactive\">"._("Next")."</li>\n";
        else {
            $start = $this->curend + 1;
            $end = $this->curend + $this->max;
            echo "<li class=\"nextList\"><a href=\"".$_SERVER["SCRIPT_NAME"];
            printf("?module=%s&amp;submod=%s&amp;action=%s&amp;start=%d&amp;end=%d&amp;filter=%s%s", $_GET["module"],$_GET["submod"],$_GET["action"],$start, $end, $_GET["filter"], $this->extra);
            echo "\">"._("Next")."</a></li>\n";
        }

        if($this->paginator) {
            // Display a border at the left of the "Next" link
            $this->displayNextListBorder();
        }

        echo "</ul>\n";
    }

    /*
     * This function displays a selector to choose the maxperpage value
     * dynamically.
     * This is useful with AjaxNavBar
     * @param $jsfunc: optional javascript function which updates ListInfos
     */
    function displaySelectMax($jsfunc=null) {
        global $conf;
        echo '<span class="pagination">'._('Pagination').': ';
        if(isset($jsfunc)) {
            $start = $this->curstart;

            echo "<select id=\"maxperpage\" name=\"maxperpage\" onChange=\"updateMaxPerPage(this); return false;\" class=\"pagination\">";
        } else {
            echo "<select id=\"maxperpage\" name=\"maxperpage\" class=\"pagination\">";
        }
        /* Display the selector and each option of the array set in the config
           file */
        foreach($conf["global"]["pagination"] as $quantity) {
            $selected = '';
            if ($_REQUEST['maxperpage'] == $quantity)
                /* Set by default if already selected before */
                $selected = ' selected="selected"';
            echo "<option value=\"$quantity\"$selected>$quantity</option>";
        }
        echo "</select></span>";

        /*
         * Print the script which will launch an update of the ListInfos when
         * selectMax value changes.
         * It also synchronizes the value of the two selectors of the widget.
         * Then it calls the javascript function which do an AJAX update of
         * the ListInfos.
         */
?>
        <script type="javascript">
	    updateMaxPerPage = function(elem) {
            // Get the selector element (the first of the page)
	        var maxperpageElement = document.getElementById('maxperpage');
            if(maxperpageElement != undefined) {
                // Synchronize the value of the two selectors of the page :
                // the ListInfos widget print two Navbar, so the maxperpage value can be changed in both
                maxperpageElement.selectedIndex = elem.selectedIndex;
                var maxperpageValue = elem.value;
                // Evaluate the end depending on the maxperpage value selected
                var end = parseInt(maxperpageValue) + parseInt(<?php echo $start ?>) - 1;
                // Call the function to update the ListInfos
                <?php echo $jsfunc ?>('<?php echo $this->filter ?>', '<?php echo $start ?>', end);
            }
            return false;
        }
        </script>
<?

    }

    /**
     * This function just print a script which add a border at the left of the "Next" link
     */
    function displayNextListBorder() {
?>
        <script type="javascript">
        var nextList = [];
        var nextListClass = "";
        if(document.getElementsByClassName("nextListInactive").length > 0) {
            nextListClass = "nextListInactive";
        }
        if(document.getElementsByClassName("nextList").length > 0) {
            nextListClass = "nextList";
        }
        if(nextListClass != "") {
            nextList = document.getElementsByClassName(nextListClass);
            nextList[0].style.borderLeft = "solid 1px #CCC";
            nextList[1].style.borderLeft = "solid 1px #CCC";
        }
        </script>
<?
    }

    function displayGotoPageField() {
        echo '<script type="text/javascript">
            gotoPage = function(input) {
                page = input.value;
                if (page <= '.$this->nbpages.') {
                    end = ('.$this->max.' * page);
                    start = end - '.$this->max.';
                    end -= 1;
                    cur =  ('.$this->curend.' + 1) / 10;
                    '.$this->jsfunc.'("'.$this->filter.'", start, end, document.getElementById("maxperpage"));
                }
            }
        </script>';
        echo '<span class="pagination">'._("Go to page").': <input type="input" size="2" onchange="gotoPage(this)" /></span>';
    }

    function displayPagesNumbers() {
        # pages links
        # show all pages
        if ($this->nbpages <= 10) {
            if($this->nbpages > 1) {
                echo '<span class="pagination">';
                for($i=1; $i<=$this->nbpages; $i++) {
                    echo $this->makePageLink($i);
                }
                echo '</span>';
            }
        }
        # show start/end pages and current page
        else {
            echo '<span class="pagination">';
            for($i=1; $i<=3; $i++) {
                echo $this->makePageLink($i);
            }
            if($this->curpage > 2 and $this->curpage < 5) {
                for($i=$this->curpage;$i<=$this->curpage+2;$i++) {
                    if ($i > 3)
                        echo $this->makePageLink($i);
                }
            }
            else if ($this->curpage > 4 and $this->curpage < $this->nbpages-3) {
                echo '.. ';
                for($i=$this->curpage-1;$i<=$this->curpage+1;$i++) {
                    echo $this->makePageLink($i);
                }
            }
            echo '.. ';
            if ($this->curpage <= $this->nbpages-2 and $this->curpage >= $this->nbpages-3) {
                for($i=$this->nbpages-4; $i<=$this->nbpages-3; $i++) {
                    echo $this->makePageLink($i);
                }
            }
            for($i=$this->nbpages-2; $i<=$this->nbpages; $i++) {
                echo $this->makePageLink($i);
            }
            echo '</span>';
        }
    }

    function makePageLink($page) {
        $end = ($this->max * $page);
        $start = $end - $this->max;
        $end -= 1;
        if ($page == $this->curpage) {
            return '<span>'.$page.'</span> ';
        }
        else {
            return '<a href="#" onclick="'.$this->jsfunc.'(\''.$this->filter.'\',\''.$start.'\',\''.$end.'\', document.getElementById(\'maxperpage\')); return false;">'.$page.'</a> ';
        }
    }

}

/**
 * Class which creates a SimpleNavBar with the paginator always enabled by
 * default
 */
class SimplePaginator extends SimpleNavBar {

    /**
     * Just call the constructor of SimpleNavBar with "true" value for the
     * $paginator attribute
     *
     * @param $curstart: the first item index to display
     * @param $curent: the last item index
     * @param $itemcount: total number of item
     * @param $filter: the current list filter
     * @param $max: max quantity of elements in a page
     */
    function SimplePaginator($curstart, $curend, $itemcount, $extra = "", $max = "") {
        $this->SimpleNavBar($curstart, $curend, $itemcount, $extra, $max, true);
    }

}

/**
 *  Display a previous/next navigation bar for ListInfos widget
 *  The AjaxNavBar is useful when an Ajax Filter is set for a ListInfos widget
 */
class AjaxNavBar extends SimpleNavBar {

    /**
     *
     * The AjaxNavBar start/end item are get from $_GET["start"] and
     * $_GET["end"]
     *
     * @param $itemcount: total number of item
     * @param $filter: the current list filter
     * @param $extra: extra URL parameter to pass the next/list button
     * @param $jsfunc: the name of the javascript function that applies the AJAX filter for the ListInfos widget
     * @param $max: the max number of elements to display in a page
     */
    function AjaxNavBar($itemcount, $filter, $jsfunc = "updateSearchParam", $max = "", $paginator = false) {
        global $conf;

        if (isset($_GET["start"])) {
            $curstart = $_GET["start"];
            $curend = $_GET["end"];
        } else {
            $curstart = 0;
            if ($itemcount > 0){
                if($max != "") {
                    $curend = $max -1;
                } else {
                    $curend = $conf["global"]["maxperpage"] - 1;
                }
            } else
                $curend = 0;
        }
        $this->SimpleNavBar($curstart, $curend, $itemcount, null, $max, $paginator);
        $this->filter = $filter;
        $this->jsfunc = $jsfunc;
    }

    function display() {
        echo '<form method="post">';
        echo "<ul class=\"navList\">\n";

        if($this->paginator) {
            // Display the maxperpage selector
            $this->displaySelectMax($this->jsfunc);
        }

        // show goto page field
        if ($this->nbpages > 20) {
            $this->displayGotoPageField();
        }

        # previous link
        if ($this->curstart == 0 || ($this->curstart - $this->max < 0))
            echo "<li class=\"previousListInactive\">" . _("Previous") . "</li>\n";
        else {
            $start = $this->curstart - $this->max;
            $end = $this->curstart - 1;
            echo "<li class=\"previousList\"><a href=\"#\" onClick=\"" . $this->jsfunc . "('" . $this->filter . "','$start','$end', document.getElementById('maxperpage')); return false;\">" . _("Previous") . "</a></li>\n";
        }

        // display pages numbers
        $this->displayPagesNumbers();

        # next link
        if (($this->curend + 1) >= $this->itemcount)
            echo "<li class=\"nextListInactive\">"._("Next")."</li>\n";
        else {
            $start = $this->curend + 1;
            $end = $this->curend + $this->max;
            echo "<li class=\"nextList\"><a href=\"#\" onClick=\"" . $this->jsfunc . "('" . $this->filter . "','$start','$end', document.getElementById('maxperpage')); return false;\">" . _("Next") . "</a></li>\n";
        }

        // Display a border at the left of the "Next" link
        if ($this->nbpages > 1) {
            $this->displayNextListBorder();
        }

        echo "</ul>\n";
    }
}

/**
 * Class which creates an AjaxNavBar with the paginator always enabled by
 * default
 */
class AjaxPaginator extends AjaxNavBar {
    /**
     * Just call the constructor of AjaxNavBar with "true" value for the $paginator attribute
     *
     * @param $itemcount: total number of item
     * @param $filter: the current list filter
     * @param $jsfunc: the name of the javascript function that applies the AJAX filter for the ListInfos widget
     * @param $max: the max number of elements to display in a page
     */
    function AjaxPaginator($itemcount, $filter, $jsfunc = "updateSearchParam", $max = "") {
        $this->AjaxNavBar($itemcount, $filter, $jsfunc, $max, true);
    }

}

/**
 *
 * Create an AjaxFilter Form that updates a div according to an url output
 *
 */

class AjaxFilter extends HtmlElement {

    /**
     * @param $url: URL called by the javascript updated. The URL gets the filter in $_GET["filter"]
     * @param $divid: div ID which is updated by the URL output
     * @param $formid: change the form id (usefull for multiple Ajaxfilter in one page)
     */
    function AjaxFilter($url, $divid = "container", $params = array(), $formid = "") {
        if (strpos($url, "?") === False)
            /* Add extra ? needed to build the URL */
            $this->url = $url . "?";
        else
            /* Add extra & needed to build the URL */
            $this->url = $url . "&";
        $this->divid = $divid;
        $this->formid = $formid;
        $this->refresh= 0;
        $this->params = '';
        foreach ($params as $k => $v) {
            $this->params .= "&".$k."=".$v;
        }

        // get the current module pages
        if (isset($_GET["module"]))
            $__module = $_GET["module"];
        else
            $__module = "default";
        if (isset($_GET["submod"]))
            $__submod = $_GET["submod"];
        else
            $__submod = "default";
        if (isset($_GET["action"]))
            $__action = $_GET["action"];
        else
            $__action = "default";
        if (isset($_GET['tab']))
            $__tab = $_GET['tab'];
        else
            $__tab = "default";
        $extra = "";
        foreach($_GET as $key => $value) {
            if (!in_array($key, array('module', 'submod', 'tab', 'action', 'filter', 'start', 'end', 'maxperpage')))
                $extra += $key + "_" + $value;
        }
        // then get our filter info
        if(isset($_SESSION[$__module."_".$__submod."_".$__action."_".$__tab."_filter_".$extra])) {
            $this->storedfilter = $_SESSION[$__module."_".$__submod."_".$__action."_".$__tab."_filter_".$extra];
        }
        if(isset($_SESSION[$__module."_".$__submod."_".$__action."_".$__tab."_maxperpage_".$extra])) {
            $this->storedmax = $_SESSION[$__module."_".$__submod."_".$__action."_".$__tab."_maxperpage_".$extra];
        }
        if(isset($_SESSION[$__module."_".$__submod."_".$__action."_".$__tab."_start_".$extra])) {
            $this->storedstart = $_SESSION[$__module."_".$__submod."_".$__action."_".$__tab."_start_".$extra];
        }
        if(isset($_SESSION[$__module."_".$__submod."_".$__action."_".$__tab."_end_".$extra])) {
            $this->storedend = $_SESSION[$__module."_".$__submod."_".$__action."_".$__tab."_end_".$extra];
        }
    }

    /**
     * Allow the list to refresh
     * @param $refresh: time in ms
     */
    function setRefresh($refresh) {
        $this->refresh = $refresh;
    }

    function display() {
        global $conf;
        $root = $conf["global"]["root"];
        $maxperpage = $conf["global"]["maxperpage"];

?>
<form name="Form<?php echo $this->formid ?>" id="Form<?php echo $this->formid ?>" action="#" onsubmit="return false;">

    <div id="loader<?php echo $this->formid ?>">
        <img id="loadimg" src="<?php echo $root; ?>img/common/loader.gif" alt="loader" class="loader"/>
    </div>
    <div id="searchSpan<?php echo $this->formid ?>" class="searchbox" style="float: right;">
    <img src="graph/search.gif" style="position:relative; top: 2px; float: left;" alt="search" /> <span class="searchfield"><input type="text" class="searchfieldreal" name="param" id="param<?php echo $this->formid ?>" onkeyup="pushSearch<?php echo $this->formid ?>(); return false;" />
    <img src="graph/croix.gif" alt="suppression" style="position:relative; top : 3px;"
    onclick="document.getElementById('param<?php echo $this->formid ?>').value =''; pushSearch<?php echo $this->formid ?>(); return false;" />
    </span>
    </div>

    <script type="text/javascript">
<?
if(!$this->formid) {
?>
        document.getElementById('param<?php echo $this->formid ?>').focus();
<?
}
if(isset($this->storedfilter)) {
?>
        document.Form<?php echo $this->formid ?>.param.value = "<?php echo $this->storedfilter ?>";
<?
}
?>
        var refreshtimer<?php echo $this->formid ?> = null;
        var refreshparamtimer<?php echo $this->formid ?> = null;
        var refreshdelay<?php echo $this->formid ?> = <?php echo  $this->refresh ?>;
        var maxperpage = <?php echo $maxperpage ?>;
<?
if (isset($this->storedmax)) {
?>
        maxperpage = <?php echo $this->storedmax ?>;
<?
}
?>
        if(document.getElementById('maxperpage') != undefined)
            maxperpage = document.getElementById('maxperpage').value;

        /**
         * Clear the timers set vith setTimeout
         */
        clearTimers<?php echo $this->formid ?> = function() {
            if (refreshtimer<?php echo $this->formid ?> != null) {
                clearTimeout(refreshtimer<?php echo $this->formid ?>);
            }
            if (refreshparamtimer<?php echo $this->formid ?> != null) {
                clearTimeout(refreshparamtimer<?php echo $this->formid ?>);
            }
        }

        /**
         * Update div
         */
        <?php
        $url = $this->url."filter='+document.Form".$this->formid.".param.value+'&maxperpage='+maxperpage+'".$this->params;
        if (isset($this->storedstart) && isset($this->storedend)) {
            $url .= "&start=".$this->storedstart."&end=".$this->storedend;
        }
        ?>

        updateSearch<?php echo $this->formid ?> = function() {
            new Ajax.Updater('<?php echo  $this->divid; ?>',
            '<?php echo $url ?>',
            { asynchronous:true, evalScripts: true}
            );

<?
if ($this->refresh) {
?>
            refreshtimer<?php echo $this->formid ?> = setTimeout("updateSearch<?php echo $this->formid ?>()", refreshdelay<?php echo $this->formid ?>)
<?
}
?>
        }

        /**
         * Update div when clicking previous / next
         */
        updateSearchParam<?php echo $this->formid ?> = function(filter, start, end, max) {
            clearTimers<?php echo $this->formid ?>();
            if(document.getElementById('maxperpage') != undefined)
                maxperpage = document.getElementById('maxperpage').value;

            new Ajax.Updater('<?php echo  $this->divid; ?>','<?php echo  $this->url; ?>filter='+filter+'&start='+start+'&end='+end+'&maxperpage='+maxperpage+'<?php echo  $this->params ?>', { asynchronous:true, evalScripts: true});
<?
if ($this->refresh) {
?>
            refreshparamtimer<?php echo $this->formid ?> = setTimeout("updateSearchParam<?php echo $this->formid ?>('"+filter+"',"+start+","+end+","+maxperpage+")", refreshdelay<?php echo $this->formid ?>);
<?
}
?>
        }

        /**
         * wait 500ms and update search
         */
        pushSearch<?php echo $this->formid ?> = function() {
            clearTimers<?php echo $this->formid ?>();
            refreshtimer<?php echo $this->formid ?> = setTimeout("updateSearch<?php echo $this->formid ?>()", 500);
        }

        pushSearch<?php echo $this->formid ?>();

    </script>

</form>
<?
          }

    function displayDivToUpdate() {
        print '<div id="' . $this->divid . '"></div>' . "\n";
    }
}

class NoLocationTpl extends AbstractTpl {

    function NoLocationTpl($name) {
        $this->name = $name;
        $this->size = '13';
    }

    function display() {
        print '<span class="error">' . _("No item available") . '</span>';
        print '<input name="'.$this->name.'" id="'.$this->name.'" type="HIDDEN" size="'.$this->size.'" value="" class="searchfieldreal" />';
    }

    function setSelected($elemnt) {
    }
}

class SingleLocationTpl extends AbstractTpl {

    function SingleLocationTpl($name, $label) {
        $this->name = $name;
        $this->label = $label;
        $this->value = null;
    }

    function setElementsVal($value) {
        $this->value = array_values($value);
        $this->value = $this->value[0];
    }

    function setSelected($elemnt) {
    }

    function display() {
        print $this->label;
        print '<input name="'.$this->name.'" id="'.$this->name.'" type="HIDDEN" value="'. $this->value .'" class="searchfieldreal" />';
    }

}

class AjaxFilterLocation extends AjaxFilter {
    function AjaxFilterLocation($url, $divid = "container", $paramname = 'location', $params = array()) {
        $this->AjaxFilter($url, $divid, $params);
        $this->location = new SelectItem($paramname, 'pushSearch', 'searchfieldreal noborder');
        $this->paramname = $paramname;
    }

    function setElements($elt) {
        if (count($elt) == 0) {
            $this->location = new NoLocationTpl($this->paramname);
        } else if (count($elt) == 1) {
            $loc = array_values($elt);
            $this->location = new SingleLocationTpl($this->paramname, $loc[0]);
        } else {
            $this->location->setElements($elt);
        }
    }

    function setElementsVal($elt) {
        if (count($elt) >= 1) {
            $this->location->setElementsVal($elt);
        }
    }

    function setSelected($elemnt) {
        $this->location->setSelected($elemnt);
    }

    function display() {
        global $conf;
        $root = $conf["global"]["root"];
?>
<form name="Form" id="Form" action="#" onsubmit="return false;">
    <div id="loader"><img id="loadimg" src="<?php echo $root; ?>img/common/loader.gif" alt="loader" class="loader"/></div>
    <div id="searchSpan" class="searchbox" style="float: right;">
    <img src="graph/search.gif" style="position:relative; top: 2px; float: left;" alt="search" />
    <span class="searchfield">
<?php
     $this->location->display();
?>
    </span>&nbsp;
    <span class="searchfield"><input type="text" class="searchfieldreal" name="param" id="param" onkeyup="pushSearch(); return false;" />
    <img src="graph/croix.gif" alt="suppression" style="position:relative; top : 3px;"
    onclick="document.getElementById('param').value =''; pushSearch(); return false;" />
    </span>
    </div>

    <script type="text/javascript">
        document.getElementById('param').focus();

<?
if(isset($this->storedfilter)) {
?>
        document.Form.param.value = "<?php echo $this->storedfilter ?>";
<?
}
?>
        var maxperpage = 10;
        if(document.getElementById('maxperpage') != undefined)
            maxperpage = document.getElementById('maxperpage').value;

        /**
        * update div with user
        */
        function updateSearch() {
            launch--;

                if (launch==0) {
                    new Ajax.Updater('<?php echo  $this->divid; ?>','<?php echo  $this->url; ?>filter='+document.Form.param.value+'<?php echo  $this->params ?>&<?php echo  $this->paramname ?>='+document.Form.<?php echo  $this->paramname ?>.value+'&maxperpage='+maxperpage, { asynchronous:true, evalScripts: true});
                }
            }

        /**
        * provide navigation in ajax for user
        */

        function updateSearchParam(filt, start, end) {
            var reg = new RegExp("##", "g");
            var tableau = filt.split(reg);
            var location = "";
            var filter = "";
            var reg1 = new RegExp(tableau[0]+"##", "g");
            if (filt.match(reg1)) {
                if (tableau[0] != undefined) {
                    filter = tableau[0];
                }
                if (tableau[1] != undefined) {
                    location = tableau[1];
                }
            } else if (tableau.length == 1) {
                if (tableau[0] != undefined) {
                    location = tableau[0];
                }
            }
            if(document.getElementById('maxperpage') != undefined)
            {
                maxperpage = document.getElementById('maxperpage').value;
            }

            new Ajax.Updater('<?php echo  $this->divid; ?>','<?php echo  $this->url; ?>filter='+filter+'<?php echo  $this->params ?>&<?php echo  $this->paramname ?>='+location+'&start='+start+'&end='+end+'&maxperpage='+maxperpage, { asynchronous:true, evalScripts: true});
            }

        /**
        * wait 500ms and update search
        */

        function pushSearch() {
            launch++;
            setTimeout("updateSearch()",500);
        }

        pushSearch();
    </script>

</form>
<?
          }
}

class AjaxLocation extends AjaxFilterLocation {

    function AjaxLocation($url, $divid = "container", $paramname = 'location', $params = array()) {
        $this->AjaxFilterLocation($url, $divid, $paramname, $params);
        $this->location = new SelectItem($paramname, 'pushSearchLocation', 'searchfieldreal noborder');
    }

    function display() {
        global $conf;
        $root = $conf["global"]["root"];
?>
<form name="FormLocation" id="FormLocation" action="#">
    <div id="Location">
        <span id="searchSpan" class="searchbox">
            <img src="graph/search.gif"/>
            <span class="locationtext">&nbsp;<?php echo _("Select entity") ?>:&nbsp;</span>
            <span class="locationfield">
            <?php
            $this->location->display();
            ?>
            </span>
        </span>
        <img id="loadimg" src="<?php echo $root; ?>img/common/loader.gif" alt="loader" />
    </div>


    <script type="text/javascript">
        /**
        * update div with user
        */
        function updateSearchLocation() {
            launch--;
            if (launch==0) {
                new Ajax.Updater('<?php echo  $this->divid; ?>','<?php echo  $this->url; ?><?php echo  $this->params ?>&<?php echo  $this->paramname ?>='+document.FormLocation.<?php echo  $this->paramname ?>.value, { asynchronous:true, evalScripts: true});
                }
        }
        /**
        * wait 500ms and update search
        */

        function pushSearchLocation() {
            launch++;
            setTimeout("updateSearchLocation()",500);
        }
        pushSearchLocation();
    </script>

</form>
<?
    }
}

/**
 *  side menu items class
 *     this class is required by SideMenu class
 *     each SideMenuItem is all necessary information to
 *     create a link.
 *
 *     ex: create action "bar" in module "foo" with submodule "subfoo"
 *     new SideMenuItem("foobar example","foo","subfoo","bar");
 */
class SideMenuItem {
    var $text, $module, $submod, $action, $activebg, $inactivebg;
    /**
     *  main constructor
     * @param $text text for the link
     * @param $module module for link
     * @param $submod sub module for link
     * @param $action action param for link /!\ use for class id too
     * @param $activebg background image to use when menu is currently activated
     * @param $inactivebg background image to use when menu is currently inactivated
     */
    function SideMenuItem($text,$module,$submod,$action, $activebg = "", $inactivebg = "") {
        $this->text = $text;
        $this->module = $module;
        $this->submod = $submod;
        $this->action = $action;
        $this->cssId = $action;
        $this->activebg = $activebg;
        $this->inactivebg = $inactivebg;
    }

    /**
     * @return a formated link like: main.php?module=base&submod=users&action=add
     *
     */
    function getLink() {
        return 'main.php?module='.$this->module.'&amp;submod='.$this->submod.'&amp;action='.$this->action;
    }


    /**
     *  display the SideMenuItem on the screen
     */
    function display() {
        if (hasCorrectAcl($this->module, $this->submod, $this->action)) {
            echo '<li id="'.$this->cssId.'">';
            echo '<a href="'.$this->getLink().'">'.$this->text.'</a></li>'."\n";
        }
    }

    /**
     * Allows to set another CSS id then the default one which is the action
     * string
     *
     * @param id: the CSS id to use
     */
    function setCssId($id) {
        $this->cssId = $id;
    }

    /**
     * Return the menu item CSS
     *
     * @param active: this menu item is active
     */
    function getCss($active = False) {
        $ret = "";
        if ($this->activebg != "" && $this->inactivebg != "") {
            if ($active) $bgi = "background-image: url(" . $this->activebg . ");";
            else $bgi = "background-image: url(" . $this->inactivebg . ");";
        } else {
            $bgi = "";
        }

        if ($active) {
            $color = "#FFF";
            $border = "#FFF";
        } else {
            $color = "#EEE";
            $border = "#666";
        }

        $ret = "#sidebar ul." . $this->submod . " li#" . $this->cssId . " a {
                    background-color: " . $color . ";
                    color: #666;
                    border-right: 1px solid ". $border . ";"
                    . $bgi . "
                }";
        if (!$active)
                $ret = $ret . "
                #sidebar ul." . $this->submod . " li#" . $this->cssId ." a:hover {
                    color: #666;
                    background-color: #F7F7F7;"
                    . $bgi . "
                }";
        return $ret;
    }
}

class SideMenuItemNoAclCheck extends SideMenuItem {
    /**
     *  display the SideMenuItem on the screen
     */
    function display() {
        echo '<li id="'.$this->cssId.'">';
        echo '<a href="'.$this->getLink().'" target="_self">'.$this->text.'</a></li>'."\n";
    }
}

/**
 *  SideMenu class
 *     this class display side menu item
 *     side menu is mmc's left menu, it regroups
 *     possible actions we can do in a spĂŠcific module
 *     like index/configuration/add machine/ add share in
 *     samba module
 *     this class require SideMenuItem
 */
class SideMenu {
    var $itemArray;
    var $className;
    var $backgroundImage;
    var $activatedItem;

    /**
     *  SideMenu default constructor
     *     initalize empty itemArray for SideMenuItem
     */
    function SideMenu() {
        $this->itemArray = array();
        $this->backgroundImage = null;
        $this->activatedItem = null;
    }

    /**
     *  add a sideMenu Item into the SideMenu
     * @param $objSideMenuItem object SideMenuItem
     */
    function addSideMenuItem($objSideMenuItem) {
        $this->itemArray[]=&$objSideMenuItem;
    }

    /**
     * CSS class
     */
    function setClass($class) {
        $this->className=$class;
    }

    /**
     * @return className for CSS
     */
    function getClass() {
        return $this->className;
    }

    /**
     * Set the sidemenu background image
     */
    function setBackgroundImage($bg) {
        $this->backgroundImage = $bg;
    }

    /**
     * Get the sidemenu background image
     */
    function getBackgroundImage() {
        return $this->backgroundImage;
    }

    /**
     *  print the SideMenu and the sideMenuItem
     */
    function display() {
        echo "<div id=\"sidebar\">\n";
        echo "<ul class=\"".$this->className."\">\n";
        foreach ($this->itemArray as $objSideMenuItem) {
            $objSideMenuItem->display();
        }
        echo "</ul>\n";
        echo "</div>\n";
    }

    /**
     *  @return return the Css content for a sidebar
     *  static method to get SideBarCss String
     */
    function getSideBarCss() {
        $css = "";
        foreach ($this->itemArray as $objSideMenuItem) {
            $active = (($objSideMenuItem->submod == $_GET["submod"]) && (($objSideMenuItem->action == $_GET["action"]) || ($objSideMenuItem->action == $this->activatedItem)));
            $css = $css . $objSideMenuItem->getCss($active);
        }
        if ($this->backgroundImage) {
            $css .= "#sectionContainer { background-image: url(" . $this->backgroundImage . ") }";
        }
        return $css;
    }

    /**
     * Force a menu item to be displayed as activated
     * Useful for pages that don't have a dedicated tab
     */
    function forceActiveItem($item) {
        $this->activatedItem = $item;
    }

}

/**
 *  PageGenerator class
 */
class PageGenerator {
    var $sidemenu;  /*< SideMenu Object */
    var $content;   /*< array who contains contents Objects */

    /**
     *  Constructor
     */
    function PageGenerator($title = "") {
        $content=array();
        $this->title = $title;
        $this->fixheight = True;
    }

    /**
     *  set the sideMenu object
     */
    function setSideMenu($objSideMenu) {
        $this->sidemenu=$objSideMenu;
    }

    /**
     * Set the page title
     */
    function setTitle($title) {
        $this->title = $title;
    }

    /**
     *  display the whole page
     */
    function display() {
        $this->displaySideMenu();
        if ($this->title)
            $this->displayTitle();
        if ($this->fixheight) {
            /* On IE, make the page have a minimal length, else the sidemenu may be cut */
            print '<div class="fixheight"></div>';
        }
    }

    function displayCss() {
        echo'<style type="text/css">'."\n";
        echo '<!--'."\n";
        echo $this->sidemenu->getSideBarCss();
        echo '-->'."\n";
        echo '</style>'."\n\n";
    }

    /**
     *  display the side Menu
     */
    function displaySideMenu() {
        $this->displayCss();
        $this->sidemenu->display();
    }

    /**
     *  display the page title
     */
    function displayTitle() {
        if (isset($this->title)) print "<h2>" . $this->title . "</h2>\n";
    }

    /**
     * Sometimes, we don't want to add the fixheight div in the page
     */
    function setNoFixHeight() {
        $this->fixheight = False;
    }
}

/**
 * Little wrapper that just include a PHP file as a HtmlElement
 */
class DisplayFile extends HtmlElement {

    function DisplayFile($file) {
        $this->HtmlElement();
        $this->file = $file;
    }

    function display() {
        require($this->file);
    }
}

/**
 * Class for a tab content
 */
class TabbedPage extends Div {

    function TabbedPage($title, $file) {
        $this->Div(array("class" => "tabdiv"));
        $this->title = $title;
        $this->add(new DisplayFile($file));
    }

    function displayTitle() {
        return "<h2>" . $this->title . "</h2>\n";
    }

    function begin() {
        $s = Div::begin();
        $s .= $this->displayTitle();
        return $s;
    }

}

/**
 * Class for tab displayed by TabSelector
 */
class TabWidget extends HtmlElement {

    function TabWidget($id, $title, $params = array()) {
        $this->id = $id;
        $this->title = $title;
        $this->params = $params;
        $this->active = False;
        $this->last = False;
    }

    function getLink() {
        return urlStr($_GET["module"] . "/" . $_GET["submod"] . "/" . $_GET["action"], array_merge(array("tab" => $this->id), $this->params));
    }

    function setActive($flag) {
        $this->active = $flag;
    }

    function display() {
        if ($this->active)
            $klass = ' class="tabactive"';
        else
            $klass = "";
        print '<li id="' . $this->id . '"' . $klass . '"> '
                . '<a href="' . $this->getLink() . '">'
            . $this->title . "</a></li>";
    }

}

/**
 * This class allow to create a page with a tab selector
 */
class TabbedPageGenerator extends PageGenerator {

    function TabbedPageGenerator() {
        $this->PageGenerator();
        $this->topfile = null;
        $this->tabselector = new TabSelector();
        $this->pages = array();
        $this->firstTabActivated = False;
    }

    /**
     * add a header above the tab selector
     */
    function addTop($title, $file) {
        $this->title = $title;
        $this->topfile = $file;
    }


    /**
     * Add a new tab to a page
     *
     * @param name: the tab id
     * @param title: the tab title in the tab selector
     * @param pagetitle: the page title
     * @param file: the file that renders the page
     * @param params: an array of URL parameters
     */
    function addTab($id, $tabtitle, $pagetitle, $file, $params = array()) {
        global $tabAclArray;
        if (hasCorrectTabAcl($_GET["module"], $_GET["submod"], $_GET["action"], $id)) {
            if (isset($_GET["tab"]) && $_GET["tab"] == $id) {
                $this->tabselector->addActiveTab($id, $tabtitle, $params);
            } else {
                if (isset($_GET["tab"])) {
                    $this->tabselector->addTab($id, $tabtitle, $params);
                } else {
                    if (!$this->firstTabActivated) {
                        $this->tabselector->addActiveTab($id, $tabtitle, $params);
                        $this->firstTabActivated = True;
                    } else {
                        $this->tabselector->addTab($id, $tabtitle, $params);
                    }
                }
            }
            $this->pages[$id] = array($pagetitle, $file);
        }
    }

    function display() {
        $this->page = null;
        $this->displaySideMenu();
        $this->displayTitle();
        if ($this->topfile) require($this->topfile);
        $this->tabselector->display();
        if (isset($_GET["tab"]) && isset($this->pages[$_GET["tab"]])) {
            list($title, $file) = $this->pages[$_GET["tab"]];
            $this->page = new TabbedPage($title, $file);
        } else {
            /* Get the first tab page */
            $tab = $this->tabselector->getDefaultTab();
            if ($tab != null) {
                list($title, $file) = $this->pages[$tab->id];
                $this->page = new TabbedPage($title, $file);
            }
        }
        if ($this->page != null) $this->page->display();
    }

}

/**
 * Allow to draw a tab selector
 */
class TabSelector extends HtmlContainer {

    function TabSelector() {
        $this->HtmlContainer();
        $this->tabs = array();
        $this->order = array();
    }

    function getDefaultTab() {
        if (empty($this->elements))
            return null;
        else
            return $this->elements[0];
    }

    function addActiveTab($name, $title, $params = array()) {
        $tab = new TabWidget($name, $title, $params);
        $tab->setActive(True);
        $this->add($tab);
    }

    function addTab($name, $title, $params = array()) {
        $this->add(new TabWidget($name, $title, $params));
    }

    function begin() {
        return '<div class="tabselector"><ul>';
    }

    function end() {
        return "</ul></div>";
    }

}

/**
 * display popup window if notify add in queue
 *
 */
class NotifyWidget {

    /**
     * default constructor
     */
    function NotifyWidget() {
    }

    /**
     * Add a string in notify widget
     * @param $str any HTML CODE
     */
    function add($str) {

        if (!isset($_SESSION['__notify'])) {
            $_SESSION['__notify'] = array();
        }
        $_SESSION['__notify'][] = $str;
    }

    /**
     * set width size
     * @param $size size in px
     */
    function setSize($size) {
        $_SESSION['__notify_size'] = $size;
    }

    /**
     * private internal function
     */
    function getSize() {
        if (isset($_SESSION['__notify_size']) && $_SESSION['__notify_size']) {
            return $_SESSION['__notify_size'];
        } else {
            return 300; //default value
        }
    }

    /**
     * @brief set level (change icon in widget)
     * @param $level level must be beetween 0 and 5
     * level must be beetween 0,5
     * 0: info (default, blue info bubble)
     * <= 1: error for the moment (red icon)
     * 5 is critical
     */
    function setLevel($level) {
        $_SESSION['__notify_level'] = $level;
    }

    /**
     * private internal function
     */
    function getLevel() {
        if (isset($_SESSION['__notify_level']) && $_SESSION['__notify_level']) {
            return $_SESSION['__notify_level'];
        } else {
            return 0; //default level is 0
        }
    }

    /**
     * private internal function
     */
    function getImgLevel() {
        if ($this->getLevel() != 0) {
            return "img/common/icn_alert.gif";
        }

        return "img/common/big_icn_info.png";

    }

    /**
     * private internal function
     */
    function get() {
        $_SESSION['__notify'];
    }

    /**
     * private internal function
     */
    function showJS() {
        # if this function has already been launch, no need for a second launch
        global $doneJS;
        if ($doneJS) { return; }
        $doneJS = True;
        if (!isset($_SESSION['__notify'])) {
            return;
        }
        echo "<script>\n";
        echo "$('popup').style.width='".$this->getSize()."px';";
        echo "  showPopupCenter('includes/notify.php');";
        echo "</script>\n";
    }


    /**
     * private internal function
     */
    function display() {
        # if this function has already been launch, no need for a second launch
        global $doneDisplay;
        if ($doneDisplay) { return; }
        $doneDisplay = True;
        if (!isset($_SESSION['__notify'])) {
            return;
        }
        echo '<table style="border-width: 0 0 0 0; border-style: none;"><tr style="border-width: 0 0 0 0; border-style: none;"><td style="border-width: 0 0 0 0; border-style: none;">';
        echo '<div id="popupicon" style="float: left;"><img src="'.$this->getImgLevel().'"></div>';
        echo '</td><td style="vertical-align: center; border-width: 0 0 0 0; text-align: justify; width:100%;">';
        foreach ($_SESSION['__notify'] as $info) {
            echo "<p style=\"margin: auto;\">$info</p>";
        }
        echo '<div style="text-align: center; padding-top: 10px">';
        echo '<input name="breset" type="reset" class="btnSecondary" onclick="getStyleObject(\'popup\').display=\'none\'; return false;" value="'._("Ok").'" />';
        echo '</div>';
        echo '</td></tr></table>';
        $this->flush();
    }

    function flush() {
        unset($_SESSION['__notify']);
        unset ($_SESSION['__notify_size']);
        unset ($_SESSION['__notify_level']);
    }
}

/**
 * display a popup window with a message for a successful operation
 *
 */
class NotifyWidgetSuccess extends NotifyWidget {

    function NotifyWidgetSuccess($message) {
        $this->flush();
        $this->add("<div id=\"validCode\">$message</div>");
        $this->setLevel(0);
        $this->setSize(600);
    }

}

/**
 * display a popup window with a message for a failure
 *
 */
class NotifyWidgetFailure extends NotifyWidget {

    function NotifyWidgetFailure($message) {
        $this->flush();
        $this->add("<div id=\"errorCode\">$message</div>");
        $this->setLevel(4);
        $this->setSize(600);
    }

}

/**
 * display a popup window with a message for a warning
 *
 */
class NotifyWidgetWarning extends NotifyWidget {

    function NotifyWidgetWarning($message) {
        $this->flush();
        $this->add("<div id=\"warningCode\">$message</div>");
        $this->setLevel(3);
        $this->setSize(600);
    }
}

/**
 * Display a simple DIV with an error message
 */
class ErrorMessage extends HtmlElement {

    function ErrorMessage($msg) {
        $this->msg = $msg;
    }

    function display() {
        print '<div class="errorCode">' . $this->msg . '</div>';
    }
}

/**
 * Create an URL
 *
 * @param $link string accept format like "module/submod/action" or
 *              "module/submod/action/tab"
 * @param $param assoc array with param to add in GET method
 * @param $ampersandEncode bool defining if we want ampersand to be encoded in URL
 */
function urlStr($link, $param = array(), $ampersandEncode = True) {
    $arr = array();
    $arr = explode ('/',$link);

    if ($ampersandEncode) $amp = "&amp;";
    else $amp = "&";

    $enc_param = "";
    foreach ($param as $key=>$value) {
        $enc_param.= "$amp"."$key=$value";
    }

    if (count($arr) == 3) {
        $ret = "main.php?module=".$arr[0]."$amp"."submod=".$arr[1]."$amp"."action=".$arr[2].$enc_param;
    } else if (count($arr) == 4) {
        $ret = "main.php?module=".$arr[0]."$amp"."submod=".$arr[1]."$amp"."action=".$arr[2]. "$amp" . "tab=" . $arr[3] . $enc_param;
    } else {
        die("Can't build URL");
    }

    return $ret;
}

function urlStrRedirect($link, $param = array()) {
    return(urlStr($link, $param, False));
}

function findInSideBar($sidebar,$query) {
    foreach ($sidebar['content'] as $arr) {
        if (ereg($query,$arr['link'])) {
            return $arr['text'];
        }
    }
}

function findFirstInSideBar($sidebar) {
    return $sidebar['content'][0]['text'];
}


class HtmlElement {

    var $options;

    function HtmlElement() {
        $this->options = array();
    }

    function setOptions($options) {
        $this->options = $options;
    }

    function hasBeenPopped() {
        return True;
    }

    function display() {
        die("Must be implemented by the subclass");
    }

}

class HtmlContainer {

    var $elements;
    var $index;
    var $popped;
    var $debug;

    function HtmlContainer() {
        $this->elements = array();
        $this->popped = False;
        $this->index = -1;
    }

    function begin() {
        die("Must be implemented by the subclass");
    }

    function end() {
        die("Must be implemented by the subclass");
    }

    function display() {
        print "\n" . $this->begin() . "\n";
        foreach($this->elements as $element) $element->display();
        print "\n" . $this->end() . "\n";
    }

    function add($element, $options = array()) {
        $element->setOptions($options);
        $this->push($element);
    }

    function push($element) {
        if ($this->index == -1) {
            /* Add first element to container */
            $this->index++;
            $this->elements[$this->index] = $element;
            //print "pushing " . $element->options["id"] . " into " . $this->options["id"] . "<br>";
        } else {
            if ($this->elements[$this->index]->hasBeenPopped()) {
                /* All the contained elements have been popped, so add the new element in the list */
                $this->index++;
                $this->elements[$this->index] = $element;
                //print "pushing " . $element->options["id"] . " into " . $this->options["id"] . "<br>";
            } else {
                /* Recursively push a new element into the container */
                $this->elements[$this->index]->push($element);
            }
        }
    }

    function hasBeenPopped() {

        if ($this->popped) $ret = True;
        else if ($this->index == -1) $ret = False;
        else $ret = False;
        return $ret;
    }

    function pop() {
        if (!$this->popped) {
            if ($this->index == -1)
                $this->popped = True;
            else if ($this->elements[$this->index]->hasBeenPopped())
                $this->popped = True;
            else $this->elements[$this->index]->pop();
            //if ($this->popped) print "popping " . $this->options["id"] . "<br>";
        } else die("Nothing more to pop");
    }

}


class Div extends HtmlContainer {

    function Div($options = array()) {
        $this->HtmlContainer();
        $this->options = $options;
        $this->display = True;
    }

    function begin() {
        $str = "";
        foreach($this->options as $key => $value) $str.= " $key=\"$value\"";
        if (!$this->display) $displayStyle = ' style =" display: none;"';
        else $displayStyle = "";
        return "<div$str$displayStyle>";
    }

    function end () {
        return "</div>";
    }

    function setVisibility($flag) {
        $this->display = $flag;
    }

}

class Form extends HtmlContainer {

    function Form($options = array()) {
        $this->HtmlContainer();
        if (!isset($options["method"])) $options["method"] = "POST";
        $this->options = $options;
        $this->buttons = array();
        $this->summary = NULL;
    }

    function begin() {
        $str = "";
        foreach($this->options as $key => $value) $str.= " $key=\"$value\"";
        $ret = "<form$str>";
        if (isset($this->summary)) {
            $ret = "<p>" . $this->summary . "</p>\n" . $ret;
        }
        return $ret;
    }

    function end() {
        $str = "";
        foreach($this->buttons as $button) $str .= "\n$button\n";
        $str .= "\n</form>\n";
        return $str;
    }

    function addButton($name, $value, $klass = "btnPrimary", $extra = "", $type = "submit") {
        $b = new Button();
        $this->buttons[] = $b->getButtonString($name, $value, $klass, $extra, $type);
    }

    function addValidateButton($name) {
        $b = new Button();
        $this->buttons[] = $b->getValidateButtonString($name);
    }

    function addCancelButton($name) {
        $b = new Button();
        $this->buttons[] = $b->getCancelButtonString($name, "btnSecondary");
    }

    function addExpertButton($name, $value) {
        $d = new DivExpertMode();
        $b = new Button();
        $this->buttons[] = $d->begin() . $b->getButtonString($name, $value) . $d->end();
    }

    function addSummary($msg) {
        $this->summary = $msg;
    }

    function getButtonString($name, $value, $klass = "btnPrimary", $extra = "", $type = "submit") {
        $b = new Button();
        return $b->getButtonString($name, $value, $klass, $extra, $type);
    }

    function addOnClickButton($text, $url) {
        $b = new Button();
        $this->buttons[] = $b->getOnClickButton($text, $url);
    }
}

class Button {
    function Button($module = null, $submod = null, $action = null) { # TODO also verify ACL on tabs
        if ($module == null) {
            $this->module = $_GET["module"];
        } else {
            $this->module = $module;
        }
        if ($submod == null) {
            $this->submod = $_GET["submod"];
        } else {
            $this->submod = $submod;
        }
        if ($action == null) {
            $this->action = $_GET["action"];
        } else {
            $this->action = $action;
        }
    }

    function getButtonString($name, $value, $klass = "btnPrimary", $extra = "", $type = "submit") {
        if (hasCorrectAcl($this->module,$this->submod,$this->action)) {
            return $this->getButtonStringWithRight($name, $value, $klass, $extra, $type);
        } else {
            return $this->getButtonStringWithNoRight($name, $value, $klass, $extra, $type);
        }
    }

    function getButtonStringWithRight($name, $value, $klass = "btnPrimary", $extra = "", $type = "submit") {
        return "<input type=\"$type\" name=\"$name\" value=\"$value\" class=\"$klass\" $extra />";
    }
    function getButtonStringWithNoRight($name, $value, $klass = "btnPrimary", $extra = "", $type = "submit") {
        return "<input disabled type=\"$type\" name=\"$name\" value=\"$value\" class=\"btnDisabled\" $extra />";
    }

    function getValidateButtonString($name, $klass = "btnPrimary", $extra = "", $type = "submit") {
        return $this->getButtonString($name, _("Confirm"));
    }

    function getCancelButtonString($name, $klass = "btnPrimary", $extra = "", $type = "submit") {
        return $this->getButtonString($name, _("Cancel"));
    }

    function getOnClickButton($text, $url, $klass = "btnPrimary", $extra = "", $type = "button") {
        return $this->getButtonString("onclick", $text, $klass, $extra = "onclick=\"location.href='" . $url . "';\"", $type);
    }
}

class ValidatingForm extends Form {

    function ValidatingForm($options = array()) {
        $this->Form($options);
        $this->options["id"] = "edit";
        $this->options["onsubmit"] = "selectAll(); return validateForm();";
    }

    function end() {
        $str = parent::end();
        $str .= "
        <script type=\"text/javascript\">
            if(Form.findFirstElement(\"".$this->options["id"]."\")) {
                Form.focusFirstElement(\"".$this->options["id"]."\");
            }
        </script>\n";
        return $str;
    }

}

/**
 *
 * Allow to easily build the little popup displayed when deleting a user for example
 *
 */
class PopupForm extends Form {

    function PopupForm($title) {
        $options = array("action" => $_SERVER["REQUEST_URI"]);
        $this->Form($options);
        $this->title = $title;
        $this->text = array();
        $this->ask = "";
    }

    function begin() {
        $str = "<h2>" . $this->title . "</h2>\n";
        $str .= parent::begin();
        foreach($this->text as $text)
            $str .= "<p>" . $text . "</p>";
        return $str;
    }

    function end() {
        $str = "<p>" . $this->ask . "</p>";
        $str .= parent::end();
        return $str;
    }

    function addText($msg) {
        $this->text[] = $msg;
    }

    function setQuestion($msg) {
        $this->ask = $ask;
    }

    function addValidateButtonWithFade($name) {
        $this->buttons[] = $this->getButtonString($name, _("Confirm"), "btnPrimary", "onclick=\"new Effect.Fade('popup'); return true;\"" );
    }

    function addCancelButton($name) {
        $this->buttons[] = $this->getButtonString($name, _("Cancel"), "btnSecondary", "onclick=\"new Effect.Fade('popup'); return false;\"" );
    }

}

/**
 *
 * Allow to easily build the little popup, summon a new window
 *
 */
class PopupWindowForm extends PopupForm {

    function PopupWindowForm($title) {
        $options = array("action" => $_SERVER["REQUEST_URI"]);
        $this->PopupForm($options);
        $this->title = $title;
        $this->text = array();
        $this->ask = "";
        $this->target_uri = "";
    }

    function addValidateButtonWithFade($name) {
        $this->buttons[] = $this->getButtonString($name, _("Confirm"), "btnPrimary", "onclick=\"new Effect.Fade('popup'); window.open('".$this->target_uri."', '', 'toolbar=no, location=no, menubar=no, status=no, status=no, scrollbars=no, width=330, height=200'); return false;\"" );
    }
}

class Table extends HtmlContainer {

    function Table($options = array()) {
        $this->HtmlContainer();
        $this->lines = array();
        $this->tr_style = '';
        $this->td_style = '';
        $this->options = $options;
        if (isset($options['tr_style'])) { $this->tr_style = $options['tr_style']; }
        if (isset($options['td_style'])) { $this->td_style = $options['td_style']; }
    }

    function setLines($lines) {
        $this->lines = $lines;
    }

    function begin() {
        return '<table cellspacing="0">';
    }

    function end() {
        return "</table>";
    }

    function getContent() {
        $str = '';
        foreach ($this->lines as $line) {
            $str .= sprintf("<tr%s><td%s>%s</td></tr>", $this->tr_style, $this->td_style, implode(sprintf('</td><td%s>', $this->td_style), $line));
        }
        return $str;
    }

    function displayTable($displayContent = False) {
        print $this->begin();
        if ($displayContent) {
            print $this->getContent();
        }
        print $this->end();
    }

}

class DivForModule extends Div {

    function DivForModule($title, $color, $options = array()) {
        $options["style"] = "background-color: " . $color;
        $options["class"] = "formblock";
        $this->Div($options);
        $this->title = $title;
        $this->color = $color;
    }

    function begin() {
        print parent::begin();
        print "<h3>" . $this->title . "</h3>";
    }
}

class DivExpertMode extends Div {

    function begin() {
        $str = '<div id="expertMode" ';
        if (isExpertMode()) {
            $str .= ' style="display: inline;"';
        } else {
            $str .= ' style="display: none;"';
        }
        return $str . ' >';
    }

}

class ModuleTitleElement extends HtmlElement{

    function ModuleTitleElement($title){
        $this->title=$title;
    }

    function display(){
        print '<br><h1>'.$this->title.'</h1>';
    }
}

class TitleElement extends HtmlElement {
    function TitleElement($title, $level = 2){
        $this->title=$title;
        $this->level = $level;
    }
    function display(){
        print '<br/><h'.$this->level.'>'.$this->title.'</h'.$this->level.'>';
    }
}

class SelectElement extends HtmlElement{

    function SelectElement($name, $nametab){
        $this->name = $name;
        $this->nametab = $nametab;
    }

    function display() {
        print '<a href="javascript:void(0);" onclick="checkAll(\''.$this->name.'\',1);checkAll(\''.$this->nametab.'\',1);">'._("Select all").' </a> / ';
        print '<a href="javascript:void(0);" onclick="checkAll(\''.$this->name.'\',0);checkAll(\''.$this->nametab.'\',0);">'._("Unselect all").'</a><br/>';
    }
}

class TrTitleElement extends HtmlElement{

        function TrTitleElement($arrtitles){
            $this->titles=$arrtitles;
        }

        function display(){
            $colsize=100/sizeof($this->titles);
            print '<tr>';
            foreach( $this->titles as $value ){
                    print '<td width="'.$colsize.'%"><b>'.$value.'</b></td>';
            }
            print '</tr>';
        }
}

?>
Back to Top