C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\rodam\includes\joomla.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
<?php
/**
* @version $Id: joomla.php 2599 2006-02-24 07:49:49Z stingrey $
* @package Joomla
* @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// no direct access
defined'_VALID_MOS' ) or die( 'Restricted access' );
define'_MOS_MAMBO_INCLUDED');

/**
 * Page generation time
 * @package Joomla
 */
class mosProfiler {
    
/** @var int Start time stamp */
    
var $start=0;
    
/** @var string A prefix for mark messages */
    
var $prefix='';

    
/**
     * Constructor
     * @param string A prefix for mark messages
     */
    
function mosProfiler$prefix='' ) {
        
$this->start $this->getmicrotime();
        
$this->prefix $prefix;
    }

    
/**
     * @return string A format message of the elapsed time
     */
    
function mark$label ) {
        return 
sprintf "\n<div class=\"profiler\">$this->prefix %.3f $label</div>"$this->getmicrotime() - $this->start );
    }

    
/**
     * @return float The current time in milliseconds
     */
    
function getmicrotime(){
        list(
$usec$sec) = explode(" ",microtime());
        return ((float)
$usec + (float)$sec);
    }
}

if (
phpversion() < '4.2.0') {
    require_once( 
dirname__FILE__ ) . '/compat.php41x.php' );
}
if (
phpversion() < '4.3.0') {
    require_once( 
dirname__FILE__ ) . '/compat.php42x.php' );
}
if (
version_comparephpversion(), '5.0' ) < 0) {
    require_once( 
dirname__FILE__ ) . '/compat.php50x.php' );
}

@
set_magic_quotes_runtime);

if (@
$mosConfig_error_reporting === 0) {
    
error_reporting);
} else if (@
$mosConfig_error_reporting 0) {
    
error_reporting$mosConfig_error_reporting );
}

require_once( 
$mosConfig_absolute_path '/includes/version.php' );
require_once( 
$mosConfig_absolute_path '/includes/database.php' );
require_once( 
$mosConfig_absolute_path '/includes/gacl.class.php' );
require_once( 
$mosConfig_absolute_path '/includes/gacl_api.class.php' );
require_once( 
$mosConfig_absolute_path '/includes/phpmailer/class.phpmailer.php' );
require_once( 
$mosConfig_absolute_path '/includes/joomla.xml.php' );
require_once( 
$mosConfig_absolute_path '/includes/phpInputFilter/class.inputfilter.php' );

$database = new database$mosConfig_host$mosConfig_user$mosConfig_password$mosConfig_db$mosConfig_dbprefix );
if (
$database->getErrorNum()) {
    
$mosSystemError $database->getErrorNum();
    
$basePath dirname__FILE__ );
    include 
$basePath '/../configuration.php';
    include 
$basePath '/../offline.php';
    exit();
}
$database->debug$mosConfig_debug );
$acl = new gacl_api();

/**
 * @package Joomla
 * @abstract
 */
class mosAbstractLog {
    
/** @var array */
    
var $_log    null;

    
/**
     * Constructor
     */
    
function mosAbstractLog() {
        
$this->__constructor();
    }

    
/**
     * Generic constructor
     */
    
function __constructor() {
        
$this->_log = array();
    }

    
/**
     * @param string Log message
     * @param boolean True to append to last message
     */
    
function log$text$append=false ) {
        
$n count$this->_log );
        if (
$append && $n 0) {
            
$this->_log[count$this->_log )-1] .= $text;
        } else {
            
$this->_log[] = $text;
        }
    }

    
/**
     * @param string The glue for each log item
     * @return string Returns the log
     */
    
function getLog$glue='<br/>'$truncate=9000$htmlSafe=false ) {
        
$logs = array();
        foreach (
$this->_log as $log) {
            if (
$htmlSafe) {
                
$log htmlspecialchars$log );
            }
            
$logs[] = substr$log0$truncate );
        }
        return  
implode$glue$logs );
    }
}

/**
 * Task routing class
 * @package Joomla
 * @abstract
 */
class mosAbstractTasker {
    
/** @var array An array of the class methods to call for a task */
    
var $_taskMap     null;
    
/** @var string The name of the current task*/
    
var $_task         null;
    
/** @var array An array of the class methods*/
    
var $_methods     null;
    
/** @var string A url to redirect to */
    
var $_redirect     null;
    
/** @var string A message about the operation of the task */
    
var $_message     null;

    
// action based access control

    /** @var string The ACO Section */
    
var $_acoSection         null;
    
/** @var string The ACO Section value */
    
var $_acoSectionValue     null;

    
/**
     * Constructor
     * @param string Set the default task
     */
    
function mosAbstractTasker$default='' ) {
        
$this->_taskMap = array();
        
$this->_methods = array();
        foreach (
get_class_methodsget_class$this ) ) as $method) {
            if (
substr$method0) != '_') {
                
$this->_methods[] = strtolower$method );
                
// auto register public methods as tasks
                
$this->_taskMap[strtolower$method )] = $method;
            }
        }
        
$this->_redirect '';
        
$this->_message '';
        if (
$default) {
            
$this->registerDefaultTask$default );
        }
    }

    
/**
     * Sets the access control levels
     * @param string The ACO section (eg, the component)
     * @param string The ACO section value (if using a constant value)
     */
    
function setAccessControl$section$value=null ) {
        
$this->_acoSection $section;
        
$this->_acoSectionValue $value;
    }
    
/**
     * Access control check
     */
    
function accessCheck$task ) {
        global 
$acl$my;

        
// only check if the derived class has set these values
        
if ($this->_acoSection) {
            
// ensure user has access to this function
            
if ($this->_acoSectionValue) {
                
// use a 'constant' task for this task handler
                
$task $this->_acoSectionValue;
            }
            return 
$acl->acl_check$this->_acoSection$task'users'$my->usertype );
        } else {
            return 
true;
        }
    }

    
/**
     * Set a URL to redirect the browser to
     * @param string A URL
     */
    
function setRedirect$url$msg null ) {
        
$this->_redirect $url;
        if (
$msg !== null) {
            
$this->_message $msg;
        }
    }
    
/**
     * Redirects the browser
     */
    
function redirect() {
        if (
$this->_redirect) {
            
mosRedirect$this->_redirect$this->_message );
        }
    }
    
/**
     * Register (map) a task to a method in the class
     * @param string The task
     * @param string The name of the method in the derived class to perform for this task
     */
    
function registerTask$task$method ) {
        if (
in_arraystrtolower$method ), $this->_methods )) {
            
$this->_taskMap[strtolower$task )] = $method;
        } else {
            
$this->methodNotFound$method );
        }
    }
    
/**
     * Register the default task to perfrom if a mapping is not found
     * @param string The name of the method in the derived class to perform if the task is not found
     */
    
function registerDefaultTask$method ) {
        
$this->registerTask'__default'$method );
    }
    
/**
     * Perform a task by triggering a method in the derived class
     * @param string The task to perform
     * @return mixed The value returned by the function
     */
    
function performTask$task ) {
        
$this->_task $task;

        
$task strtolower$task );
        if (isset( 
$this->_taskMap[$task] )) {
            
$doTask $this->_taskMap[$task];
        } else if (isset( 
$this->_taskMap['__default'] )) {
            
$doTask $this->_taskMap['__default'];
        } else {
            return 
$this->taskNotFound$this->_task );
        }

        if (
$this->accessCheck$doTask )) {
            return 
call_user_func( array( &$this$doTask ) );
        } else {
            return 
$this->notAllowed$task );
        }
    }
    
/**
     * Get the last task that was to be performed
     * @return string The task that was or is being performed
     */
    
function getTask() {
        return 
$this->_task;
    }
    
/**
     * Basic method if the task is not found
     * @param string The task
     * @return null
     */
    
function taskNotFound$task ) {
        echo 
'Task ' $task ' not found';
        return 
null;
    }
    
/**
     * Basic method if the registered method is not found
     * @param string The name of the method in the derived class
     * @return null
     */
    
function methodNotFound$name ) {
        echo 
'Method ' $name ' not found';
        return 
null;
    }
    
/**
     * Basic method if access is not permitted to the task
     * @param string The name of the method in the derived class
     * @return null
     */
    
function notAllowed$name ) {
        echo 
_NOT_AUTH;

        return 
null;
    }
}


/**
* Class to support function caching
* @package Joomla
*/
class mosCache {
    
/**
    * @return object A function cache object
    */
    
function &getCache(  $group=''  ) {
        global 
$mosConfig_absolute_path$mosConfig_caching$mosConfig_cachepath$mosConfig_cachetime;

        require_once( 
$mosConfig_absolute_path '/includes/Cache/Lite/Function.php' );

        
$options = array(
            
'cacheDir'         => $mosConfig_cachepath '/',
            
'caching'         => $mosConfig_caching,
            
'defaultGroup'     => $group,
            
'lifeTime'         => $mosConfig_cachetime
        
);
        
$cache = new Cache_Lite_Function$options );
        return 
$cache;
    }
    
/**
    * Cleans the cache
    */
    
function cleanCache$group=false ) {
        global 
$mosConfig_caching;
        if (
$mosConfig_caching) {
            
$cache =& mosCache::getCache$group );
            
$cache->clean$group );
        }
    }
}
/**
* Joomla! Mainframe class
*
* Provide many supporting API functions
* @package Joomla
*/
class mosMainFrame {
    
/** @var database Internal database class pointer */
    
var $_db                        null;
    
/** @var object An object of configuration variables */
    
var $_config                    null;
    
/** @var object An object of path variables */
    
var $_path                        null;
    
/** @var mosSession The current session */
    
var $_session                    null;
    
/** @var string The current template */
    
var $_template                    null;
    
/** @var array An array to hold global user state within a session */
    
var $_userstate                    null;
    
/** @var array An array of page meta information */
    
var $_head                        null;
    
/** @var string Custom html string to append to the pathway */
    
var $_custom_pathway            null;
    
/** @var boolean True if in the admin client */
    
var $_isAdmin                     false;    
    

    
/**
    * Class constructor
    * @param database A database connection object
    * @param string The url option
    * @param string The path of the mos directory
    */
    
function mosMainFrame( &$db$option$basePath$isAdmin=false ) {
        
$this->_db =& $db;

        
// load the configuration values
        
$this->_setTemplate$isAdmin );
        
$this->_setAdminPaths$option$this->getCfg'absolute_path' ) );
        if (isset( 
$_SESSION['session_userstate'] )) {
            
$this->_userstate =& $_SESSION['session_userstate'];
        } else {
            
$this->_userstate null;
        }
        
$this->_head = array();
        
$this->_head['title']     = $GLOBALS['mosConfig_sitename'];
        
$this->_head['meta']     = array();
        
$this->_head['custom']     = array();

        
//set the admin check
        
$this->_isAdmin         = (boolean) $isAdmin;
    }

    
/**
     * Gets the id number for a client
     * @param mixed A client identifier
     */
    
function getClientID$client ) {
        switch (
$client) {
            case 
'2':
            case 
'installation':
                return 
2;
                break;

            case 
'1':
            case 
'admin':
            case 
'administrator':
                return 
1;
                break;

            case 
'0':
            case 
'site':
            case 
'front':
            default:
                return 
0;
                break;
        }
    }

    
/**
     * Gets the client name
     * @param int The client identifier
     * @return strint The text name of the client
     */
    
function getClientName$client_id ) {
         
// do not translate
        
$clients = array( 'site''admin''installer' );
        return 
mosGetParam$clients$client_id'unknown' );
    }

    
/**
     * Gets the base path for the client
     * @param mixed A client identifier
     * @param boolean True (default) to add traling slash
     */
    
function getBasePath$client=0$addTrailingSlash=true ) {
        global 
$mosConfig_absolute_path;

        switch (
$client) {
            case 
'0':
            case 
'site':
            case 
'front':
            default:
                return 
mosPathName$mosConfig_absolute_path$addTrailingSlash );
                break;

            case 
'2':
            case 
'installation':
                return 
mosPathName$mosConfig_absolute_path '/installation'$addTrailingSlash );
                break;

            case 
'1':
            case 
'admin':
            case 
'administrator':
                return 
mosPathName$mosConfig_absolute_path '/administrator'$addTrailingSlash );
                break;

        }
    }

    
/**
    * @param string
    */
    
function setPageTitle$title=null ) {
        if (@
$GLOBALS['mosConfig_pagetitles']) {
            
$title trimhtmlspecialchars$title ) );
            
$this->_head['title'] = $title $GLOBALS['mosConfig_sitename'] . ' - '$title $GLOBALS['mosConfig_sitename'];
        }
    }
    
/**
    * @param string The value of the name attibute
    * @param string The value of the content attibute
    * @param string Text to display before the tag
    * @param string Text to display after the tag
    */
    
function addMetaTag$name$content$prepend=''$append='' ) {
        
$name trimhtmlspecialchars$name ) );
        
$content trimhtmlspecialchars$content ) );
        
$prepend trim$prepend );
        
$append trim$append );
        
$this->_head['meta'][] = array( $name$content$prepend$append );
    }
    
/**
    * @param string The value of the name attibute
    * @param string The value of the content attibute to append to the existing
    * Tags ordered in with Site Keywords and Description first
    */
    
function appendMetaTag$name$content ) {
        
$name trimhtmlspecialchars$name ) );
        
$n count$this->_head['meta'] );
        for (
$i 0$i $n$i++) {
            if (
$this->_head['meta'][$i][0] == $name) {
                
$content trimhtmlspecialchars$content ) );
                if ( 
$content ) {
                    if ( !
$this->_head['meta'][$i][1] ) {
                        
$this->_head['meta'][$i][1] = $content ;
                    } else {
                        
$this->_head['meta'][$i][1] = $content .', '$this->_head['meta'][$i][1];
                    }
                }
                return;
            }
        }
        
$this->addMetaTag$name $content );
    }

    
/**
    * @param string The value of the name attibute
    * @param string The value of the content attibute to append to the existing
    */
    
function prependMetaTag$name$content ) {
        
$name trimhtmlspecialchars$name ) );
        
$n count$this->_head['meta'] );
        for (
$i 0$i $n$i++) {
            if (
$this->_head['meta'][$i][0] == $name) {
                
$content trimhtmlspecialchars$content ) );
                
$this->_head['meta'][$i][1] = $content $this->_head['meta'][$i][1];
                return;
            }
        }
        
$this->addMetaTag$name$content );
    }
    
/**
     * Adds a custom html string to the head block
     * @param string The html to add to the head
     */
    
function addCustomHeadTag$html ) {
        
$this->_head['custom'][] = trim$html );
    }
    
/**
    * @return string
    */
    
function getHead() {
        
$head = array();
        
$head[] = '<title>' $this->_head['title'] . '</title>';
        foreach (
$this->_head['meta'] as $meta) {
            if (
$meta[2]) {
                
$head[] = $meta[2];
            }
            
$head[] = '<meta name="' $meta[0] . '" content="' $meta[1] . '" />';
            if (
$meta[3]) {
                
$head[] = $meta[3];
            }
        }
        foreach (
$this->_head['custom'] as $html) {
            
$head[] = $html;
        }
        return 
implode"\n"$head ) . "\n";
    }
    
/**
    * @return string
    */
    
function getPageTitle() {
        return 
$this->_head['title'];
    }

    
/**
    * @return string
    */
    
function getCustomPathWay() {
        return 
$this->_custom_pathway;
    }

    function 
appendPathWay$html ) {
    
$this->_custom_pathway[] = $html;
  }

  
/**
    * Gets the value of a user state variable
    * @param string The name of the variable
    */
    
function getUserState$var_name ) {
        if (
is_array$this->_userstate )) {
            return 
mosGetParam$this->_userstate$var_namenull );
        } else {
            return 
null;
        }
    }
    
/**
    * Gets the value of a user state variable
    * @param string The name of the user state variable
    * @param string The name of the variable passed in a request
    * @param string The default value for the variable if not found
    */
    
function getUserStateFromRequest$var_name$req_name$var_default=null ) {
        if (
is_array$this->_userstate )) {
            if (isset( 
$_REQUEST[$req_name] )) {
                
$this->setUserState$var_name$_REQUEST[$req_name] );
            } else if (!isset( 
$this->_userstate[$var_name] )) {
                
$this->setUserState$var_name$var_default );
            }            
            return 
$this->_userstate[$var_name];
        } else {
            return 
null;
        }
    }
    
/**
    * Sets the value of a user state variable
    * @param string The name of the variable
    * @param string The value of the variable
    */
    
function setUserState$var_name$var_value ) {
        if (
is_array$this->_userstate )) {
            
$this->_userstate[$var_name] = $var_value;
        }
    }
    
/**
    * Initialises the user session
    *
    * Old sessions are flushed based on the configuration value for the cookie
    * lifetime. If an existing session, then the last access time is updated.
    * If a new session, a session id is generated and a record is created in
    * the jos_sessions table.
    */
    
function initSession() {
        
// initailize session variables
        
$session     =& $this->_session;
        
$session     = new mosSession$this->_db );
        
        
// purge expired frontend logged sessions only - expiry time set in Global Config
        
$and         "\n AND guest = 0 \n AND gid > 0";
        
$session->purge(intval$this->getCfg'lifetime' ) ), $and );
        
// purge expired frontend guest sessions only - expire time fixed at 15 mins
        
$and         "\n AND guest = 1 \n AND userid = 0";
        
$session->purge900$and );

        
// Session Cookie `name`
        
$sessionCookieName     mosMainFrame::sessionCookieName();
        
// Get Session Cookie `value`
        
$sessioncookie         mosGetParam$_COOKIE$sessionCookieNamenull );
        
        
// Session ID / `value`
        
$sessionValueCheck     mosMainFrame::sessionCookieValue$sessioncookie );
        
//echo mosMakePassword(32);
        // Check if existing session exists in db corresponding to Session cookie `value` 
        // extra check added in 1.0.8 to test sessioncookie value is of correct length
        
if ( $sessioncookie && strlen($sessioncookie) == 32 && $sessioncookie != '-' && $session->load($sessionValueCheck) ) {
            
// update time in session table
            
$session->time time();
            
$session->update();
        } else {
            
// Remember Me Cookie `name`
            
$remCookieName mosMainFrame::remCookieName_User();
            
            
// test if cookie found
            
$cookie_found false;
            if ( isset(
$_COOKIE[$sessionCookieName]) || isset($_COOKIE[$remCookieName]) || isset($_POST['force_session']) ) {
                
$cookie_found true;
            }
            
            
// check if neither remembermecookie or sessioncookie found
            
if (!$cookie_found) {
                
// create sessioncookie and set it to a test value set to expire on session end
                
setcookie$sessionCookieName'-'false'/' );                
            } else {
            
// otherwise, sessioncookie was found, but set to test val or the session expired, prepare for session registration and register the session
                
$session->guest     1;
                
$session->username     '';
                
$session->time         time();
                
$session->gid         0;
                
// Generate Session Cookie `value`
                
$session->generateId();

                if (!
$session->insert()) {
                    die( 
$session->getError() );
                }
                
                
// create Session Tracking Cookie set to expire on session end
                
setcookie$sessionCookieName$session->getCookie(), false'/' );
            }

            
// Cookie used by Remember me functionality
            
$remCookieValue    mosGetParam$_COOKIE$remCookieNamenull );
            
            
// test if cookie is correct length            
            
if ( strlen($remCookieValue) == 64 ) {
                
// Separate Values from Remember Me Cookie
                
$remUser    substr$remCookieValue032 );
                
$remPass    substr$remCookieValue3232 );

                
// check if Remember me cookie exists. Login with usercookie info.
                
if ( strlen($remUser) == 32 && strlen($remPass) == 32 ) {
                    
$this->login$remUser$remPass);
                }
            }
        }
    }
    
    
/*
    * Function used to conduct admin session duties
    * Added as of 1.0.8
    * Deperciated 1.1
    */
    
function initSessionAdmin($option) {    
        global 
$_VERSION;
        
        
// logout check
        
if ($option == 'logout') {
            require 
'logout.php';
            exit();
        }
        
        
$site            $this->getCfg'live_site' );
        
        
// check if session name corresponds to correct format
        
if ( session_name() != md5$site ) ) {
            echo 
"<script>document.location.href='$site/administrator/index.php'</script>\n";
            exit();
        }

        
// restore some session variables
        
$my             = new mosUser$this->_db );
        
$my->id         mosGetParam$_SESSION'session_user_id''' );
        
$my->username     mosGetParam$_SESSION'session_username''' );
        
$my->usertype     mosGetParam$_SESSION'session_usertype''' );
        
$my->gid         mosGetParam$_SESSION'session_gid''' );
        
$my->params        mosGetParam$_SESSION'session_user_params''' );

        
$session_id     mosGetParam$_SESSION'session_id''' );
        
$logintime         mosGetParam$_SESSION'session_logintime''' );
        
        
// set garbage cleaning timeout
        
$this->setSessionGarbageClean();
        
        
// check against db record of session
        
if ( $session_id == md5$my->id $my->username $my->usertype $logintime ) ) {
            
// check to see if site is a production site
            // allows multiple logins with same user for a demo site
            
if ( $_VERSION->SITE ) {
                
$query "SELECT COUNT( session_id )"
                
"\n FROM #__session"
                
"\n WHERE session_id = '$session_id'"
                
"\n AND username = "$this->_db->Quote$my->username )
                . 
"\n AND userid = "intval$my->id )
                ;
                
$this->_db->setQuery$query );
                
$count $this->_db->loadResult();
                
                
// if no entry in session table that corresponds disallow login
                
if ( $count == ) {
                    echo 
"<script>document.location.href='index.php'</script>\n";
                    exit();
                }
            }
        } else {
        
// session id does not correspond to required session format
            
echo "<script>document.location.href='$site/administrator/index.php'</script>\n";
            exit();
        }
        
        
// update session timestamp
        
$current_time time();
        
$query "UPDATE #__session"
        
"\n SET time = '$current_time'"
        
"\n WHERE session_id = '$session_id'"
        
;
        
$this->_db->setQuery$query );
        
$this->_db->query();
        
        
// purge expired admin sessions only        
        
$past time() - $this->getCfg'session_life_admin' );
        
$query "DELETE FROM #__session"
        
"\n WHERE time < '$past'"
        
"\n AND guest = 1"
        
"\n AND gid = 0"
        
"\n AND userid <> 0"
        
;
        
$this->_db->setQuery$query );
        
$this->_db->query();    

        return 
$my;
    }
    
    
/*
    * Function used to set Session Garbage Cleaning
    * garbage cleaning set at configured session time + 600 seconds
    * Added as of 1.0.8
    * Deperciated 1.1
    */
    
function setSessionGarbageClean() {
        
/** ensure that funciton is only called once */
        
if (!defined'_JOS_GARBAGECLEAN' )) {
            
define'_JOS_GARBAGECLEAN');
            
            
$garbage_timeout $this->getCfg('session_life_admin') + 600;
            
ini_set('session.gc_maxlifetime'$garbage_timeout);
        }
    }
    
    
/*
    * Static Function used to generate the Session Cookie Name
    * Added as of 1.0.8
    * Deperciated 1.1
    */
    
function sessionCookieName() {
        global 
$mainframe;
        
        return 
md5'site' $mainframe->getCfg'live_site' ) );        
    }
    
    
/*
    * Static Function used to generate the Session Cookie Value
    * Added as of 1.0.8
    * Deperciated 1.1
    */
    
function sessionCookieValue$id=null ) {
        global 
$mainframe;        
    
        
$type         $mainframe->getCfg'session_type' );
        
        
$browser     = @$_SERVER['HTTP_USER_AGENT'];
        
        switch (
$type) {
            case 
2:
            
// 1.0.0 to 1.0.7 Compatibility
            // lowest level security
                
$value             md5$id $_SERVER['REMOTE_ADDR'] );
                break;

            case 
1:
            
// slightly reduced security - 3rd level IP authentication for those behind IP Proxy 
                
$remote_addr     explode('.',$_SERVER['REMOTE_ADDR']);
                
$ip                $remote_addr[0] .'.'$remote_addr[1] .'.'$remote_addr[2];
                
$value             mosHash$id $ip $browser );
                break;
            
            default:
            
// Highest security level - new default for 1.0.8 and beyond
                
$ip                $_SERVER['REMOTE_ADDR'];
                
$value             mosHash$id $ip $browser );
                break;
        }        

        return 
$value;
    }
    
    
/*
    * Static Function used to generate the Rememeber Me Cookie Name for Username information
    * Added as of 1.0.8
    * Depreciated 1.1
    */
    
function remCookieName_User() {
        
$value mosHash'remembermecookieusername'mosMainFrame::sessionCookieName() );

        return 
$value;
    }
    
    
/*
    * Static Function used to generate the Rememeber Me Cookie Name for Password information
    * Added as of 1.0.8
    * Depreciated 1.1
    */
    
function remCookieName_Pass() {
        
$value mosHash'remembermecookiepassword'mosMainFrame::sessionCookieName() );

        return 
$value;
    }
    
    
/*
    * Static Function used to generate the Remember Me Cookie Value for Username information
    * Added as of 1.0.8
    * Depreciated 1.1
    */
    
function remCookieValue_User$username ) {
        
$value md5$username mosHash( @$_SERVER['HTTP_USER_AGENT'] ) );

        return 
$value;
    }
    
    
/*
    * Static Function used to generate the Remember Me Cookie Value for Password information
    * Added as of 1.0.8
    * Depreciated 1.1
    */
    
function remCookieValue_Pass$passwd ) {
        
$value     md5$passwd mosHash( @$_SERVER['HTTP_USER_AGENT'] ) );
        
        return 
$value;
    }
    
    
/**
    * Login validation function
    *
    * Username and encoded password is compare to db entries in the jos_users
    * table. A successful validation updates the current session record with
    * the users details.
    */
    
function login$username=null,$passwd=null$remember=null ) {
        global 
$acl$_VERSION;
        
        
// if no username and password passed from function, then function is being called from login module/component
        
if (!$username || !$passwd) {
            
$username     strvalmosGetParam$_POST'username''' ) );
            
$passwd     mosGetParam$_POST'passwd''' );
            
$passwd     md5$passwd );
            
$bypost     1;
        }

        if (!
$username || !$passwd) {
            echo 
"<script> alert(\""._LOGIN_INCOMPLETE."\"); window.history.go(-1); </script>\n";
            exit();
        } else {
            if ( 
$remember && strlen($username) == 32 && strlen($passwd) == 32 ) {
            
// query used for remember me cookie
                
$harden mosHash( @$_SERVER['HTTP_USER_AGENT'] );

                
$query "SELECT *"
                
"\n FROM #__users"
                
"\n WHERE block != 1"
                
"\n AND MD5( CONCAT( username , '$harden' ) ) = '$username'"
                
"\n AND MD5( CONCAT( password , '$harden' ) ) = '$passwd'"
                
;
            } else {
            
// query used for normal login
                
$query "SELECT *"
                
"\n FROM #__users"
                
"\n WHERE block != 1"
                
"\n AND username = '$username'"
                
"\n AND password = '$passwd'"
                
;
            }
            
$this->_db->setQuery$query );
            
$row null;
            
            if (
$this->_db->loadObject$row )) {
                
// user blocked from login
                
if ($row->block == 1) {
                    
mosErrorAlert(_LOGIN_BLOCKED);
                }
                
                
// fudge the group stuff
                
$grp $acl->getAroGroup$row->id );
                
$row->gid 1;
                if (
$acl->is_group_child_of$grp->name'Registered''ARO' ) || $acl->is_group_child_of$grp->name'Public Backend''ARO' )) {
                    
// fudge Authors, Editors, Publishers and Super Administrators into the Special Group
                    
$row->gid 2;
                }
                
$row->usertype $grp->name;

                
// initialize session data
                
$session             =& $this->_session;
                
$session->guest     0;
                
$session->username     $row->username;
                
$session->userid     intval$row->id );
                
$session->usertype     $row->usertype;
                
$session->gid         intval$row->gid );
                
$session->update();
                
                
// check to see if site is a production site
                // allows multiple logins with same user for a demo site
                
if ( $_VERSION->SITE ) {
                    
// delete any old front sessions to stop duplicate sessions
                    
$query "DELETE FROM #__session"
                    
"\n WHERE session_id != '$session->session_id'"
                    
"\n AND username = '$row->username'"
                    
"\n AND userid = $row->id"
                    
"\n AND gid = $row->gid"
                    
"\n AND guest = 0"
                    
;
                    
$this->_db->setQuery$query );
                    
$this->_db->query();    
                }
                
                
// update user visit data
                
$currentDate date("Y-m-d\TH:i:s");
                
$query "UPDATE #__users"
                
"\n SET lastvisitDate = '$currentDate'"
                
"\n WHERE id = $session->userid"
                
;
                
$this->_db->setQuery($query);
                if (!
$this->_db->query()) {
                    die(
$this->_db->stderr(true));
                }

                
// set remember me cookie if selected
                
$remember mosGetParam$_POST'remember''' );
                if ( 
$remember == 'yes' ) {
                    
// cookie lifetime of 365 days
                    
$lifetime         time() + 365*24*60*60;
                    
$remCookieName     mosMainFrame::remCookieName_User();
                    
$remCookieValue mosMainFrame::remCookieValue_User$row->username ) . mosMainFrame::remCookieValue_Pass$row->password );
                    
setcookie$remCookieName$remCookieValue$lifetime'/' );
                }
                
mosCache::cleanCache();
            } else {
                if (isset(
$bypost)) {
                    
mosErrorAlert(_LOGIN_INCORRECT);
                } else {
                    
$this->logout();
                    
mosRedirect('index.php');
                }
                exit();
            }
        }
    }
    
    
/**
    * User logout
    *
    * Reverts the current session record back to 'anonymous' parameters
    */
    
function logout() {
        
mosCache::cleanCache();
        
        
$session             =& $this->_session;
        
$session->guest     1;
        
$session->username     '';
        
$session->userid     '';
        
$session->usertype     '';
        
$session->gid         0;

        
$session->update();

        
// kill remember me cookie
        
$lifetime         time() - 86400;
        
$remCookieName     mosMainFrame::remCookieName_User();
        
setcookie$remCookieName' '$lifetime'/' );
        
        @
session_destroy();
    }
    
    
/**
    * @return mosUser A user object with the information from the current session
    */
    
function getUser() {
        global 
$database;

        
$user = new mosUser$this->_db );

        
$user->id             intval$this->_session->userid );
        
$user->username     $this->_session->username;
        
$user->usertype     $this->_session->usertype;
        
$user->gid             intval$this->_session->gid );

        if (
$user->id) {
            
$query "SELECT params"
            
"\n FROM #__users"
            
"\n WHERE id = "intval$user->id )
            ;
            
$database->setQuery$query );
            
$params $database->loadResult();
        } else {
            
$params '';
        }
        
$user->params $params;

        return 
$user;
    }
    
/**
     * @param string The name of the variable (from configuration.php)
     * @return mixed The value of the configuration variable or null if not found
     */
    
function getCfg$varname ) {
        
$varname 'mosConfig_' $varname;
        if (isset( 
$GLOBALS[$varname] )) {
            return 
$GLOBALS[$varname];
        } else {
            return 
null;
        }
    }

    function 
_setTemplate$isAdmin=false ) {
        global 
$Itemid;
        
$mosConfig_absolute_path $this->getCfg'absolute_path' );

        if (
$isAdmin) {
            
$query "SELECT template"
            
"\n FROM #__templates_menu"
            
"\n WHERE client_id = 1"
            
"\n AND menuid = 0"
            
;
            
$this->_db->setQuery$query );
            
$cur_template $this->_db->loadResult();
            
$path "$mosConfig_absolute_path/administrator/templates/$cur_template/index.php";
            if (!
file_exists$path )) {
                
$cur_template 'joomla_admin';
            }
        } else {
            
$assigned = ( !empty( $Itemid ) ? " OR menuid = $Itemid'' );

            
$query "SELECT template"
            
"\n FROM #__templates_menu"
            
"\n WHERE client_id = 0"
            
"\n AND ( menuid = 0 $assigned )"
            
"\n ORDER BY menuid DESC"
            
"\n LIMIT 1"
            
;
            
$this->_db->setQuery$query );
            
$cur_template $this->_db->loadResult();

            
// TemplateChooser Start
            
$jos_user_template         mosGetParam$_COOKIE'jos_user_template''' );
            
$jos_change_template     mosGetParam$_REQUEST'jos_change_template'$jos_user_template );
            if (
$jos_change_template) {
                
// clean template name
                
$jos_change_template preg_replace'#\W#'''$jos_change_template );
                if ( 
strlen$jos_change_template ) >= 40 ) {
                    
$jos_change_template substr($jos_change_template39);
                }
                
                
// check that template exists in case it was deleted
                
if (file_exists$mosConfig_absolute_path .'/templates/'$jos_change_template .'/index.php' )) {
                    
$lifetime         60*10;
                    
$cur_template     $jos_change_template;
                    
setcookie'jos_user_template'"$jos_change_template"time()+$lifetime);
                } else {
                    
setcookie'jos_user_template'''time()-3600 );
                }
            }
            
// TemplateChooser End
        
}

        
$this->_template $cur_template;
    }

    function 
getTemplate() {
        return 
$this->_template;
    }

    
/**
    * Determines the paths for including engine and menu files
    * @param string The current option used in the url
    * @param string The base path from which to load the configuration file
    */
    
function _setAdminPaths$option$basePath='.' ) {
        
$option strtolower$option );
        
$this->_path = new stdClass();

        
$prefix substr$option0);
        if (
$prefix != 'com_') {
            
// ensure backward compatibility with existing links
            
$name $option;
            
$option "com_$option";
        } else {
            
$name substr$option);
        }
        
// components
        
if (file_exists"$basePath/templates/$this->_template/components/$name.html.php" )) {
            
$this->_path->front "$basePath/components/$option/$name.php";
            
$this->_path->front_html "$basePath/templates/$this->_template/components/$name.html.php";
        } else if (
file_exists"$basePath/components/$option/$name.php" )) {
            
$this->_path->front "$basePath/components/$option/$name.php";
            
$this->_path->front_html "$basePath/components/$option/$name.html.php";
        }
        if (
file_exists"$basePath/administrator/components/$option/admin.$name.php" )) {
            
$this->_path->admin "$basePath/administrator/components/$option/admin.$name.php";
            
$this->_path->admin_html "$basePath/administrator/components/$option/admin.$name.html.php";
        }
        if (
file_exists"$basePath/administrator/components/$option/toolbar.$name.php" )) {
            
$this->_path->toolbar "$basePath/administrator/components/$option/toolbar.$name.php";
            
$this->_path->toolbar_html "$basePath/administrator/components/$option/toolbar.$name.html.php";
            
$this->_path->toolbar_default "$basePath/administrator/includes/toolbar.html.php";
        }
        if (
file_exists"$basePath/components/$option/$name.class.php" )) {
            
$this->_path->class "$basePath/components/$option/$name.class.php";
        } else if (
file_exists"$basePath/administrator/components/$option/$name.class.php" )) {
            
$this->_path->class "$basePath/administrator/components/$option/$name.class.php";
        } else if (
file_exists"$basePath/includes/$name.php" )) {
            
$this->_path->class "$basePath/includes/$name.php";
        }
        if (
file_exists("$basePath/administrator/components/$option/admin.$name.php" )) {
            
$this->_path->admin "$basePath/administrator/components/$option/admin.$name.php";
            
$this->_path->admin_html "$basePath/administrator/components/$option/admin.$name.html.php";
        } else {
            
$this->_path->admin "$basePath/administrator/components/com_admin/admin.admin.php";
            
$this->_path->admin_html "$basePath/administrator/components/com_admin/admin.admin.html.php";
        }
    }
    
/**
    * Returns a stored path variable
    *
    */
    
function getPath$varname$option='' ) {
        global 
$mosConfig_absolute_path;
        if (
$option) {
            
$temp $this->_path;
            
$this->_setAdminPaths$option$this->getCfg'absolute_path' ) );
        }
        
$result null;
        if (isset( 
$this->_path->$varname )) {
            
$result $this->_path->$varname;
        } else {
            switch (
$varname) {
                case 
'com_xml':
                    
$name substr$option);
                    
$path "$mosConfig_absolute_path/administrator/components/$option/$name.xml";
                    if (
file_exists$path )) {
                        
$result $path;
                    } else {
                        
$path "$mosConfig_absolute_path/components/$option/$name.xml";
                        if (
file_exists$path )) {
                            
$result $path;
                        }
                    }
                    break;

                case 
'mod0_xml':
                    
// Site modules
                    
if ($option == '') {
                        
$path $mosConfig_absolute_path "/modules/custom.xml";
                    } else {
                        
$path $mosConfig_absolute_path "/modules/$option.xml";
                    }
                    if (
file_exists$path )) {
                        
$result $path;
                    }
                    break;

                case 
'mod1_xml':
                    
// admin modules
                    
if ($option == '') {
                        
$path $mosConfig_absolute_path '/administrator/modules/custom.xml';
                    } else {
                        
$path $mosConfig_absolute_path "/administrator/modules/$option.xml";
                    }
                    if (
file_exists$path )) {
                        
$result $path;
                    }
                    break;

                case 
'bot_xml':
                    
// Site mambots
                    
$path $mosConfig_absolute_path "/mambots/$option.xml";
                    if (
file_exists$path )) {
                        
$result $path;
                    }
                    break;

                case 
'menu_xml':
                    
$path $mosConfig_absolute_path "/administrator/components/com_menus/$option/$option.xml";
                    if (
file_exists$path )) {
                        
$result $path;
                    }
                    break;

                case 
'installer_html':
                    
$path $mosConfig_absolute_path "/administrator/components/com_installer/$option/$option.html.php";
                    if (
file_exists$path )) {
                        
$result $path;
                    }
                    break;

                case 
'installer_class':
                    
$path $mosConfig_absolute_path "/administrator/components/com_installer/$option/$option.class.php";
                    if (
file_exists$path )) {
                        
$result $path;
                    }
                    break;
            }
        }
        if (
$option) {
            
$this->_path $temp;
        }
        return 
$result;
    }
    
/**
    * Detects a 'visit'
    *
    * This function updates the agent and domain table hits for a particular
    * visitor.  The user agent is recorded/incremented if this is the first visit.
    * A cookie is set to mark the first visit.
    */
    
function detect() {
        global 
$mosConfig_enable_stats;
        if (
$mosConfig_enable_stats == 1) {
            if (
mosGetParam$_COOKIE'mosvisitor')) {
                return;
            }
            
setcookie"mosvisitor""1" );

            if (
phpversion() <= "4.2.1") {
                
$agent getenv"HTTP_USER_AGENT" );
                
$domain gethostbyaddrgetenv"REMOTE_ADDR" ) );
            } else {
                if ( isset(
$_SERVER['HTTP_USER_AGENT']) ) {
                    
$agent $_SERVER['HTTP_USER_AGENT'];
                } else {
                    
$agent 'Unknown';
                }

                
$domain gethostbyaddr$_SERVER['REMOTE_ADDR'] );
            }

            
$browser mosGetBrowser$agent );

            
$query "SELECT COUNT(*)"
            
"\n FROM #__stats_agents"
            
"\n WHERE agent = '$browser'"
            
"\n AND type = 0"
            
;
            
$this->_db->setQuery$query );
            if (
$this->_db->loadResult()) {
                
$query "UPDATE #__stats_agents"
                
"\n SET hits = ( hits + 1 )"
                
"\n WHERE agent = '$browser'"
                
"\n AND type = 0"
                
;
                
$this->_db->setQuery$query );
            } else {
                
$query "INSERT INTO #__stats_agents"
                
"\n ( agent, type )"
                
"\n VALUES ( '$browser', 0 )"
                
;
                
$this->_db->setQuery$query );
            }
            
$this->_db->query();

            
$os mosGetOS$agent );

            
$query "SELECT COUNT(*)"
            
"\n FROM #__stats_agents"
            
"\n WHERE agent = '$os'"
            
"\n AND type = 1"
            
;
            
$this->_db->setQuery$query );
            if (
$this->_db->loadResult()) {
                
$query "UPDATE #__stats_agents"
                
"\n SET hits = ( hits + 1 )"
                
"\n WHERE agent = '$os'"
                
"\n AND type = 1"
                
;
                
$this->_db->setQuery$query );
            } else {
                
$query "INSERT INTO #__stats_agents"
                
"\n ( agent, type )"
                
"\n VALUES ( '$os', 1 )"
                
;
                
$this->_db->setQuery$query );
            }
            
$this->_db->query();

            
// tease out the last element of the domain
            
$tldomain split"\."$domain );
            
$tldomain $tldomain[count$tldomain )-1];

            if (
is_numeric$tldomain )) {
                
$tldomain "Unknown";
            }

            
$query "SELECT COUNT(*)"
            
"\n FROM #__stats_agents"
            
"\n WHERE agent = '$tldomain'"
            
"\n AND type = 2"
            
;
            
$this->_db->setQuery$query );
            if (
$this->_db->loadResult()) {
                
$query "UPDATE #__stats_agents"
                
"\n SET hits = ( hits + 1 )"
                
"\n WHERE agent = '$tldomain'"
                
"\n AND type = 2"
                
;
                
$this->_db->setQuery$query );
            } else {
                
$query "INSERT INTO #__stats_agents"
                
"\n ( agent, type )"
                
"\n VALUES ( '$tldomain', 2 )"
                
;
                
$this->_db->setQuery$query );
            }
            
$this->_db->query();
        }
    }

    
/**
    * @return correct Itemid for Content Item
    */
    
function getItemid$id$typed=1$link=1$bs=1$bc=1$gbs=) {
        global 
$Itemid;
        
        
$bs     $this->get'_BlogSectionCount' );
        
$bc     $this->get'_BlogCategoryCount' );
        
$gbs     $this->get'_GlobalBlogSectionCount' );

        
$_Itemid '';
        if (
$_Itemid == '' && $typed) {
            
$exists 0;
            foreach( 
$this->get'_ContentTyped', array() ) as $key => $value ) {
                
// check if id has been tested before, if it is pull from class variable store
                
if ( $key == $id ) {
                    
$_Itemid     $value;
                    
$exists     1;
                    break;
                }
            }
            
// if id hasnt been checked before initaite query
            
if ( !$exists ) {                
                
// Search for typed link
                
$query "SELECT id"
                
"\n FROM #__menu"
                
"\n WHERE type = 'content_typed'"
                
"\n AND published = 1"
                
"\n AND link = 'index.php?option=com_content&task=view&id=$id'"
                
;
                
$this->_db->setQuery$query );
                
// pull existing query storage into temp variable
                
$ContentTyped         $this->get'_ContentTyped', array() );
                
// add query result to temp array storage
                
$ContentTyped[$id]     = $this->_db->loadResult();    
                
// save temp array to main array storage
                
$this->set'_ContentTyped'$ContentTyped );
                
                
$_Itemid $ContentTyped[$id];                
            }
        }

        if (
$_Itemid == '' && $link) {
            
$exists 0;
            foreach( 
$this->get'_ContentItemLink', array() ) as $key => $value ) {
                
// check if id has been tested before, if it is pull from class variable store
                
if ( $key == $id ) {
                    
$_Itemid     $value;
                    
$exists     1;
                    break;
                }
            }
            
// if id hasnt been checked before initaite query
            
if ( !$exists ) {                
                
// Search for item link
                
$query "SELECT id"
                
."\n FROM #__menu"
                
."\n WHERE type = 'content_item_link'"
                
"\n AND published = 1"
                
"\n AND link = 'index.php?option=com_content&task=view&id=$id'"
                
;
                
$this->_db->setQuery$query );
                
// pull existing query storage into temp variable
                
$ContentItemLink         $this->get'_ContentItemLink', array() );
                
// add query result to temp array storage
                
$ContentItemLink[$id]     = $this->_db->loadResult();    
                
// save temp array to main array storage
                
$this->set'_ContentItemLink'$ContentItemLink );
                
                
$_Itemid $ContentItemLink[$id];                
            }
        }

        if (
$_Itemid == '') {
            
$exists 0;
            foreach( 
$this->get'_ContentSection', array() ) as $key => $value ) {
            
// check if id has been tested before, if it is pull from class variable store
                
if ( $key == $id ) {
                    
$_Itemid     $value;
                    
$exists     1;
                    break;
                }
            }
            
// if id hasnt been checked before initaite query
            
if ( !$exists ) {
                
// Search in sections
                
$query "SELECT m.id "
                
"\n FROM #__content AS i"
                
"\n LEFT JOIN #__sections AS s ON i.sectionid = s.id"
                
"\n LEFT JOIN #__menu AS m ON m.componentid = s.id "
                
"\n WHERE m.type = 'content_section'"
                
"\n AND m.published = 1"
                
"\n AND i.id = $id"
                
;
                
$this->_db->setQuery$query );
                
// pull existing query storage into temp variable
                
$ContentSection         $this->get'_ContentSection', array() );
                
// add query result to temp array storage
                
$ContentSection[$id]     = $this->_db->loadResult();    
                
// save temp array to main array storage
                
$this->set'_ContentSection'$ContentSection );
                
                
$_Itemid $ContentSection[$id];                
            }
        }

        if (
$_Itemid == '' && $bs) {
            
$exists 0;
            foreach( 
$this->get'_ContentBlogSection', array() ) as $key => $value ) {
                
// check if id has been tested before, if it is pull from class variable store
                
if ( $key == $id ) {
                    
$_Itemid     $value;
                    
$exists     1;
                    break;
                }
            }
            
// if id hasnt been checked before initaite query
            
if ( !$exists ) {
                
// Search in specific blog section
                
$query "SELECT m.id "
                
"\n FROM #__content AS i"
                
"\n LEFT JOIN #__sections AS s ON i.sectionid = s.id"
                
"\n LEFT JOIN #__menu AS m ON m.componentid = s.id "
                
"\n WHERE m.type = 'content_blog_section'"
                
"\n AND m.published = 1"
                
"\n AND i.id = $id"
                
;
                
$this->_db->setQuery$query );
                
// pull existing query storage into temp variable
                
$ContentBlogSection         $this->get'_ContentBlogSection', array() );
                
// add query result to temp array storage
                
$ContentBlogSection[$id]     = $this->_db->loadResult();    
                
// save temp array to main array storage
                
$this->set'_ContentBlogSection'$ContentBlogSection );
                
                
$_Itemid $ContentBlogSection[$id];                
            }
        }

        if (
$_Itemid == '' && $bc) {
            
$exists 0;
            foreach( 
$this->get'_ContentBlogCategory', array() ) as $key => $value ) {
                
// check if id has been tested before, if it is pull from class variable store
                
if ( $key == $id ) {
                    
$_Itemid     $value;
                    
$exists     1;
                    break;
                }
            }
            
// if id hasnt been checked before initaite query
            
if ( !$exists ) {
                
// Search in specific blog category
                
$query "SELECT m.id "
                
"\n FROM #__content AS i"
                
"\n LEFT JOIN #__categories AS c ON i.catid = c.id"
                
"\n LEFT JOIN #__menu AS m ON m.componentid = c.id "
                
"\n WHERE m.type = 'content_blog_category'"
                
"\n AND m.published = 1"
                
"\n AND i.id = $id"
                
;
                
$this->_db->setQuery$query );
                
// pull existing query storage into temp variable
                
$ContentBlogCategory         $this->get'_ContentBlogCategory', array() );
                
// add query result to temp array storage
                
$ContentBlogCategory[$id]     = $this->_db->loadResult();    
                
// save temp array to main array storage
                
$this->set'_ContentBlogCategory'$ContentBlogCategory );
                
                
$_Itemid $ContentBlogCategory[$id];                
            }
        }

        if (
$_Itemid == '' && $gbs) {
            
// ensure that query is only called once        
            
if ( !$this->get'_GlobalBlogSection' ) && !defined'_JOS_GBS' ) ) {                    
                
define'_JOS_GBS');
                
                
// Search in global blog section
                
$query "SELECT id "
                
"\n FROM #__menu "
                
"\n WHERE type = 'content_blog_section'"
                
"\n AND published = 1"
                
"\n AND componentid = 0"
                
;
                
$this->_db->setQuery$query );
                
$this->set'_GlobalBlogSection'$this->_db->loadResult() );
            }
            
            
$_Itemid $this->get'_GlobalBlogSection' );
        }

        if (
$_Itemid == '') {
            
$exists 0;
            foreach( 
$this->get'_ContentCategory', array() ) as $key => $value ) {
                
// check if id has been tested before, if it is pull from class variable store
                
if ( $key == $id ) {
                    
$_Itemid     $value;
                    
$exists     1;
                    break;
                }
            }
            
// if id hasnt been checked before initaite query
            
if ( !$exists ) {
                
// Search in categories
                
$query "SELECT m.id "
                
"\n FROM #__content AS i"
                
"\n LEFT JOIN #__categories AS cc ON i.catid = cc.id"
                
"\n LEFT JOIN #__menu AS m ON m.componentid = cc.id "
                
"\n WHERE m.type = 'content_category'"
                
"\n AND m.published = 1"
                
"\n AND i.id = $id"
                
;
                
$this->_db->setQuery$query );
                
// pull existing query storage into temp variable
                
$ContentCategory         $this->get'_ContentCategory', array() );
                
// add query result to temp array storage
                
$ContentCategory[$id]     = $this->_db->loadResult();    
                
// save temp array to main array storage
                
$this->set'_ContentCategory'$ContentCategory );
                
                
$_Itemid $ContentCategory[$id];                
            }
        }

        if ( 
$_Itemid != '' ) {
            return 
$_Itemid;
        } else {
            return 
$Itemid;
        }
    }

    
/**
    * @return number of Published Blog Sections
    */
    
function getBlogSectionCount( ) {
        
// ensure that query is only called once        
        
if ( !$this->get'_BlogSectionCount' ) && !defined'_JOS_BSC' ) ) {        
            
define'_JOS_BSC');
            
            
$query "SELECT COUNT( id )"
            
."\n FROM #__menu "
            
."\n WHERE type = 'content_blog_section'"
            
."\n AND published = 1"
            
;
            
$this->_db->setQuery$query );
            
// saves query result to variable
            
$this->set'_BlogSectionCount'$this->_db->loadResult() );
        }
        
        return 
$this->get'_BlogSectionCount' );
    }

    
/**
    * @return number of Published Blog Categories
    */
    
function getBlogCategoryCount( ) {
        
// ensure that query is only called once        
        
if ( !$this->get'_BlogCategoryCount' )&& !defined'_JOS_BCC' ) ) {
            
define'_JOS_BCC');
            
            
$query "SELECT COUNT( id )"
            
."\n FROM #__menu "
            
"\n WHERE type = 'content_blog_category'"
            
"\n AND published = 1"
            
;
            
$this->_db->setQuery$query );
            
// saves query result to variable
            
$this->set'_BlogCategoryCount'$this->_db->loadResult() );
        }
        
        return 
$this->get'_BlogCategoryCount' );
    }

    
/**
    * @return number of Published Global Blog Sections
    */
    
function getGlobalBlogSectionCount( ) {
        
// ensure that query is only called once        
        
if ( !$this->get'_GlobalBlogSectionCount' ) && !defined'_JOS_GBSC' ) ) {        
            
define'_JOS_GBSC');
            
            
$query "SELECT COUNT( id )"
            
."\n FROM #__menu "
            
."\n WHERE type = 'content_blog_section'"
            
."\n AND published = 1"
            
."\n AND componentid = 0"
            
;
            
$this->_db->setQuery$query );
            
// saves query result to variable
            
$this->set'_GlobalBlogSectionCount'$this->_db->loadResult() );
        }
        
        return 
$this->get'_GlobalBlogSectionCount' );
    }

    
/**
    * @return number of Static Content
    */
    
function getStaticContentCount( ) {
        
// ensure that query is only called once        
        
if ( !$this->get'_StaticContentCount' ) && !defined'_JOS_SCC' ) ) {        
            
define'_JOS_SCC');
            
            
$query "SELECT COUNT( id )"
            
."\n FROM #__menu "
            
."\n WHERE type = 'content_typed'"
            
."\n AND published = 1"
            
;
            
$this->_db->setQuery$query );
            
// saves query result to variable
            
$this->set'_StaticContentCount'$this->_db->loadResult() );
        }
        
        return 
$this->get'_StaticContentCount' );        
    }

    
/**
    * @return number of Content Item Links
    */
    
function getContentItemLinkCount( ) {
        
// ensure that query is only called once        
        
if ( !$this->get'_ContentItemLinkCount' ) && !defined'_JOS_CILC' ) ) {        
            
define'_JOS_CILC');
            
            
$query "SELECT COUNT( id )"
            
."\n FROM #__menu "
            
."\n WHERE type = 'content_item_link'"
            
."\n AND published = 1"
            
;
            
// saves query result to variable
            
$this->set'_ContentItemLinkCount'$this->_db->loadResult() );
        }

        return 
$this->get'_ContentItemLinkCount' );
    }

    
/**
    * @param string The name of the property
    * @param mixed The value of the property to set
    */
    
function set$property$value=null ) {
        
$this->$property $value;
    }

    
/**
    * @param string The name of the property
    * @param mixed  The default value
    * @return mixed The value of the property
    */
    
function get($property$default=null) {
        if(isset(
$this->$property)) {
            return 
$this->$property;
        } else {
            return 
$default;
        }
    }

    
/** Is admin interface?
     * @return boolean
     * @since 1.0.2
     */
    
function isAdmin() {
        return 
$this->_isAdmin;
    }
}

/**
* Component database table class
* @package Joomla
*/
class mosComponent extends mosDBTable {
    
/** @var int Primary key */
    
var $id                    null;
    
/** @var string */
    
var $name                null;
    
/** @var string */
    
var $link                null;
    
/** @var int */
    
var $menuid                null;
    
/** @var int */
    
var $parent                null;
    
/** @var string */
    
var $admin_menu_link    null;
    
/** @var string */
    
var $admin_menu_alt        null;
    
/** @var string */
    
var $option                null;
    
/** @var string */
    
var $ordering            null;
    
/** @var string */
    
var $admin_menu_img        null;
    
/** @var int */
    
var $iscore                null;
    
/** @var string */
    
var $params                null;

    
/**
    * @param database A database connector object
    */
    
function mosComponent( &$db ) {
        
$this->mosDBTable'#__components''id'$db );
    }
}

/**
* Utility class for all HTML drawing classes
* @package Joomla
*/
class mosHTML {
    function 
makeOption$value$text=''$value_name='value'$text_name='text' ) {
        
$obj = new stdClass;
        
$obj->$value_name $value;
        
$obj->$text_name trim$text ) ? $text $value;
        return 
$obj;
    }

  function 
writableCell$folder ) {

      echo 
'<tr>';
      echo 
'<td class="item">' $folder '/</td>';
      echo 
'<td align="left">';
      echo 
is_writable"../$folder) ? '<b><font color="green">Writeable</font></b>' '<b><font color="red">Unwriteable</font></b>' '</td>';
      echo 
'</tr>';
  }

    
/**
    * Generates an HTML select list
    * @param array An array of objects
    * @param string The value of the HTML name attribute
    * @param string Additional HTML attributes for the <select> tag
    * @param string The name of the object variable for the option value
    * @param string The name of the object variable for the option text
    * @param mixed The key that is selected
    * @returns string HTML for the select list
    */
    
function selectList( &$arr$tag_name$tag_attribs$key$text$selected=NULL ) {
        
reset$arr );
        
$html "\n<select name=\"$tag_name\" $tag_attribs>";
        for (
$i=0$n=count$arr ); $i $n$i++ ) {
            
$k $arr[$i]->$key;
            
$t $arr[$i]->$text;
            
$id = ( isset($arr[$i]->id) ? @$arr[$i]->id null);

            
$extra '';
            
$extra .= $id " id=\"" $arr[$i]->id "\"" '';
            if (
is_array$selected )) {
                foreach (
$selected as $obj) {
                    
$k2 $obj->$key;
                    if (
$k == $k2) {
                        
$extra .= " selected=\"selected\"";
                        break;
                    }
                }
            } else {
                
$extra .= ($k == $selected " selected=\"selected\"" '');
            }
            
$html .= "\n\t<option value=\"".$k."\"$extra>" $t "</option>";
        }
        
$html .= "\n</select>\n";
        return 
$html;
    }

    
/**
    * Writes a select list of integers
    * @param int The start integer
    * @param int The end integer
    * @param int The increment
    * @param string The value of the HTML name attribute
    * @param string Additional HTML attributes for the <select> tag
    * @param mixed The key that is selected
    * @param string The printf format to be applied to the number
    * @returns string HTML for the select list
    */
    
function integerSelectList$start$end$inc$tag_name$tag_attribs$selected$format="" ) {
        
$start     intval$start );
        
$end     intval$end );
        
$inc     intval$inc );
        
$arr     = array();

        for (
$i=$start$i <= $end$i+=$inc) {
            
$fi $format sprintf"$format"$i ) : "$i";
            
$arr[] = mosHTML::makeOption$fi$fi );
        }

        return 
mosHTML::selectList$arr$tag_name$tag_attribs'value''text'$selected );
    }

    
/**
    * Writes a select list of month names based on Language settings
    * @param string The value of the HTML name attribute
    * @param string Additional HTML attributes for the <select> tag
    * @param mixed The key that is selected
    * @returns string HTML for the select list values
    */
    
function monthSelectList$tag_name$tag_attribs$selected ) {
        
$arr = array(
            
mosHTML::makeOption'01'_JAN ),
            
mosHTML::makeOption'02'_FEB ),
            
mosHTML::makeOption'03'_MAR ),
            
mosHTML::makeOption'04'_APR ),
            
mosHTML::makeOption'05'_MAY ),
            
mosHTML::makeOption'06'_JUN ),
            
mosHTML::makeOption'07'_JUL ),
            
mosHTML::makeOption'08'_AUG ),
            
mosHTML::makeOption'09'_SEP ),
            
mosHTML::makeOption'10'_OCT ),
            
mosHTML::makeOption'11'_NOV ),
            
mosHTML::makeOption'12'_DEC )
        );

        return 
mosHTML::selectList$arr$tag_name$tag_attribs'value''text'$selected );
    }

    
/**
    * Generates an HTML select list from a tree based query list
    * @param array Source array with id and parent fields
    * @param array The id of the current list item
    * @param array Target array.  May be an empty array.
    * @param array An array of objects
    * @param string The value of the HTML name attribute
    * @param string Additional HTML attributes for the <select> tag
    * @param string The name of the object variable for the option value
    * @param string The name of the object variable for the option text
    * @param mixed The key that is selected
    * @returns string HTML for the select list
    */
    
function treeSelectList( &$src_list$src_id$tgt_list$tag_name$tag_attribs$key$text$selected ) {

        
// establish the hierarchy of the menu
        
$children = array();
        
// first pass - collect children
        
foreach ($src_list as $v ) {
            
$pt $v->parent;
            
$list = @$children[$pt] ? $children[$pt] : array();
            
array_push$list$v );
            
$children[$pt] = $list;
        }
        
// second pass - get an indent list of the items
        
$ilist mosTreeRecurse0'', array(), $children );

        
// assemble menu items to the array
        
$this_treename '';
        foreach (
$ilist as $item) {
            if (
$this_treename) {
                if (
$item->id != $src_id && strpos$item->treename$this_treename ) === false) {
                    
$tgt_list[] = mosHTML::makeOption$item->id$item->treename );
                }
            } else {
                if (
$item->id != $src_id) {
                    
$tgt_list[] = mosHTML::makeOption$item->id$item->treename );
                } else {
                    
$this_treename "$item->treename/";
                }
            }
        }
        
// build the html select list
        
return mosHTML::selectList$tgt_list$tag_name$tag_attribs$key$text$selected );
    }

    
/**
    * Writes a yes/no select list
    * @param string The value of the HTML name attribute
    * @param string Additional HTML attributes for the <select> tag
    * @param mixed The key that is selected
    * @returns string HTML for the select list values
    */
    
function yesnoSelectList$tag_name$tag_attribs$selected$yes=_CMN_YES$no=_CMN_NO ) {
        
$arr = array(
        
mosHTML::makeOption'0'$no ),
        
mosHTML::makeOption'1'$yes ),
        );

        return 
mosHTML::selectList$arr$tag_name$tag_attribs'value''text'$selected );
    }

    
/**
    * Generates an HTML radio list
    * @param array An array of objects
    * @param string The value of the HTML name attribute
    * @param string Additional HTML attributes for the <select> tag
    * @param mixed The key that is selected
    * @param string The name of the object variable for the option value
    * @param string The name of the object variable for the option text
    * @returns string HTML for the select list
    */
    
function radioList( &$arr$tag_name$tag_attribs$selected=null$key='value'$text='text' ) {
        
reset$arr );
        
$html "";
        for (
$i=0$n=count$arr ); $i $n$i++ ) {
            
$k $arr[$i]->$key;
            
$t $arr[$i]->$text;
            
$id = ( isset($arr[$i]->id) ? @$arr[$i]->id null);

            
$extra '';
            
$extra .= $id " id=\"" $arr[$i]->id "\"" '';
            if (
is_array$selected )) {
                foreach (
$selected as $obj) {
                    
$k2 $obj->$key;
                    if (
$k == $k2) {
                        
$extra .= " selected=\"selected\"";
                        break;
                    }
                }
            } else {
                
$extra .= ($k == $selected " checked=\"checked\"" '');
            }
            
$html .= "\n\t<input type=\"radio\" name=\"$tag_name\" id=\"$tag_name$k\" value=\"".$k."\"$extra $tag_attribs />";
            
$html .= "\n\t<label for=\"$tag_name$k\">$t</label>";
        }
        
$html .= "\n";
        return 
$html;
    }

    
/**
    * Writes a yes/no radio list
    * @param string The value of the HTML name attribute
    * @param string Additional HTML attributes for the <select> tag
    * @param mixed The key that is selected
    * @returns string HTML for the radio list
    */
    
function yesnoRadioList$tag_name$tag_attribs$selected$yes=_CMN_YES$no=_CMN_NO ) {
        
$arr = array(
        
mosHTML::makeOption'0'$no ),
        
mosHTML::makeOption'1'$yes )
        );
        return 
mosHTML::radioList$arr$tag_name$tag_attribs$selected );
    }

    
/**
    * @param int The row index
    * @param int The record id
    * @param boolean
    * @param string The name of the form element
    * @return string
    */
    
function idBox$rowNum$recId$checkedOut=false$name='cid' ) {
        if ( 
$checkedOut ) {
            return 
'';
        } else {
            return 
'<input type="checkbox" id="cb'.$rowNum.'" name="'.$name.'[]" value="'.$recId.'" onclick="isChecked(this.checked);" />';
        }
    }

    function 
sortIcon$base_href$field$state='none' ) {
        global 
$mosConfig_live_site;

        
$alts = array(
            
'none'     => _CMN_SORT_NONE,
            
'asc'     => _CMN_SORT_ASC,
            
'desc'     => _CMN_SORT_DESC,
        );
        
$next_state 'asc';
        if (
$state == 'asc') {
            
$next_state 'desc';
        } else if (
$state == 'desc') {
            
$next_state 'none';
        }

        
$html "<a href=\"$base_href&field=$field&order=$next_state\">"
        
"<img src=\"$mosConfig_live_site/images/M_images/sort_$state.png\" width=\"12\" height=\"12\" border=\"0\" alt=\"{$alts[$next_state]}\" />"
        
"</a>";
        return 
$html;
    }

    
/**
    * Writes Close Button
    */
    
function CloseButton ( &$params$hide_js=NULL ) {
        
// displays close button in Pop-up window
        
if ( $params->get'popup' ) && !$hide_js ) {
            
?>
            <div align="center" style="margin-top: 30px; margin-bottom: 30px;">
            <a href='javascript:window.close();'>
            <span class="small">
            <?php echo _PROMPT_CLOSE;?>
            </span>
            </a>
            </div>
            <?php
        
}
    }

    
/**
    * Writes Back Button
    */
    
function BackButton ( &$params$hide_js=NULL ) {
        
// Back Button
        
if ( $params->get'back_button' ) && !$params->get'popup' ) && !$hide_js) {
            
?>
            <div class="back_button">
            <a href='javascript:history.go(-1)'>
            <?php echo _BACK?>
            </a>
            </div>
            <?php
        
}
    }

    
/**
    * Cleans text of all formating and scripting code
    */
    
function cleanText ( &$text ) {
        
$text preg_replace"'<script[^>]*>.*?</script>'si"''$text );
        
$text preg_replace'/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is''\2 (\1)'$text );
        
$text preg_replace'/<!--.+?-->/'''$text );
        
$text preg_replace'/{.+?}/'''$text );
        
$text preg_replace'/&nbsp;/'' '$text );
        
$text preg_replace'/&amp;/'' '$text );
        
$text preg_replace'/&quot;/'' '$text );
        
$text strip_tags$text );
        
$text htmlspecialchars$text );
        return 
$text;
    }

    
/**
    * Writes Print icon
    */
    
function PrintIcon( &$row, &$params$hide_js$link$status=NULL ) {
        global 
$mosConfig_live_site$mosConfig_absolute_path$cur_template$Itemid;
        if ( 
$params->get'print' )  && !$hide_js ) {
            
// use default settings if none declared
            
if ( !$status ) {
                
$status 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no';
            }

            
// checks template image directory for image, if non found default are loaded
            
if ( $params->get'icons' ) ) {
                
$image mosAdminMenus::ImageCheck'printButton.png''/images/M_images/'NULLNULL_CMN_PRINT_CMN_PRINT );
            } else {
                
$image _ICON_SEP .'&nbsp;'_CMN_PRINT'&nbsp;'_ICON_SEP;
            }

            if ( 
$params->get'popup' ) && !$hide_js ) {
                
// Print Preview button - used when viewing page
                
?>
                <td align="right" width="100%" class="buttonheading">
                <a href="javascript:void(0)" onclick="javascript:window.print(); return false" title="<?php echo _CMN_PRINT;?>">
                <?php echo $image;?>
                </a>
                </td>
                <?php
            
} else {
                
// Print Button - used in pop-up window
                
?>
                <td align="right" width="100%" class="buttonheading">
                <a href="javascript:void(0)" onclick="window.open('<?php echo $link?>','win2','<?php echo $status?>');" title="<?php echo _CMN_PRINT;?>">
                <?php echo $image;?>
                </a>
                </td>
                <?php
            
}
        }
    }

    
/**
    * simple Javascript Cloaking
    * email cloacking
     * by default replaces an email with a mailto link with email cloacked
    */
    
function emailCloaking$mail$mailto=1$text=''$email=) {
        
// convert text
        
$mail         mosHTML::encoding_converter$mail );
        
// split email by @ symbol
        
$mail        explode'@'$mail );
        
$mail_parts    explode'.'$mail[1] );
        
// random number
        
$rand    rand1100000 );

        
$replacement     "\n<script language='JavaScript' type='text/javascript'> \n";
        
$replacement     .= "<!-- \n";
        
$replacement     .= "var prefix = '&#109;a' + 'i&#108;' + '&#116;o'; \n";
        
$replacement     .= "var path = 'hr' + 'ef' + '='; \n";
        
$replacement     .= "var addy"$rand ." = '". @$mail[0] ."' + '&#64;'; \n";
        
$replacement     .= "addy"$rand ." = addy"$rand ." + '"implode"' + '&#46;' + '"$mail_parts ) ."'; \n";
        if ( 
$mailto ) {
            
// special handling when mail text is different from mail addy
            
if ( $text ) {
                if ( 
$email ) {
                    
// convert text
                    
$text     mosHTML::encoding_converter$text );
                    
// split email by @ symbol
                    
$text     explode'@'$text );
                    
$text_parts    explode'.'$text[1] );
                    
$replacement     .= "var addy_text"$rand ." = '". @$text[0] ."' + '&#64;' + '"implode"' + '&#46;' + '", @$text_parts ) ."'; \n";
                } else {
                    
//$text     = mosHTML::encoding_converter( $text );
                    
$replacement     .= "var addy_text"$rand ." = '"$text ."';\n";
                }
                
$replacement     .= "document.write( '<a ' + path + '\'' + prefix + ':' + addy"$rand ." + '\'>' ); \n";
                
$replacement     .= "document.write( addy_text"$rand ." ); \n";
                
$replacement     .= "document.write( '<\/a>' ); \n";
            } else {
                
$replacement     .= "document.write( '<a ' + path + '\'' + prefix + ':' + addy"$rand ." + '\'>' ); \n";
                
$replacement     .= "document.write( addy"$rand ." ); \n";
                
$replacement     .= "document.write( '<\/a>' ); \n";
            }
        } else {
            
$replacement     .= "document.write( addy"$rand ." ); \n";
        }
        
$replacement     .= "//--> \n";
        
$replacement     .= "</script>";
        
$replacement     .= "<noscript> \n";
        
$replacement     .= _CLOAKING;
        
$replacement     .= "\n</noscript>";

        return 
$replacement;
    }

    function 
encoding_converter$text ) {
        
// replace vowels with character encoding
        
$text     str_replace'a''&#97;'$text );
        
$text     str_replace'e''&#101;'$text );
        
$text     str_replace'i''&#105;'$text );
        
$text     str_replace'o''&#111;'$text );
        
$text    str_replace'u''&#117;'$text );

        return 
$text;
    }
}

/**
* Category database table class
* @package Joomla
*/
class mosCategory extends mosDBTable {
    
/** @var int Primary key */
    
var $id                    null;
    
/** @var int */
    
var $parent_id            null;
    
/** @var string The menu title for the Category (a short name)*/
    
var $title                null;
    
/** @var string The full name for the Category*/
    
var $name                null;
    
/** @var string */
    
var $image                null;
    
/** @var string */
    
var $section            null;
    
/** @var int */
    
var $image_position        null;
    
/** @var string */
    
var $description        null;
    
/** @var boolean */
    
var $published            null;
    
/** @var boolean */
    
var $checked_out        null;
    
/** @var time */
    
var $checked_out_time    null;
    
/** @var int */
    
var $ordering            null;
    
/** @var int */
    
var $access                null;
    
/** @var string */
    
var $params                null;

    
/**
    * @param database A database connector object
    */
    
function mosCategory( &$db ) {
        
$this->mosDBTable'#__categories''id'$db );
    }
    
// overloaded check function
    
function check() {
        
// check for valid name
        
if (trim$this->title ) == '') {
            
$this->_error "Your Category must contain a title.";
            return 
false;
        }
        if (
trim$this->name ) == '') {
            
$this->_error "Your Category must have a name.";
            return 
false;
        }

        
// check for existing name
        
$query "SELECT id"
        
"\n FROM #__categories "
        
"\n WHERE name = '$this->name'"
        
"\n AND section = '$this->section'"
        
;
        
$this->_db->setQuery$query );

        
$xid intval$this->_db->loadResult() );
        if (
$xid && $xid != intval$this->id )) {
            
$this->_error "There is a category already with that name, please try again.";
            return 
false;
        }
        return 
true;
    }
}

/**
* Section database table class
* @package Joomla
*/
class mosSection extends mosDBTable {
    
/** @var int Primary key */
    
var $id                    null;
    
/** @var string The menu title for the Section (a short name)*/
    
var $title                null;
    
/** @var string The full name for the Section*/
    
var $name                null;
    
/** @var string */
    
var $image                null;
    
/** @var string */
    
var $scope                null;
    
/** @var int */
    
var $image_position        null;
    
/** @var string */
    
var $description        null;
    
/** @var boolean */
    
var $published            null;
    
/** @var boolean */
    
var $checked_out        null;
    
/** @var time */
    
var $checked_out_time    null;
    
/** @var int */
    
var $ordering            null;
    
/** @var int */
    
var $access                null;
    
/** @var string */
    
var $params                null;

    
/**
    * @param database A database connector object
    */
    
function mosSection( &$db ) {
        
$this->mosDBTable'#__sections''id'$db );
    }
    
// overloaded check function
    
function check() {
        
// check for valid name
        
if (trim$this->title ) == '') {
            
$this->_error "Your Section must contain a title.";
            return 
false;
        }
        if (
trim$this->name ) == '') {
            
$this->_error "Your Section must have a name.";
            return 
false;
        }
        
// check for existing name
        
$query "SELECT id"
        
"\n FROM #__sections "
        
"\n WHERE name = '$this->name'"
        
"\n AND scope = '$this->scope'"
        
;
        
$this->_db->setQuery$query );

        
$xid intval$this->_db->loadResult() );
        if (
$xid && $xid != intval$this->id )) {
            
$this->_error "There is a section already with that name, please try again.";
            return 
false;
        }
        return 
true;
    }
}

/**
* Module database table class
* @package Joomla
*/
class mosContent extends mosDBTable {
    
/** @var int Primary key */
    
var $id                    null;
    
/** @var string */
    
var $title                null;
    
/** @var string */
    
var $title_alias        null;
    
/** @var string */
    
var $introtext            null;
    
/** @var string */
    
var $fulltext            null;
    
/** @var int */
    
var $state                null;
    
/** @var int The id of the category section*/
    
var $sectionid            null;
    
/** @var int DEPRECATED */
    
var $mask                null;
    
/** @var int */
    
var $catid                null;
    
/** @var datetime */
    
var $created            null;
    
/** @var int User id*/
    
var $created_by            null;
    
/** @var string An alias for the author*/
    
var $created_by_alias    null;
    
/** @var datetime */
    
var $modified            null;
    
/** @var int User id*/
    
var $modified_by        null;
    
/** @var boolean */
    
var $checked_out        null;
    
/** @var time */
    
var $checked_out_time    null;
    
/** @var datetime */
    
var $frontpage_up        null;
    
/** @var datetime */
    
var $frontpage_down        null;
    
/** @var datetime */
    
var $publish_up            null;
    
/** @var datetime */
    
var $publish_down        null;
    
/** @var string */
    
var $images                null;
    
/** @var string */
    
var $urls                null;
    
/** @var string */
    
var $attribs            null;
    
/** @var int */
    
var $version            null;
    
/** @var int */
    
var $parentid            null;
    
/** @var int */
    
var $ordering            null;
    
/** @var string */
    
var $metakey            null;
    
/** @var string */
    
var $metadesc            null;
    
/** @var int */
    
var $access                null;
    
/** @var int */
    
var $hits                null;

    
/**
    * @param database A database connector object
    */
    
function mosContent( &$db ) {
        
$this->mosDBTable'#__content''id'$db );
    }

    
/**
     * Validation and filtering
     */
    
function check() {
        
// filter malicious code
        
$ignoreList = array( 'introtext''fulltext' );
        
$this->filter$ignoreList );

        
/*
        TODO: This filter is too rigorous,
        need to implement more configurable solution
        // specific filters
        $iFilter = new InputFilter( null, null, 1, 1 );
        $this->introtext = trim( $iFilter->process( $this->introtext ) );
        $this->fulltext =  trim( $iFilter->process( $this->fulltext ) );
        */

        
if (trimstr_replace'&nbsp;'''$this->fulltext ) ) == '') {
            
$this->fulltext '';
        }

        return 
true;
    }

    
/**
    * Converts record to XML
    * @param boolean Map foreign keys to text values
    */
    
function toXML$mapKeysToText=false ) {
        global 
$database;

        if (
$mapKeysToText) {
            
$query "SELECT name"
            
"\n FROM #__sections"
            
"\n WHERE id = $this->sectionid"
            
;
            
$database->setQuery$query );
            
$this->sectionid $database->loadResult();

            
$query "SELECT name"
            
"\n FROM #__categories"
            
"\n WHERE id $this->catid"
            
;
            
$database->setQuery$query );
            
$this->catid $database->loadResult();

            
$query "SELECT name"
            
"\n FROM #__users"
            
"\n WHERE id = $this->created_by"
            
;
            
$database->setQuery$query );
            
$this->created_by $database->loadResult();
        }

        return 
parent::toXML$mapKeysToText );
    }
}

/**
* Module database table class
* @package Joomla
*/
class mosMenu extends mosDBTable {
    
/** @var int Primary key */
    
var $id                    null;
    
/** @var string */
    
var $menutype            null;
    
/** @var string */
    
var $name                null;
    
/** @var string */
    
var $link                null;
    
/** @var int */
    
var $type                null;
    
/** @var int */
    
var $published            null;
    
/** @var int */
    
var $componentid        null;
    
/** @var int */
    
var $parent                null;
    
/** @var int */
    
var $sublevel            null;
    
/** @var int */
    
var $ordering            null;
    
/** @var boolean */
    
var $checked_out        null;
    
/** @var datetime */
    
var $checked_out_time    null;
    
/** @var boolean */
    
var $pollid                null;
    
/** @var string */
    
var $browserNav            null;
    
/** @var int */
    
var $access                null;
    
/** @var int */
    
var $utaccess            null;
    
/** @var string */
    
var $params                null;

    
/**
    * @param database A database connector object
    */
    
function mosMenu( &$db ) {
        
$this->mosDBTable'#__menu''id'$db );
    }
}

/**
* Users Table Class
*
* Provides access to the jos_user table
* @package Joomla
*/
class mosUser extends mosDBTable {
    
/** @var int Unique id*/
    
var $id                null;
    
/** @var string The users real name (or nickname)*/
    
var $name            null;
    
/** @var string The login name*/
    
var $username        null;
    
/** @var string email*/
    
var $email            null;
    
/** @var string MD5 encrypted password*/
    
var $password        null;
    
/** @var string */
    
var $usertype        null;
    
/** @var int */
    
var $block            null;
    
/** @var int */
    
var $sendEmail        null;
    
/** @var int The group id number */
    
var $gid            null;
    
/** @var datetime */
    
var $registerDate    null;
    
/** @var datetime */
    
var $lastvisitDate    null;
    
/** @var string activation hash*/
    
var $activation        null;
    
/** @var string */
    
var $params            null;

    
/**
    * @param database A database connector object
    */
    
function mosUser( &$database ) {
        
$this->mosDBTable'#__users''id'$database );
    }

    
/**
     * Validation and filtering
     * @return boolean True is satisfactory
     */
    
function check() {
        global 
$mosConfig_uniquemail;

        
// filter malicious code
        //$this->filter();

        // Validate user information
        
if (trim$this->name ) == '') {
            
$this->_error _REGWARN_NAME;
            return 
false;
        }

        if (
trim$this->username ) == '') {
            
$this->_error _REGWARN_UNAME;
            return 
false;
        }

        if (
eregi"[\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-]"$this->username) || strlen$this->username ) < 3) {
            
$this->_error sprintf_VALID_AZ09_PROMPT_UNAME);
            return 
false;
        }

        if ((
trim($this->email == "")) || (preg_match("/[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}/"$this->email )==false)) {
            
$this->_error _REGWARN_MAIL;
            return 
false;
        }

        
// check for existing username
        
$query "SELECT id"
        
"\n FROM #__users "
        
"\n WHERE username = '$this->username'"
        
"\n AND id != " . (int)$this->id
        
;
        
$this->_db->setQuery$query );
        
$xid intval$this->_db->loadResult() );
        if (
$xid && $xid != intval$this->id )) {
            
$this->_error _REGWARN_INUSE;
            return 
false;
        }

        if (
$mosConfig_uniquemail) {
            
// check for existing email
            
$query "SELECT id"
            
"\n FROM #__users "
            
"\n WHERE email = '$this->email'"
            
"\n AND id != " . (int)$this->id
            
;
            
$this->_db->setQuery$query );
            
$xid intval$this->_db->loadResult() );
            if (
$xid && $xid != intval$this->id )) {
                
$this->_error _REGWARN_EMAIL_INUSE;
                return 
false;
            }
        }

        return 
true;
    }

    function 
store$updateNulls=false ) {
        global 
$acl$migrate;
        
$section_value 'users';

        
$k $this->_tbl_key;
        
$key =  $this->$k;
        if( 
$key && !$migrate) {
            
// existing record
            
$ret $this->_db->updateObject$this->_tbl$this$this->_tbl_key$updateNulls );
            
// syncronise ACL
            // single group handled at the moment
            // trivial to expand to multiple groups
            
$groups $acl->get_object_groups$section_value$this->$k'ARO' );
            
$acl->del_group_object$groups[0], $section_value$this->$k'ARO' );
            
$acl->add_group_object$this->gid$section_value$this->$k'ARO' );

            
$object_id $acl->get_object_id$section_value$this->$k'ARO' );
            
$acl->edit_object$object_id$section_value$this->_db->getEscaped$this->name ), $this->$k00'ARO' );
        } else {
            
// new record
            
$ret $this->_db->insertObject$this->_tbl$this$this->_tbl_key );
            
// syncronise ACL
            
$acl->add_object$section_value$this->_db->getEscaped$this->name ), $this->$knullnull'ARO' );
            
$acl->add_group_object$this->gid$section_value$this->$k'ARO' );
        }
        if( !
$ret ) {
            
$this->_error strtolower(get_class$this ))."::store failed <br />" $this->_db->getErrorMsg();
            return 
false;
        } else {
            return 
true;
        }
    }

    function 
delete$oid=null ) {
        global 
$acl;

        
$k $this->_tbl_key;
        if (
$oid) {
            
$this->$k intval$oid );
        }
        
$aro_id $acl->get_object_id'users'$this->$k'ARO' );
//        $acl->del_object( $aro_id, 'ARO', true );

        
$query "DELETE FROM $this->_tbl"
        
"\n WHERE $this->_tbl_key = '"$this->$k ."'"
        
;
        
$this->_db->setQuery$query );

        if (
$this->_db->query()) {
            
// cleanup related data

            // :: private messaging
            
$query "DELETE FROM #__messages_cfg"
            
"\n WHERE user_id = "$this->$k .""
            
;
            
$this->_db->setQuery$query );
            if (!
$this->_db->query()) {
                
$this->_error $this->_db->getErrorMsg();
                return 
false;
            }
            
$query "DELETE FROM #__messages"
            
"\n WHERE user_id_to = "$this->$k .""
            
;
            
$this->_db->setQuery$query );
            if (!
$this->_db->query()) {
                
$this->_error $this->_db->getErrorMsg();
                return 
false;
            }

            return 
true;
        } else {
            
$this->_error $this->_db->getErrorMsg();
            return 
false;
        }
    }

    
/**
     * Gets the users from a group
     * @param string The value for the group (not used 1.0)
     * @param string The name for the group
     * @param string If RECURSE, will drill into child groups
     * @param string Ordering for the list
     * @return array
     */
    
function getUserListFromGroup$value$name$recurse='NO_RECURSE'$order='name' ) {
        global 
$acl;

        
// Change back in
        //$group_id = $acl->get_group_id( $value, $name, $group_type = 'ARO');
        
$group_id $acl->get_group_id$name$group_type 'ARO');
        
$objects $acl->get_group_objects$group_id'ARO''RECURSE');

        if (isset( 
$objects['users'] )) {
            
$gWhere '(id =' implode' OR id ='$objects['users'] ) . ')';

            
$query "SELECT id AS value, name AS text"
            
"\n FROM #__users"
            
"\n WHERE block = '0'"
            
"\n AND " $gWhere
            
"\n ORDER BY "$order
            
;
            
$this->_db->setQuery$query );
            
$options $this->_db->loadObjectList();
            return 
$options;
        } else {
            return array();
        }
    }
}

/**
* Template Table Class
*
* Provides access to the jos_templates table
* @package Joomla
*/
class mosTemplate extends mosDBTable {
    
/** @var int */
    
var $id                null;
    
/** @var string */
    
var $cur_template    null;
    
/** @var int */
    
var $col_main        null;

    
/**
    * @param database A database connector object
    */
    
function mosTemplate( &$database ) {
        
$this->mosDBTable'#__templates''id'$database );
    }
}

/**
 * Utility function to return a value from a named array or a specified default
 * @param array A named array
 * @param string The key to search for
 * @param mixed The default value to give if no key found
 * @param int An options mask: _MOS_NOTRIM prevents trim, _MOS_ALLOWHTML allows safe html, _MOS_ALLOWRAW allows raw input
 */
define"_MOS_NOTRIM"0x0001 );
define"_MOS_ALLOWHTML"0x0002 );
define"_MOS_ALLOWRAW"0x0004 );
function 
mosGetParam( &$arr$name$def=null$mask=) {
    static 
$noHtmlFilter     null;
    static 
$safeHtmlFilter     null;

    
$return null;
    if (isset( 
$arr[$name] )) {
        
$return $arr[$name];
        
        if (
is_string$return )) {
            
// trim data
            
if (!($mask&_MOS_NOTRIM)) {
                
$return trim$return );
            }
            
            if (
$mask&_MOS_ALLOWRAW) {
                
// do nothing
            
} else if ($mask&_MOS_ALLOWHTML) {
                
// do nothing - compatibility mode
                /*
                if (is_null( $safeHtmlFilter )) {
                    $safeHtmlFilter = new InputFilter( null, null, 1, 1 );
                }
                $arr[$name] = $safeHtmlFilter->process( $arr[$name] );
                */
            
} else {
                
// send to inputfilter
                
if (is_null$noHtmlFilter )) {
                    
$noHtmlFilter = new InputFilter/* $tags, $attr, $tag_method, $attr_method, $xss_auto */ );
                }
                
$return $noHtmlFilter->process$return );
            }
            
            
// account for magic quotes setting
            
if (!get_magic_quotes_gpc()) {
                
$return addslashes$return );
            }
        }
        
        return 
$return;
    } else {
        return 
$def;
    }
}

/**
 * Strip slashes from strings or arrays of strings
 * @param mixed The input string or array
 * @return mixed String or array stripped of slashes
 */
function mosStripslashes( &$value ) {
    
$ret '';
    if (
is_string$value )) {
        
$ret stripslashes$value );
    } else {
        if (
is_array$value )) {
            
$ret = array();
            foreach (
$value as $key => $val) {
                
$ret[$key] = mosStripslashes$val );
            }
        } else {
            
$ret $value;
        }
    }
    return 
$ret;
}

/**
* Copy the named array content into the object as properties
* only existing properties of object are filled. when undefined in hash, properties wont be deleted
* @param array the input array
* @param obj byref the object to fill of any class
* @param string
* @param boolean
*/
function mosBindArrayToObject$array, &$obj$ignore=''$prefix=NULL$checkSlashes=true ) {
    if (!
is_array$array ) || !is_object$obj )) {
        return (
false);
    }

    foreach (
get_object_vars($obj) as $k => $v) {
        if( 
substr$k0) != '_' ) {            // internal attributes of an object are ignored
            
if (strpos$ignore$k) === false) {
                if (
$prefix) {
                    
$ak $prefix $k;
                } else {
                    
$ak $k;
                }
                if (isset(
$array[$ak])) {
                    
$obj->$k = ($checkSlashes && get_magic_quotes_gpc()) ? mosStripslashes$array[$ak] ) : $array[$ak];
                }
            }
        }
    }

    return 
true;
}

/**
* Utility function to read the files in a directory
* @param string The file system path
* @param string A filter for the names
* @param boolean Recurse search into sub-directories
* @param boolean True if to prepend the full path to the file name
*/
function mosReadDirectory$path$filter='.'$recurse=false$fullpath=false  ) {
    
$arr = array();
    if (!@
is_dir$path )) {
        return 
$arr;
    }
    
$handle opendir$path );

    while (
$file readdir($handle)) {
        
$dir mosPathName$path.'/'.$filefalse );
        
$isDir is_dir$dir );
        if ((
$file != ".") && ($file != "..")) {
            if (
preg_match"/$filter/"$file )) {
                if (
$fullpath) {
                    
$arr[] = trimmosPathName$path.'/'.$filefalse ) );
                } else {
                    
$arr[] = trim$file );
                }
            }
            if (
$recurse && $isDir) {
                
$arr2 mosReadDirectory$dir$filter$recurse$fullpath );
                
$arr array_merge$arr$arr2 );
            }
        }
    }
    
closedir($handle);
    
asort($arr);
    return 
$arr;
}

/**
* Utility function redirect the browser location to another url
*
* Can optionally provide a message.
* @param string The file system path
* @param string A filter for the names
*/
function mosRedirect$url$msg='' ) {

   global 
$mainframe;

    
// specific filters
    
$iFilter = new InputFilter();
    
$url $iFilter->process$url );
    if (!empty(
$msg)) {
        
$msg $iFilter->process$msg );
    }

    if (
$iFilter->badAttributeValue( array( 'href'$url ))) {
        
$url $GLOBALS['mosConfig_live_site'];
    }

    if (
trim$msg )) {
         if (
strpos$url'?' )) {
            
$url .= '&mosmsg=' urlencode$msg );
        } else {
            
$url .= '?mosmsg=' urlencode$msg );
        }
    }

    if (
headers_sent()) {
        echo 
"<script>document.location.href='$url';</script>\n";
    } else {
        @
ob_end_clean(); // clear output buffer
        
header'HTTP/1.1 301 Moved Permanently' );
        
header"Location: "$url );
    }
    exit();
}

function 
mosErrorAlert$text$action='window.history.go(-1);'$mode=) {
    
$text nl2br$text );
    
$text addslashes$text );
    
$text strip_tags$text );

    switch ( 
$mode ) {
        case 
2:
            echo 
"<script>$action</script> \n";
            break;

        case 
1:
        default:
            echo 
"<script>alert('$text'); $action</script> \n";
            
//echo '<noscript>';
            //mosRedirect( @$_SERVER['HTTP_REFERER'], $text );
            //echo '</noscript>';
            
break;
    }

    exit;
}

function 
mosTreeRecurse$id$indent$list, &$children$maxlevel=9999$level=0$type=) {
    if (@
$children[$id] && $level <= $maxlevel) {
        foreach (
$children[$id] as $v) {
            
$id $v->id;

            if ( 
$type ) {
                
$pre     '<sup>L</sup>&nbsp;';
                
$spacer '.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
            } else {
                
$pre     '- ';
                
$spacer '&nbsp;&nbsp;';
            }

            if ( 
$v->parent == ) {
                
$txt     $v->name;
            } else {
                
$txt     $pre $v->name;
            }
            
$pt $v->parent;
            
$list[$id] = $v;
            
$list[$id]->treename "$indent$txt";
            
$list[$id]->children count( @$children[$id] );
            
$list mosTreeRecurse$id$indent $spacer$list$children$maxlevel$level+1$type );
        }
    }
    return 
$list;
}

/**
* Function to strip additional / or \ in a path name
* @param string The path
* @param boolean Add trailing slash
*/
function mosPathName($p_path,$p_addtrailingslash true) {
    
$retval "";

    
$isWin = (substr(PHP_OS03) == 'WIN');

    if (
$isWin)    {
        
$retval str_replace'/''\\'$p_path );
        if (
$p_addtrailingslash) {
            if (
substr$retval, -) != '\\') {
                
$retval .= '\\';
            }
        }
        
// Remove double \\
        
$retval str_replace'\\\\''\\'$retval );
    } else {
        
$retval str_replace'\\''/'$p_path );
        if (
$p_addtrailingslash) {
            if (
substr$retval, -) != '/') {
                
$retval .= '/';
            }
        }
        
// Remove double //
        
$retval str_replace('//','/',$retval);
    }

    return 
$retval;
}

/**
* Class mosMambot
* @package Joomla
*/
class mosMambot extends mosDBTable {
    
/** @var int */
    
var $id                    null;
    
/** @var varchar */
    
var $name                null;
    
/** @var varchar */
    
var $element            null;
    
/** @var varchar */
    
var $folder                null;
    
/** @var tinyint unsigned */
    
var $access                null;
    
/** @var int */
    
var $ordering            null;
    
/** @var tinyint */
    
var $published            null;
    
/** @var tinyint */
    
var $iscore                null;
    
/** @var tinyint */
    
var $client_id            null;
    
/** @var int unsigned */
    
var $checked_out        null;
    
/** @var datetime */
    
var $checked_out_time    null;
    
/** @var text */
    
var $params                null;

    function 
mosMambot( &$db ) {
        
$this->mosDBTable'#__mambots''id'$db );
    }
}

/**
* Module database table class
* @package Joomla
*/
class mosModule extends mosDBTable {
    
/** @var int Primary key */
    
var $id                    null;
    
/** @var string */
    
var $title                null;
    
/** @var string */
    
var $showtitle            null;
    
/** @var int */
    
var $content            null;
    
/** @var int */
    
var $ordering            null;
    
/** @var string */
    
var $position            null;
    
/** @var boolean */
    
var $checked_out        null;
    
/** @var time */
    
var $checked_out_time    null;
    
/** @var boolean */
    
var $published            null;
    
/** @var string */
    
var $module                null;
    
/** @var int */
    
var $numnews            null;
    
/** @var int */
    
var $access                null;
    
/** @var string */
    
var $params                null;
    
/** @var string */
    
var $iscore                null;
    
/** @var string */
    
var $client_id            null;

    
/**
    * @param database A database connector object
    */
    
function mosModule( &$db ) {
        
$this->mosDBTable'#__modules''id'$db );
    }
    
// overloaded check function
    
function check() {
        
// check for valid name
        
if (trim$this->title ) == '') {
            
$this->_error "Your Module must contain a title.";
            return 
false;
        }

        
// limitation has been removed
        // check for existing title
        //$this->_db->setQuery( "SELECT id FROM #__modules"
        //. "\nWHERE title='$this->title'"
        //);
        // check for module of same name
        //$xid = intval( $this->_db->loadResult() );
        //if ($xid && $xid != intval( $this->id )) {
        //    $this->_error = "There is a module already with that name, please try again.";
        //    return false;
        //}
        
return true;
    }
}

/**
* Session database table class
* @package Joomla
*/
class mosSession extends mosDBTable {
    
/** @var int Primary key */
    
var $session_id            null;
    
/** @var string */
    
var $time                null;
    
/** @var string */
    
var $userid                null;
    
/** @var string */
    
var $usertype            null;
    
/** @var string */
    
var $username            null;
    
/** @var time */
    
var $gid                null;
    
/** @var int */
    
var $guest                null;
    
/** @var string */
    
var $_session_cookie    null;

    
/**
    * @param database A database connector object
    */
    
function mosSession( &$db ) {
        
$this->mosDBTable'#__session''session_id'$db );
    }

    
/**
     * @param string Key search for
     * @param mixed Default value if not set
     * @return mixed
     */
    
function get$key$default=null ) {
        return 
mosGetParam$_SESSION$key$default );
    }

    
/**
     * @param string Key to set
     * @param mixed Value to set
     * @return mixed The new value
     */
    
function set$key$value ) {
        
$_SESSION[$key] = $value;
        return 
$value;
    }

    
/**
     * Sets a key from a REQUEST variable, otherwise uses the default
     * @param string The variable key
     * @param string The REQUEST variable name
     * @param mixed The default value
     * @return mixed
     */
    
function setFromRequest$key$varName$default=null ) {
        if (isset( 
$_REQUEST[$varName] )) {
            return 
mosSession::set$key$_REQUEST[$varName] );
        } else if (isset( 
$_SESSION[$key] )) {
            return 
$_SESSION[$key];
        } else {
            return 
mosSession::set$key$default );
        }
    }

    
/**
     * Insert a new row
     * @return boolean
     */
    
function insert() {
        
$ret $this->_db->insertObject$this->_tbl$this );

        if( !
$ret ) {
            
$this->_error strtolower(get_class$this ))."::store failed <br />" $this->_db->stderr();
            return 
false;
        } else {
            return 
true;
        }
    }

    
/**
     * Update an existing row
     * @return boolean
     */
    
function update$updateNulls=false ) {
        
$ret $this->_db->updateObject$this->_tbl$this'session_id'$updateNulls );

        if( !
$ret ) {
            
$this->_error strtolower(get_class$this ))."::store failed <br />" $this->_db->stderr();
            return 
false;
        } else {
            return 
true;
        }
    }

    
/**
     * Generate a unique session id
     * @return string
     */
    
function generateId() {
        
$failsafe 20;
        
$randnum 0;
        while (
$failsafe--) {
            
$randnum md5uniqidmicrotime(), ) );
            if (
$randnum != "") {
                
$cryptrandnum md5$randnum );
                
$query "SELECT $this->_tbl_key"
                
"\n FROM $this->_tbl"
                
"\n WHERE $this->_tbl_key = MD5( '$randnum' )"
                
;
                
$this->_db->setQuery$query );
                if(!
$result $this->_db->query()) {
                    die( 
$this->_db->stderrtrue ));
                    
// todo: handle gracefully
                
}
                if (
$this->_db->getNumRows($result) == 0) {
                    break;
                }
            }
        }
        
        
$this->_session_cookie $randnum;        
        
$this->session_id mosMainFrame::sessionCookieValue$randnum );
    }

    
/**
     * @return string The name of the session cookie
     */
    
function getCookie() {
        return 
$this->_session_cookie;
    }

    
/**
     * Purge lapsed sessions
     * @return boolean
     */
    
function purge$inc=1800$and='' ) {
        
$past time() - $inc;
        
$query "DELETE FROM $this->_tbl"
        
"\n WHERE ( time < '$past' )"
        
$and
        
;
        
$this->_db->setQuery($query);

        return 
$this->_db->query();
    }
}


function 
mosObjectToArray($p_obj) {
    
$retarray null;
    if(
is_object($p_obj))
    {
        
$retarray = array();
        foreach (
get_object_vars($p_obj) as $k => $v)
        {
            if(
is_object($v))
            
$retarray[$k] = mosObjectToArray($v);
            else
            
$retarray[$k] = $v;
        }
    }
    return 
$retarray;
}
/**
* Checks the user agent string against known browsers
*/
function mosGetBrowser$agent ) {
    require( 
'includes/agent_browser.php' );

    if (
preg_match"/msie[\/\sa-z]*([\d\.]*)/i"$agent$m )
    && !
preg_match"/webtv/i"$agent )
    && !
preg_match"/omniweb/i"$agent )
    && !
preg_match"/opera/i"$agent )) {
        
// IE
        
return "MS Internet Explorer $m[1]";
    } else if (
preg_match"/netscape.?\/([\d\.]*)/i"$agent$m )) {
        
// Netscape 6.x, 7.x ...
        
return "Netscape $m[1]";
    } else if ( 
preg_match"/mozilla[\/\sa-z]*([\d\.]*)/i"$agent$m )
    && !
preg_match"/gecko/i"$agent )
    && !
preg_match"/compatible/i"$agent )
    && !
preg_match"/opera/i"$agent )
    && !
preg_match"/galeon/i"$agent )
    && !
preg_match"/safari/i"$agent )) {
        
// Netscape 3.x, 4.x ...
        
return "Netscape $m[1]";
    } else {
        
// Other
        
$found false;
        foreach (
$browserSearchOrder as $key) {
            if (
preg_match"/$key.?\/([\d\.]*)/i"$agent$m )) {
                
$name "$browsersAlias[$key] $m[1]";
                return 
$name;
                break;
            }
        }
    }

    return 
'Unknown';
}

/**
* Checks the user agent string against known operating systems
*/
function mosGetOS$agent ) {
    require( 
"includes/agent_os.php" );

    foreach (
$osSearchOrder as $key) {
        if (
preg_match"/$key/i"$agent )) {
            return 
$osAlias[$key];
            break;
        }
    }

    return 
'Unknown';
}

/**
* @param string SQL with ordering As value and 'name field' AS text
* @param integer The length of the truncated headline
*/
function mosGetOrderingList$sql$chop='30' ) {
    global 
$database;

    
$order = array();
    
$database->setQuery$sql );
    if (!(
$orders $database->loadObjectList())) {
        if (
$database->getErrorNum()) {
            echo 
$database->stderr();
            return 
false;
        } else {
            
$order[] = mosHTML::makeOption1'first' );
            return 
$order;
        }
    }
    
$order[] = mosHTML::makeOption0'0 first' );
    for (
$i=0$n=count$orders ); $i $n$i++) {

        if (
strlen($orders[$i]->text) > $chop) {
            
$text substr($orders[$i]->text,0,$chop)."...";
        } else {
            
$text $orders[$i]->text;
        }

        
$order[] = mosHTML::makeOption$orders[$i]->value$orders[$i]->value.' ('.$text.')' );
    }
    
$order[] = mosHTML::makeOption$orders[$i-1]->value+1, ($orders[$i-1]->value+1).' last' );

    return 
$order;
}

/**
* Makes a variable safe to display in forms
*
* Object parameters that are non-string, array, object or start with underscore
* will be converted
* @param object An object to be parsed
* @param int The optional quote style for the htmlspecialchars function
* @param string|array An optional single field name or array of field names not
*                     to be parsed (eg, for a textarea)
*/
function mosMakeHtmlSafe( &$mixed$quote_style=ENT_QUOTES$exclude_keys='' ) {
    if (
is_object$mixed )) {
        foreach (
get_object_vars$mixed ) as $k => $v) {
            if (
is_array$v ) || is_object$v ) || $v == NULL || substr$k1) == '_' ) {
                continue;
            }
            if (
is_string$exclude_keys ) && $k == $exclude_keys) {
                continue;
            } else if (
is_array$exclude_keys ) && in_array$k$exclude_keys )) {
                continue;
            }
            
$mixed->$k htmlspecialchars$v$quote_style );
        }
    }
}

/**
* Checks whether a menu option is within the users access level
* @param int Item id number
* @param string The menu option
* @param int The users group ID number
* @param database A database connector object
* @return boolean True if the visitor's group at least equal to the menu access
*/
function mosMenuCheck$Itemid$menu_option$task$gid ) {
    global 
$database;
    
    
$dblink "index.php?option=$menu_option";
    
    if ( 
$Itemid != '' && $Itemid != && $Itemid != 99999999 ) {
        
$query "SELECT access"
        
"\n FROM #__menu"
        
"\n WHERE id = $Itemid"
        
;
    } else {
        if (
$task != '') {
            
$dblink    .= "&task=$task";
        }
        
        
$query "SELECT access"
        
"\n FROM #__menu"
        
"\n WHERE link LIKE '$dblink%'"
        
;
    }
    
$database->setQuery$query );
    
$results     $database->loadObjectList();
    
$access     0;
    
    foreach (
$results as $result) {
        
$access max$access$result->access );
    }
    
    return (
$access <= $gid);
}

/**
* Returns formated date according to current local and adds time offset
* @param string date in datetime format
* @param string format optional format for strftime
* @param offset time offset if different than global one
* @returns formated date
*/
function mosFormatDate$date$format=""$offset=NULL ){
    global 
$mosConfig_offset;
    if ( 
$format == '' ) {
        
// %Y-%m-%d %H:%M:%S
        
$format _DATE_FORMAT_LC;
    }
    if ( 
is_null($offset) ) {
        
$offset $mosConfig_offset;
    }
    if ( 
$date && ereg"([0-9]{4})-([0-9]{2})-([0-9]{2})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})"$date$regs ) ) {
        
$date mktime$regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1] );
        
$date $date > -strftime$format$date + ($offset*60*60) ) : '-';
    }
    return 
$date;
}

/**
* Returns current date according to current local and time offset
* @param string format optional format for strftime
* @returns current date
*/
function mosCurrentDate$format="" ) {
    global 
$mosConfig_offset;
    if (
$format=="") {
        
$format _DATE_FORMAT_LC;
    }
    
$date strftime$formattime() + ($mosConfig_offset*60*60) );
    return 
$date;
}

/**
* Utility function to provide ToolTips
* @param string ToolTip text
* @param string Box title
* @returns HTML code for ToolTip
*/
function mosToolTip$tooltip$title=''$width=''$image='tooltip.png'$text=''$href='#'$link=) {
    global 
$mosConfig_live_site;

    if ( 
$width ) {
        
$width ', WIDTH, \''.$width .'\'';
    }
    if ( 
$title ) {
        
$title ', CAPTION, \''.$title .'\'';
    }
    if ( !
$text ) {
        
$image     $mosConfig_live_site '/includes/js/ThemeOffice/'$image;
        
$text     '<img src="'$image .'" border="0" alt="tooltip"/>';
    }
    
$style 'style="text-decoration: none; color: #333;"';
    if ( 
$href ) {
        
$style '';
    } else{
        
$href '#';
    }

    
$mousover 'return overlib(\''$tooltip .'\''$title .', BELOW, RIGHT'$width .');';

    
$tip "<!-- Tooltip -->\n";
    if ( 
$link ) {
        
$tip .= '<a href="'$href .'" onmouseover="'$mousover .'" onmouseout="return nd();" '$style .'>'$text .'</a>';
    } else {
        
$tip .= '<span onmouseover="'$mousover .'" onmouseout="return nd();" '$style .'>'$text .'</span>';
    }

    return 
$tip;
}

/**
* Utility function to provide Warning Icons
* @param string Warning text
* @param string Box title
* @returns HTML code for Warning
*/
function mosWarning($warning$title='Joomla! Warning') {
    global 
$mosConfig_live_site;

    
$mouseover     'return overlib(\''$warning .'\', CAPTION, \''$title .'\', BELOW, RIGHT);';

    
$tip         "<!-- Warning -->\n";
    
$tip         .= '<a href="javascript:void(0)" onmouseover="'$mouseover .'" onmouseout="return nd();">';
    
$tip         .= '<img src="'$mosConfig_live_site .'/includes/js/ThemeOffice/warning.png" border="0"  alt="warning"/></a>';

    return 
$tip;
}

function 
mosCreateGUID(){
    
srand((double)microtime()*1000000);
    
$r rand ;
    
$u uniqid(getmypid() . $r . (double)microtime()*1000000,1);
    
$m md5 ($u);
    return(
$m);
}

function 
mosCompressID$ID ){
    return(
Base64_encode(pack("H*",$ID)));
}

function 
mosExpandID$ID ) {
    return ( 
implode(unpack("H*",Base64_decode($ID)), '') );
}

/**
* Function to create a mail object for futher use (uses phpMailer)
* @param string From e-mail address
* @param string From name
* @param string E-mail subject
* @param string Message body
* @return object Mail object
*/
function mosCreateMail$from=''$fromname=''$subject$body ) {
    global 
$mosConfig_absolute_path$mosConfig_sendmail;
    global 
$mosConfig_smtpauth$mosConfig_smtpuser;
    global 
$mosConfig_smtppass$mosConfig_smtphost;
    global 
$mosConfig_mailfrom$mosConfig_fromname$mosConfig_mailer;

    
$mail = new mosPHPMailer();

    
$mail->PluginDir $mosConfig_absolute_path .'/includes/phpmailer/';
    
$mail->SetLanguage'en'$mosConfig_absolute_path '/includes/phpmailer/language/' );
    
$mail->CharSet     substr_replace(_ISO''08);
    
$mail->IsMail();
    
$mail->From     $from $from $mosConfig_mailfrom;
    
$mail->FromName $fromname $fromname $mosConfig_fromname;
    
$mail->Mailer     $mosConfig_mailer;

    
// Add smtp values if needed
    
if ( $mosConfig_mailer == 'smtp' ) {
        
$mail->SMTPAuth $mosConfig_smtpauth;
        
$mail->Username $mosConfig_smtpuser;
        
$mail->Password $mosConfig_smtppass;
        
$mail->Host     $mosConfig_smtphost;
    } else

    
// Set sendmail path
    
if ( $mosConfig_mailer == 'sendmail' ) {
        if (isset(
$mosConfig_sendmail))
            
$mail->Sendmail $mosConfig_sendmail;
    } 
// if

    
$mail->Subject     $subject;
    
$mail->Body     $body;

    return 
$mail;
}

/**
* Mail function (uses phpMailer)
* @param string From e-mail address
* @param string From name
* @param string/array Recipient e-mail address(es)
* @param string E-mail subject
* @param string Message body
* @param boolean false = plain text, true = HTML
* @param string/array CC e-mail address(es)
* @param string/array BCC e-mail address(es)
* @param string/array Attachment file name(s)
* @param string/array ReplyTo e-mail address(es)
* @param string/array ReplyTo name(s)
*/
function mosMail$from$fromname$recipient$subject$body$mode=0$cc=NULL$bcc=NULL$attachment=NULL$replyto=NULL$replytoname=NULL ) {
    global 
$mosConfig_debug;
    
$mail mosCreateMail$from$fromname$subject$body );

    
// activate HTML formatted emails
    
if ( $mode ) {
        
$mail->IsHTML(true);
    }

    if (
is_array$recipient )) {
        foreach (
$recipient as $to) {
            
$mail->AddAddress$to );
        }
    } else {
        
$mail->AddAddress$recipient );
    }
    if (isset( 
$cc )) {
        if (
is_array$cc )) {
            foreach (
$cc as $to) {
                
$mail->AddCC($to);
            }
        } else {
            
$mail->AddCC($cc);
        }
    }
    if (isset( 
$bcc )) {
        if (
is_array$bcc )) {
            foreach (
$bcc as $to) {
                
$mail->AddBCC$to );
            }
        } else {
            
$mail->AddBCC$bcc );
        }
    }
    if (
$attachment) {
        if (
is_array$attachment )) {
            foreach (
$attachment as $fname) {
                
$mail->AddAttachment$fname );
            }
        } else {
            
$mail->AddAttachment($attachment);
        }
    }
    
//Important for being able to use mosMail without spoofing...
    
if ($replyto) {
        if (
is_array$replyto )) {
            
reset$replytoname );
            foreach (
$replyto as $to) {
                
$toname = ((list( $key$value ) = each$replytoname )) ? $value '');
                
$mail->AddReplyTo$to$toname );
            }
        } else {
            
$mail->AddReplyTo($replyto$replytoname);
        }
    }

    
$mailssend $mail->Send();

    if( 
$mosConfig_debug ) {
        
//$mosDebug->message( "Mails send: $mailssend");
    
}
    if( 
$mail->error_count ) {
        
//$mosDebug->message( "The mail message $fromname <$from> about $subject to $recipient <b>failed</b><br /><pre>$body</pre>", false );
        //$mosDebug->message( "Mailer Error: " . $mail->ErrorInfo . "" );
    
}
    return 
$mailssend;
// mosMail

/**
 * Initialise GZIP
 */
function initGzip() {
    global 
$mosConfig_gzip$do_gzip_compress;
    
    
$do_gzip_compress FALSE;
    if (
$mosConfig_gzip == 1) {
        
$phpver     phpversion();
        
$useragent     mosGetParam$_SERVER'HTTP_USER_AGENT''' );
        
$canZip     mosGetParam$_SERVER'HTTP_ACCEPT_ENCODING''' );
        
        
$gzip_check     0;
        
$zlib_check     0;
        
$gz_check        0;
        
$zlibO_check    0;
        
$sid_check        0;
        if ( 
strpos$canZip'gzip' ) !== false) {
            
$gzip_check 1;
        }        
        if ( 
extension_loaded'zlib' ) ) {
            
$zlib_check 1;
        }        
        if ( 
function_exists('ob_gzhandler') ) {
            
$gz_check 1;
        }
        if ( 
ini_get('zlib.output_compression') ) {
            
$zlibO_check 1;
        }
        if ( 
ini_get('session.use_trans_sid') ) {
            
$sid_check 1;
        }

        if ( 
$phpver >= '4.0.4pl1' && ( strpos($useragent,'compatible') !== false || strpos($useragent,'Gecko')    !== false ) ) {
            
// Check for gzip header or northon internet securities or session.use_trans_sid
            
if ( ( $gzip_check || isset( $_SERVER['---------------']) ) && $zlib_check && $gz_check && !$zlibO_check && !$sid_check ) {
                
// You cannot specify additional output handlers if
                // zlib.output_compression is activated here
                
ob_start'ob_gzhandler' );
                return;
            }
        } else if ( 
$phpver '4.0' ) {
            if ( 
$gzip_check ) {
                if ( 
$zlib_check ) {
                    
$do_gzip_compress TRUE;
                    
ob_start();
                    
ob_implicit_flush(0);
                    
                    
header'Content-Encoding: gzip' );
                    return;
                }
            }
        }
    }
    
ob_start();
}

/**
* Perform GZIP
*/
function doGzip() {
    global 
$do_gzip_compress;
    if ( 
$do_gzip_compress ) {
        
/**
        *Borrowed from php.net!
        */
        
$gzip_contents ob_get_contents();
        
ob_end_clean();

        
$gzip_size strlen($gzip_contents);
        
$gzip_crc crc32($gzip_contents);

        
$gzip_contents gzcompress($gzip_contents9);
        
$gzip_contents substr($gzip_contents0strlen($gzip_contents) - 4);

        echo 
"\x1f\x8b\x08\x00\x00\x00\x00\x00";
        echo 
$gzip_contents;
        echo 
pack('V'$gzip_crc);
        echo 
pack('V'$gzip_size);
    } else {
        
ob_end_flush();
    }
}

/**
* Random password generator
* @return password
*/
function mosMakePassword($length=8) {
    
$salt         "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    
$len         strlen($salt);
    
$makepass    '';
    
mt_srand(10000000*(double)microtime());
    for (
$i 0$i $length$i++)
    
$makepass .= $salt[mt_rand(0,$len 1)];
    return 
$makepass;
}

if (!
function_exists('html_entity_decode')) {
    
/**
    * html_entity_decode function for backward compatability in PHP
    * @param string
    * @param string
    */
    
function html_entity_decode ($string$opt ENT_COMPAT) {

        
$trans_tbl get_html_translation_table (HTML_ENTITIES);
        
$trans_tbl array_flip ($trans_tbl);

        if (
$opt 1) { // Translating single quotes
            // Add single quote to translation table;
            // doesn't appear to be there by default
            
$trans_tbl["&apos;"] = "'";
        }

        if (!(
$opt 2)) { // Not translating double quotes
            // Remove double quote from translation table
            
unset($trans_tbl["&quot;"]);
        }

        return 
strtr ($string$trans_tbl);
    }
}

/**
* Plugin handler
* @package Joomla
*/
class mosMambotHandler {
    
/** @var array An array of functions in event groups */
    
var $_events            null;
    
/** @var array An array of lists */
    
var $_lists                null;
    
/** @var array An array of mambots */
    
var $_bots                null;
    
/** @var int Index of the mambot being loaded */
    
var $_loading            null;
    
    
/** Added as of 1.0.8 to ensure queries are only called once **/
    
    /** @var array An array of the content mambots in the system */
    
var $_content_mambots    null;
    
/** @var array An array of the content mambot params */
    
var $_content_mambot_params    = array();

    
/**
    * Constructor
    */
    
function mosMambotHandler() {
        
$this->_events = array();
    }
    
/**
    * Loads all the bot files for a particular group
    * @param string The group name, relates to the sub-directory in the mambots directory
    */
    
function loadBotGroup$group ) {
        global 
$database$my;

        
$group trim$group );
        if (
is_object$my )) {
            
$gid $my->gid;
        } else {
            
$gid 0;
        }

        
$group trim$group );

        switch ( 
$group ) {
            case 
'content':
                if (!
defined'_JOS_CONTENT_MAMBOTS' )) {
                    
/** ensure that query is only called once */
                    
define'_JOS_CONTENT_MAMBOTS');
    
                    
$query "SELECT folder, element, published, params"
                    
"\n FROM #__mambots"
                    
"\n WHERE access <= $gid"
                    
"\n AND folder = 'content'"
                    
"\n ORDER BY ordering"
                    
;
                    
$database->setQuery$query );
                
                    
// load query into class variable _content_mambots
                    
if (!($this->_content_mambots $database->loadObjectList())) {
                        
//echo "Error loading Mambots: " . $database->getErrorMsg();
                        
return false;
                    }
                }
                
                
// pull bots to be processed from class variable 
                
$bots $this->_content_mambots;
                break;

            default:
                
$query "SELECT folder, element, published, params"
                
"\n FROM #__mambots"
                
"\n WHERE published >= 1"
                
"\n AND access <= $gid"
                
"\n AND folder = '$group'"
                
"\n ORDER BY ordering"
                
;
                
$database->setQuery$query );
            
                if (!(
$bots $database->loadObjectList())) {
                    
//echo "Error loading Mambots: " . $database->getErrorMsg();
                    
return false;
                }
                break;
        }
        
        
// load bots found by queries
        
$n count$bots);
        for (
$i 0$i $n$i++) {            
            
$this->loadBot$bots[$i]->folder$bots[$i]->element$bots[$i]->published$bots[$i]->params );
        }

        return 
true;
    }
    
/**
     * Loads the bot file
     * @param string The folder (group)
     * @param string The elements (name of file without extension)
     * @param int Published state
     * @param string The params for the bot
     */
    
function loadBot$folder$element$published$params='' ) {
        global 
$mosConfig_absolute_path;
        global 
$_MAMBOTS;

        
$path $mosConfig_absolute_path '/mambots/' $folder '/' $element '.php';
        if (
file_exists$path )) {
            
$this->_loading count$this->_bots );
            
$bot = new stdClass;
            
$bot->folder     $folder;
            
$bot->element     $element;
            
$bot->published $published;
            
$bot->lookup     $folder '/' $element;
            
$bot->params     $params;
            
$this->_bots[]     = $bot;

            require_once( 
$path );

            
$this->_loading null;
        }
    }
    
/**
    * Registers a function to a particular event group
    * @param string The event name
    * @param string The function name
    */
    
function registerFunction$event$function ) {
        
$this->_events[$event][] = array( $function$this->_loading );
    }
    
/**
    * Makes a option for a particular list in a group
    * @param string The group name
    * @param string The list name
    * @param string The value for the list option
    * @param string The text for the list option
    */
    
function addListOption$group$listName$value$text='' ) {
        
$this->_lists[$group][$listName][] = mosHTML::makeOption$value$text );
    }
    
/**
    * @param string The group name
    * @param string The list name
    * @return array
    */
    
function getList$group$listName ) {
        return 
$this->_lists[$group][$listName];
    }
    
/**
    * Calls all functions associated with an event group
    * @param string The event name
    * @param array An array of arguments
    * @param boolean True is unpublished bots are to be processed
    * @return array An array of results from each function call
    */
    
function trigger$event$args=null$doUnpublished=false ) {
        
$result = array();

        if (
$args === null) {
            
$args = array();
        }
        if (
$doUnpublished) {
            
// prepend the published argument
            
array_unshift$argsnull );
        }
        if (isset( 
$this->_events[$event] )) {
            foreach (
$this->_events[$event] as $func) {
                if (
function_exists$func[0] )) {
                    if (
$doUnpublished) {
                        
$args[0] = $this->_bots[$func[1]]->published;
                        
$result[] = call_user_func_array$func[0], $args );
                    } else if (
$this->_bots[$func[1]]->published) {
                        
$result[] = call_user_func_array$func[0], $args );
                    }
                }
            }
        }
        return 
$result;
    }
    
/**
    * Same as trigger but only returns the first event and
    * allows for a variable argument list
    * @param string The event name
    * @return array The result of the first function call
    */
    
function call$event ) {
        
$doUnpublished=false;

        
$args =& func_get_args();
        
array_shift$args );

        if (isset( 
$this->_events[$event] )) {
            foreach (
$this->_events[$event] as $func) {
                if (
function_exists$func[0] )) {
                    if (
$this->_bots[$func[1]]->published) {
                        return 
call_user_func_array$func[0], $args );
                    }
                }
            }
        }
        return 
null;
    }
}

/**
* Tab Creation handler
* @package Joomla
*/
class mosTabs {
    
/** @var int Use cookies */
    
var $useCookies 0;

    
/**
    * Constructor
    * Includes files needed for displaying tabs and sets cookie options
    * @param int useCookies, if set to 1 cookie will hold last used tab between page refreshes
    */
    
function mosTabs$useCookies$xhtml=NULL ) {
        global 
$mosConfig_live_site$mainframe;

        if ( 
$xhtml ) {
            
$mainframe->addCustomHeadTag'<link rel="stylesheet" type="text/css" media="all" href="includes/js/tabs/tabpane.css" id="luna-tab-style-sheet" />' );
        } else {
            echo 
"<link id=\"luna-tab-style-sheet\" type=\"text/css\" rel=\"stylesheet\" href=\"" $mosConfig_live_site"/includes/js/tabs/tabpane.css\" />";
        }

        echo 
"<script type=\"text/javascript\" src=\""$mosConfig_live_site "/includes/js/tabs/tabpane_mini.js\"></script>";

        
$this->useCookies $useCookies;
    }

    
/**
    * creates a tab pane and creates JS obj
    * @param string The Tab Pane Name
    */
    
function startPane($id){
        echo 
"<div class=\"tab-page\" id=\"".$id."\">";
        echo 
"<script type=\"text/javascript\">\n";
        echo 
"    var tabPane1 = new WebFXTabPane( document.getElementById( \"".$id."\" ), ".$this->useCookies." )\n";
        echo 
"</script>\n";
    }

    
/**
    * Ends Tab Pane
    */
    
function endPane() {
        echo 
"</div>";
    }

    
/*
    * Creates a tab with title text and starts that tabs page
    * @param tabText - This is what is displayed on the tab
    * @param paneid - This is the parent pane to build this tab on
    */
    
function startTab$tabText$paneid ) {
        echo 
"<div class=\"tab-page\" id=\"".$paneid."\">";
        echo 
"<h2 class=\"tab\">".$tabText."</h2>";
        echo 
"<script type=\"text/javascript\">\n";
        echo 
"  tabPane1.addTabPage( document.getElementById( \"".$paneid."\" ) );";
        echo 
"</script>";
    }

    
/*
    * Ends a tab page
    */
    
function endTab() {
        echo 
"</div>";
    }
}

/**
* Common HTML Output Files
* @package Joomla
*/
class mosAdminMenus {
    
/**
    * build the select list for Menu Ordering
    */
    
function Ordering( &$row$id ) {
        global 
$database;

        if ( 
$id ) {
            
$query "SELECT ordering AS value, name AS text"
            
"\n FROM #__menu"
            
"\n WHERE menutype = '$row->menutype'"
            
"\n AND parent = $row->parent"
            
"\n AND published != -2"
            
"\n ORDER BY ordering"
            
;
            
$order mosGetOrderingList$query );
            
$ordering mosHTML::selectList$order'ordering''class="inputbox" size="1"''value''text'intval$row->ordering ) );
        } else {
            
$ordering '<input type="hidden" name="ordering" value="'$row->ordering .'" />'_CMN_NEW_ITEM_LAST;
        }
        return 
$ordering;
    }

    
/**
    * build the select list for access level
    */
    
function Access( &$row ) {
        global 
$database;

        
$query "SELECT id AS value, name AS text"
        
"\n FROM #__groups"
        
"\n ORDER BY id"
        
;
        
$database->setQuery$query );
        
$groups $database->loadObjectList();
        
$access mosHTML::selectList$groups'access''class="inputbox" size="3"''value''text'intval$row->access ) );

        return 
$access;
    }

    
/**
    * build the select list for parent item
    */
    
function Parent( &$row ) {
        global 
$database;

        
$id '';
        if ( 
$row->id ) {
            
$id "\n AND id != $row->id";
        }
        
        
// get a list of the menu items
        // excluding the current menu item and its child elements
        
$query "SELECT m.*"
        
"\n FROM #__menu m"
        
"\n WHERE menutype = '$row->menutype'"
        
"\n AND published != -2"
        
$id
        
"\n ORDER BY parent, ordering"
        
;
        
$database->setQuery$query );
        
$mitems $database->loadObjectList();

        
// establish the hierarchy of the menu
        
$children = array();
            
        if ( 
$mitems ) {
            
// first pass - collect children
            
foreach ( $mitems as $v ) {
                
$pt     $v->parent;
                
$list     = @$children[$pt] ? $children[$pt] : array();
                
array_push$list$v );
                
$children[$pt] = $list;
            }
        }

        
// second pass - get an indent list of the items
        
$list mosTreeRecurse0'', array(), $children99990);
            
        
// assemble menu items to the array
        
$mitems     = array();
        
$mitems[]     = mosHTML::makeOption'0''Top' );
        
        foreach ( 
$list as $item ) {
            
$mitems[] = mosHTML::makeOption$item->id'&nbsp;&nbsp;&nbsp;'$item->treename );
        }

        
$output mosHTML::selectList$mitems'parent''class="inputbox" size="10"''value''text'$row->parent );
        
        return 
$output;
    }

    
/**
    * build a radio button option for published state
    */
    
function Published( &$row ) {
        
$published mosHTML::yesnoRadioList'published''class="inputbox"'$row->published );
        return 
$published;
    }

    
/**
    * build the link/url of a menu item
    */
    
function Link( &$row$id$link=NULL ) {
        if ( 
$id ) {
            if ( 
$link ) {
                
$link $row->link;
            } else {
                
$link $row->link .'&amp;Itemid='$row->id;
            }
        } else {
            
$link NULL;
        }
        return 
$link;
    }

    
/**
    * build the select list for target window
    */
    
function Target( &$row ) {
        
$click[] = mosHTML::makeOption'0''Parent Window With Browser Navigation' );
        
$click[] = mosHTML::makeOption'1''New Window With Browser Navigation' );
        
$click[] = mosHTML::makeOption'2''New Window Without Browser Navigation' );
        
$target mosHTML::selectList$click'browserNav''class="inputbox" size="4"''value''text'intval$row->browserNav ) );
        return 
$target;
    }

    
/**
    * build the multiple select list for Menu Links/Pages
    */
    
function MenuLinks( &$lookup$all=NULL$none=NULL$unassigned=) {
        global 
$database;

        
// get a list of the menu items
        
$query "SELECT m.*"
        
"\n FROM #__menu AS m"
        
"\n WHERE m.published = 1"
        
//. "\n AND m.type != 'separator'"
        
"\n AND NOT ("
            
"\n ( m.type = 'url' )"
            
"\n AND ( m.link LIKE '%index.php%' )"
            
"\n AND ( m.link LIKE '%Itemid=%' )"
        
"\n )"
        
"\n ORDER BY m.menutype, m.parent, m.ordering"
        
;
        
$database->setQuery$query );
        
$mitems $database->loadObjectList();
        
$mitems_temp $mitems;

        
// establish the hierarchy of the menu
        
$children = array();
        
// first pass - collect children
        
foreach ( $mitems as $v ) {
            
$id $v->id;
            
$pt $v->parent;
            
$list = @$children[$pt] ? $children[$pt] : array();
            
array_push$list$v );
            
$children[$pt] = $list;
        }
        
// second pass - get an indent list of the items
        
$list mosTreeRecurseintval$mitems[0]->parent ), '', array(), $children99990);

        
// Code that adds menu name to Display of Page(s)
        
$text_count "0";
        
$mitems_spacer $mitems_temp[0]->menutype;
        foreach (
$list as $list_a) {
            foreach (
$mitems_temp as $mitems_a) {
                if (
$mitems_a->id == $list_a->id) {
                    
// Code that inserts the blank line that seperates different menus
                    
if ($mitems_a->menutype != $mitems_spacer) {
                        
$list_temp[] = mosHTML::makeOption( -999'----' );
                        
$mitems_spacer $mitems_a->menutype;
                    }
                    
$text $mitems_a->menutype." | ".$list_a->treename;
                    
$list_temp[] = mosHTML::makeOption$list_a->id$text );
                    if ( 
strlen($text) > $text_count) {
                        
$text_count strlen($text);
                    }
                }
            }
        }
        
$list $list_temp;

        
$mitems = array();
        if ( 
$all ) {
            
// prepare an array with 'all' as the first item
            
$mitems[] = mosHTML::makeOption0'All' );
            
// adds space, in select box which is not saved
            
$mitems[] = mosHTML::makeOption( -999'----' );
        }
        if ( 
$none ) {
            
// prepare an array with 'all' as the first item
            
$mitems[] = mosHTML::makeOption( -999'None' );
            
// adds space, in select box which is not saved
            
$mitems[] = mosHTML::makeOption( -999'----' );
        }
        if ( 
$none ) {
            
// prepare an array with 'all' as the first item
            
$mitems[] = mosHTML::makeOption99999999'Unassigned' );
            
// adds space, in select box which is not saved
            
$mitems[] = mosHTML::makeOption( -999'----' );
        }
        
// append the rest of the menu items to the array
        
foreach ($list as $item) {
            
$mitems[] = mosHTML::makeOption$item->value$item->text );
        }
        
$pages mosHTML::selectList$mitems'selections[]''class="inputbox" size="26" multiple="multiple"''value''text'$lookup );
        return 
$pages;
    }


    
/**
    * build the select list to choose a category
    */
    
function Category( &$menu$id$javascript='' ) {
        global 
$database;

        
$query "SELECT c.id AS `value`, c.section AS `id`, CONCAT_WS( ' / ', s.title, c.title) AS `text`"
        
"\n FROM #__sections AS s"
        
"\n INNER JOIN #__categories AS c ON c.section = s.id"
        
"\n WHERE s.scope = 'content'"
        
"\n ORDER BY s.name, c.name"
        
;
        
$database->setQuery$query );
        
$rows $database->loadObjectList();
        
$category '';
        if ( 
$id ) {
            foreach ( 
$rows as $row ) {
                if ( 
$row->value == $menu->componentid ) {
                    
$category $row->text;
                }
            }
            
$category .= '<input type="hidden" name="componentid" value="'$menu->componentid .'" />';
            
$category .= '<input type="hidden" name="link" value="'$menu->link .'" />';
        } else {
            
$category mosHTML::selectList$rows'componentid''class="inputbox" size="10"'$javascript'value''text' );
            
$category .= '<input type="hidden" name="link" value="" />';
        }
        return 
$category;
    }

    
/**
    * build the select list to choose a section
    */
    
function Section( &$menu$id$all=) {
        global 
$database;

        
$query "SELECT s.id AS `value`, s.id AS `id`, s.title AS `text`"
        
"\n FROM #__sections AS s"
        
"\n WHERE s.scope = 'content'"
        
"\n ORDER BY s.name"
        
;
        
$database->setQuery$query );
        if ( 
$all ) {
            
$rows[] = mosHTML::makeOption0'- All Sections -' );
            
$rows array_merge$rows$database->loadObjectList() );
        } else {
            
$rows $database->loadObjectList();
        }

        if ( 
$id ) {
            foreach ( 
$rows as $row ) {
                if ( 
$row->value == $menu->componentid ) {
                    
$section $row->text;
                }
            }
            
$section .= '<input type="hidden" name="componentid" value="'$menu->componentid .'" />';
            
$section .= '<input type="hidden" name="link" value="'$menu->link .'" />';
        } else {
            
$section mosHTML::selectList$rows'componentid''class="inputbox" size="10"''value''text' );
            
$section .= '<input type="hidden" name="link" value="" />';
        }
        return 
$section;
    }

    
/**
    * build the select list to choose a component
    */
    
function Component( &$menu$id ) {
        global 
$database;

        
$query "SELECT c.id AS value, c.name AS text, c.link"
        
"\n FROM #__components AS c"
        
"\n WHERE c.link != ''"
        
"\n ORDER BY c.name"
        
;
        
$database->setQuery$query );
        
$rows $database->loadObjectList( );

        if ( 
$id ) {
            
// existing component, just show name
            
foreach ( $rows as $row ) {
                if ( 
$row->value == $menu->componentid ) {
                    
$component $row->text;
                }
            }
            
$component .= '<input type="hidden" name="componentid" value="'$menu->componentid .'" />';
        } else {
            
$component mosHTML::selectList$rows'componentid''class="inputbox" size="10"''value''text' );
        }
        return 
$component;
    }

    
/**
    * build the select list to choose a component
    */
    
function ComponentName( &$menu$id ) {
        global 
$database;

        
$query "SELECT c.id AS value, c.name AS text, c.link"
        
"\n FROM #__components AS c"
        
"\n WHERE c.link != ''"
        
"\n ORDER BY c.name"
        
;
        
$database->setQuery$query );
        
$rows $database->loadObjectList( );

        
$component 'Component';
        foreach ( 
$rows as $row ) {
            if ( 
$row->value == $menu->componentid ) {
                
$component $row->text;
            }
        }

        return 
$component;
    }

    
/**
    * build the select list to choose an image
    */
    
function Images$name, &$active$javascript=NULL$directory=NULL ) {
        global 
$mosConfig_absolute_path;

        if ( !
$javascript ) {
            
$javascript "onchange=\"javascript:if (document.forms[0].image.options[selectedIndex].value!='') {document.imagelib.src='../images/stories/' + document.forms[0].image.options[selectedIndex].value} else {document.imagelib.src='../images/blank.png'}\"";
        }
        if ( !
$directory ) {
            
$directory '/images/stories';
        }

        
$imageFiles mosReadDirectory$mosConfig_absolute_path $directory );
        
$images = array(  mosHTML::makeOption'''- Select Image -' ) );
        foreach ( 
$imageFiles as $file ) {
            if ( 
eregi"bmp|gif|jpg|png"$file ) ) {
                
$images[] = mosHTML::makeOption$file );
            }
        }
        
$images mosHTML::selectList$images$name'class="inputbox" size="1" '$javascript'value''text'$active );

        return 
$images;
    }

    
/**
    * build the select list for Ordering of a specified Table
    */
    
function SpecificOrdering( &$row$id$query$neworder=) {
        global 
$database;

        if ( 
$neworder ) {
            
$text _CMN_NEW_ITEM_FIRST;
        } else {
            
$text _CMN_NEW_ITEM_LAST;
        }

        if ( 
$id ) {
            
$order mosGetOrderingList$query );
            
$ordering mosHTML::selectList$order'ordering''class="inputbox" size="1"''value''text'intval$row->ordering ) );
        } else {
            
$ordering '<input type="hidden" name="ordering" value="'$row->ordering .'" />'$text;
        }
        return 
$ordering;
    }

    
/**
    * Select list of active users
    */
    
function UserSelect$name$active$nouser=0$javascript=NULL$order='name'$reg=) {
        global 
$database$my;

        
$and '';
        if ( 
$reg ) {
        
// does not include registered users in the list
            
$and "\n AND gid > 18";
        }

        
$query "SELECT id AS value, name AS text"
        
"\n FROM #__users"
        
"\n WHERE block = 0"
        
$and
        
"\n ORDER BY $order"
        
;
        
$database->setQuery$query );
        if ( 
$nouser ) {
            
$users[] = mosHTML::makeOption'0''- No User -' );
            
$users array_merge$users$database->loadObjectList() );
        } else {
            
$users $database->loadObjectList();
        }

        
$users mosHTML::selectList$users$name'class="inputbox" size="1" '$javascript'value''text'$active );

        return 
$users;
    }

    
/**
    * Select list of positions - generally used for location of images
    */
    
function Positions$name$active=NULL$javascript=NULL$none=1$center=1$left=1$right=) {
        if ( 
$none ) {
            
$pos[] = mosHTML::makeOption''_CMN_NONE );
        }
        if ( 
$center ) {
            
$pos[] = mosHTML::makeOption'center'_CMN_CENTER );
        }
        if ( 
$left ) {
            
$pos[] = mosHTML::makeOption'left'_CMN_LEFT );
        }
        if ( 
$right ) {
            
$pos[] = mosHTML::makeOption'right'_CMN_RIGHT );
        }

        
$positions mosHTML::selectList$pos$name'class="inputbox" size="1"'$javascript'value''text'$active );

        return 
$positions;
    }

    
/**
    * Select list of active categories for components
    */
    
function ComponentCategory$name$section$active=NULL$javascript=NULL$order='ordering'$size=1$sel_cat=) {
        global 
$database;

        
$query "SELECT id AS value, name AS text"
        
"\n FROM #__categories"
        
"\n WHERE section = '$section'"
        
"\n AND published = 1"
        
"\n ORDER BY $order"
        
;
        
$database->setQuery$query );
        if ( 
$sel_cat ) {
            
$categories[] = mosHTML::makeOption'0'_SEL_CATEGORY );
            
$categories array_merge$categories$database->loadObjectList() );
        } else {
            
$categories $database->loadObjectList();
        }

        if ( 
count$categories ) < ) {
            
mosRedirect'index2.php?option=com_categories&section='$section'You must create a category first.' );
        }

        
$category mosHTML::selectList$categories$name'class="inputbox" size="'$size .'" '$javascript'value''text'$active );

        return 
$category;
    }

    
/**
    * Select list of active sections
    */
    
function SelectSection$name$active=NULL$javascript=NULL$order='ordering' ) {
        global 
$database;

        
$categories[] = mosHTML::makeOption'0'_SEL_SECTION );
        
$query "SELECT id AS value, title AS text"
        
"\n FROM #__sections"
        
"\n WHERE published = 1"
        
"\n ORDER BY $order"
        
;
        
$database->setQuery$query );
        
$sections array_merge$categories$database->loadObjectList() );

        
$category mosHTML::selectList$sections$name'class="inputbox" size="1" '$javascript'value''text'$active );

        return 
$category;
    }

    
/**
    * Select list of menu items for a specific menu
    */
    
function Links2Menu$type$and ) {
        global 
$database;

        
$query "SELECT *"
        
"\n FROM #__menu"
        
"\n WHERE type = '$type'"
        
"\n AND published = 1"
        
$and
        
;
        
$database->setQuery$query );
        
$menus $database->loadObjectList();

        return 
$menus;
    }

    
/**
     * Select list of menus
     * @param string The control name
     * @param string Additional javascript
     * @return string A select list
     */
    
function MenuSelect$name='menuselect'$javascript=NULL ) {
        global 
$database;

        
$query "SELECT params"
        
"\n FROM #__modules"
        
"\n WHERE module = 'mod_mainmenu'"
        
;
        
$database->setQuery$query );
        
$menus $database->loadObjectList();
        
$total count$menus );
        
$menuselect = array();
        for( 
$i 0$i $total$i++ ) {
            
$params mosParseParams$menus[$i]->params );
            
$menuselect[$i]->value     $params->menutype;
            
$menuselect[$i]->text     $params->menutype;
        }
        
// sort array of objects
        
SortArrayObjects$menuselect'text');

        
$menus mosHTML::selectList$menuselect$name'class="inputbox" size="10" '$javascript'value''text' );

        return 
$menus;
    }

    
/**
    * Internal function to recursive scan the media manager directories
    * @param string Path to scan
    * @param string root path of this folder
    * @param array  Value array of all existing folders
    * @param array  Value array of all existing images
    */
    
function ReadImages$imagePath$folderPath, &$folders, &$images ) {
        
$imgFiles mosReadDirectory$imagePath );

        foreach (
$imgFiles as $file) {
            
$ff_     $folderPath $file .'/';
            
$ff     $folderPath $file;
            
$i_f     $imagePath .'/'$file;

            if ( 
is_dir$i_f ) && $file != 'CVS' && $file != '.svn') {
                
$folders[] = mosHTML::makeOption$ff_ );
                
mosAdminMenus::ReadImages$i_f$ff_$folders$images );
            } else if ( 
eregi"bmp|gif|jpg|png"$file ) && is_file$i_f ) ) {
                
// leading / we don't need
                
$imageFile substr$ff);
                
$images[$folderPath][] = mosHTML::makeOption$imageFile$file );
            }
        }
    }

    function 
GetImageFolders( &$folders$path ) {
        
$javascript     "onchange=\"changeDynaList( 'imagefiles', folderimages, document.adminForm.folders.options[document.adminForm.folders.selectedIndex].value, 0, 0);  previewImage( 'imagefiles', 'view_imagefiles', '$path/' );\"";
        
$getfolders     mosHTML::selectList$folders'folders''class="inputbox" size="1" '$javascript'value''text''/' );
        return 
$getfolders;
    }

    function 
GetImages( &$images$path ) {
        if ( !isset(
$images['/'] ) ) {
            
$images['/'][] = mosHTML::makeOption'' );
        }

        
//$javascript    = "onchange=\"previewImage( 'imagefiles', 'view_imagefiles', '$path/' )\" onfocus=\"previewImage( 'imagefiles', 'view_imagefiles', '$path/' )\"";
        
$javascript    "onchange=\"previewImage( 'imagefiles', 'view_imagefiles', '$path/' )\"";
        
$getimages    mosHTML::selectList$images['/'], 'imagefiles''class="inputbox" size="10" multiple="multiple" '$javascript 'value''text'null );

        return 
$getimages;
    }

    function 
GetSavedImages( &$row$path ) {
        
$images2 = array();
        foreach( 
$row->images as $file ) {
            
$temp explode'|'$file );
            if( 
strrchr($temp[0], '/') ) {
                
$filename substrstrrchr($temp[0], '/' ), );
            } else {
                
$filename $temp[0];
            }
            
$images2[] = mosHTML::makeOption$file$filename );
        }
        
//$javascript    = "onchange=\"previewImage( 'imagelist', 'view_imagelist', '$path/' ); showImageProps( '$path/' ); \" onfocus=\"previewImage( 'imagelist', 'view_imagelist', '$path/' )\"";
        
$javascript    "onchange=\"previewImage( 'imagelist', 'view_imagelist', '$path/' ); showImageProps( '$path/' ); \"";
        
$imagelist     mosHTML::selectList$images2'imagelist''class="inputbox" size="10" '$javascript'value''text' );

        return 
$imagelist;
    }

    
/**
    * Checks to see if an image exists in the current templates image directory
     * if it does it loads this image.  Otherwise the default image is loaded.
    * Also can be used in conjunction with the menulist param to create the chosen image
    * load the default or use no image
    */
    
function ImageCheck$file$directory='/images/M_images/'$param=NULL$param_directory='/images/M_images/'$alt=NULL$name='image'$type=1$align='middle' ) {
        global 
$mosConfig_absolute_path$mosConfig_live_site$mainframe;

        
$cur_template $mainframe->getTemplate();

        
$name = ( $name 'name="'$name .'"' '' );
        
        if ( 
$param ) {
            
$image $mosConfig_live_site$param_directory $param;
            if ( 
$type ) {
                
$image '<img src="'$image .'" align="'$align .'" alt="'$alt .'" '$name .' border="0" />';
            }
        } else if ( 
$param == -) {
            
$image '';
        } else {
            if ( 
file_exists$mosConfig_absolute_path .'/templates/'$cur_template .'/images/'$file ) ) {
                
$image $mosConfig_live_site .'/templates/'$cur_template .'/images/'$file;
            } else {
                
// outputs only path to image
                
$image $mosConfig_live_site$directory $file;
            }

            
// outputs actual html <img> tag
            
if ( $type ) {
                
$image '<img src="'$image .'" alt="'$alt .'" align="'$align .'" '$name .' border="0" />';
            }
        }

        return 
$image;
    }

    
/**
    * Checks to see if an image exists in the current templates image directory
     * if it does it loads this image.  Otherwise the default image is loaded.
    * Also can be used in conjunction with the menulist param to create the chosen image
    * load the default or use no image
    */
    
function ImageCheckAdmin$file$directory='/administrator/images/'$param=NULL$param_directory='/administrator/images/'$alt=NULL$name=NULL$type=1$align='middle' ) {
        global 
$mosConfig_absolute_path$mosConfig_live_site$mainframe;
        
        
$cur_template $mainframe->getTemplate();

        
$name = ( $name 'name="'$name .'"' '' );
        
        if ( 
$param ) {
            
$image $mosConfig_live_site$param_directory $param;
            if ( 
$type ) {
                
$image '<img src="'$image .'" align="'$align .'" alt="'$alt .'" '$name .' border="0" />';
            }
        } else if ( 
$param == -) {
            
$image '';
        } else {
            if ( 
file_exists$mosConfig_absolute_path .'/administrator/templates/'$cur_template .'/images/'$file ) ) {
                
$image $mosConfig_live_site .'/administrator/templates/'$cur_template .'/images/'$file;
            } else {
                
$image $mosConfig_live_site$directory $file;
            }

            
// outputs actual html <img> tag
            
if ( $type ) {
                
$image '<img src="'$image .'" alt="'$alt .'" align="'$align .'" '$name .' border="0" />';
            }
        }

        return 
$image;
    }

    function 
menutypes() {
        global 
$database;

        
$query "SELECT params"
        
"\n FROM #__modules"
        
"\n WHERE module = 'mod_mainmenu'"
        
"\n ORDER BY title"
        
;
        
$database->setQuery$query    );
        
$modMenus $database->loadObjectList();

        
$query "SELECT menutype"
        
"\n FROM #__menu"
        
"\n GROUP BY menutype"
        
"\n ORDER BY menutype"
        
;
        
$database->setQuery$query    );
        
$menuMenus $database->loadObjectList();

        
$menuTypes '';
        foreach ( 
$modMenus as $modMenu ) {
            
$check 1;
            
mosMakeHtmlSafe$modMenu) ;
            
$modParams     mosParseParams$modMenu->params );
            
$menuType     = @$modParams->menutype;
            if (!
$menuType) {
                
$menuType 'mainmenu';
            }

            
// stop duplicate menutype being shown
            
if ( !is_array$menuTypes) ) {
                
// handling to create initial entry into array
                
$menuTypes[] = $menuType;
            } else {
                
$check 1;
                foreach ( 
$menuTypes as $a ) {
                    if ( 
$a == $menuType ) {
                        
$check 0;
                    }
                }
                if ( 
$check ) {
                    
$menuTypes[] = $menuType;
                }
            }

        }
        
// add menutypes from jos_menu
        
foreach ( $menuMenus as $menuMenu ) {
            
$check 1;
            foreach ( 
$menuTypes as $a ) {
                if ( 
$a == $menuMenu->menutype ) {
                    
$check 0;
                }
            }
            if ( 
$check ) {
                
$menuTypes[] = $menuMenu->menutype;
            }
        }

        
// sorts menutypes
        
asort$menuTypes );

        return 
$menuTypes;
    }

    
/*
    * loads files required for menu items
    */
    
function menuItem$item ) {
        global 
$mosConfig_absolute_path;

        
$path $mosConfig_absolute_path .'/administrator/components/com_menus/'$item .'/';
        include_once( 
$path $item .'.class.php' );
        include_once( 
$path $item .'.menu.html.php' );
    }
}


class 
mosCommonHTML {

    function 
ContentLegend( ) {
        
?>
        <table cellspacing="0" cellpadding="4" border="0" align="center">
        <tr align="center">
            <td>
            <img src="images/publish_y.png" width="12" height="12" border="0" alt="Pending" />
            </td>
            <td>
            Published, but is <u>Pending</u> |
            </td>
            <td>
            <img src="images/publish_g.png" width="12" height="12" border="0" alt="Visible" />
            </td>
            <td>
            Published and is <u>Current</u> |
            </td>
            <td>
            <img src="images/publish_r.png" width="12" height="12" border="0" alt="Finished" />
            </td>
            <td>
            Published, but has <u>Expired</u> |
            </td>
            <td>
            <img src="images/publish_x.png" width="12" height="12" border="0" alt="Finished" />
            </td>
            <td>
            Not Published
            </td>
        </tr>
        <tr>
            <td colspan="8" align="center">
            Click on icon to toggle state.
            </td>
        </tr>
        </table>
        <?php
    
}

    function 
menuLinksContent( &$menus ) {
        
?>
        <script language="javascript" type="text/javascript">
        function go2( pressbutton, menu, id ) {
            var form = document.adminForm;

            // assemble the images back into one field
            var temp = new Array;
            for (var i=0, n=form.imagelist.options.length; i < n; i++) {
                temp[i] = form.imagelist.options[i].value;
            }
            form.images.value = temp.join( '\n' );

            if (pressbutton == 'go2menu') {
                form.menu.value = menu;
                submitform( pressbutton );
                return;
            }

            if (pressbutton == 'go2menuitem') {
                form.menu.value     = menu;
                form.menuid.value     = id;
                submitform( pressbutton );
                return;
            }
        }
        </script>
        <?php
        
foreach( $menus as $menu ) {
            
?>
            <tr>
                <td colspan="2">
                <hr />
                </td>
            </tr>
            <tr>
                <td width="90px" valign="top">
                Menu
                </td>
                <td>
                <a href="javascript:go2( 'go2menu', '<?php echo $menu->menutype?>' );" title="Go to Menu">
                <?php echo $menu->menutype?>
                </a>
                </td>
            </tr>
            <tr>
                <td width="90px" valign="top">
                Link Name
                </td>
                <td>
                <strong>
                <a href="javascript:go2( 'go2menuitem', '<?php echo $menu->menutype?>', '<?php echo $menu->id?>' );" title="Go to Menu Item">
                <?php echo $menu->name?>
                </a>
                </strong>
                </td>
            </tr>
            <tr>
                <td width="90px" valign="top">
                State
                </td>
                <td>
                <?php
                
switch ( $menu->published ) {
                    case -
2:
                        echo 
'<font color="red">Trashed</font>';
                        break;
                    case 
0:
                        echo 
'UnPublished';
                        break;
                    case 
1:
                    default:
                        echo 
'<font color="green">Published</font>';
                        break;
                }
                
?>
                </td>
            </tr>
            <?php
        
}
        
?>
        <input type="hidden" name="menu" value="" />
        <input type="hidden" name="menuid" value="" />
        <?php
    
}

    function 
menuLinksSecCat( &$menus ) {
        
?>
        <script language="javascript" type="text/javascript">
        function go2( pressbutton, menu, id ) {
            var form = document.adminForm;

            if (pressbutton == 'go2menu') {
                form.menu.value = menu;
                submitform( pressbutton );
                return;
            }

            if (pressbutton == 'go2menuitem') {
                form.menu.value     = menu;
                form.menuid.value     = id;
                submitform( pressbutton );
                return;
            }
        }
        </script>
        <?php
        
foreach( $menus as $menu ) {
            
?>
            <tr>
                <td colspan="2">
                <hr/>
                </td>
            </tr>
            <tr>
                <td width="90px" valign="top">
                Menu
                </td>
                <td>
                <a href="javascript:go2( 'go2menu', '<?php echo $menu->menutype?>' );" title="Go to Menu">
                <?php echo $menu->menutype?>
                </a>
                </td>
            </tr>
            <tr>
                <td width="90px" valign="top">
                Type
                </td>
                <td>
                <?php echo $menu->type?>
                </td>
            </tr>
            <tr>
                <td width="90px" valign="top">
                Item Name
                </td>
                <td>
                <strong>
                <a href="javascript:go2( 'go2menuitem', '<?php echo $menu->menutype?>', '<?php echo $menu->id?>' );" title="Go to Menu Item">
                <?php echo $menu->name?>
                </a>
                </strong>
                </td>
            </tr>
            <tr>
                <td width="90px" valign="top">
                State
                </td>
                <td>
                <?php
                
switch ( $menu->published ) {
                    case -
2:
                        echo 
'<font color="red">Trashed</font>';
                        break;
                    case 
0:
                        echo 
'UnPublished';
                        break;
                    case 
1:
                    default:
                        echo 
'<font color="green">Published</font>';
                        break;
                }
                
?>
                </td>
            </tr>
            <?php
        
}
        
?>
        <input type="hidden" name="menu" value="" />
        <input type="hidden" name="menuid" value="" />
        <?php        
    
}

    function 
checkedOut( &$row$overlib=) {
        
$hover '';
        if ( 
$overlib ) {
            
$date                 mosFormatDate$row->checked_out_time'%A, %d %B %Y' );
            
$time                mosFormatDate$row->checked_out_time'%H:%M' );
            
$checked_out_text     '<table>';
            
$checked_out_text     .= '<tr><td>'$row->editor .'</td></tr>';
            
$checked_out_text     .= '<tr><td>'$date .'</td></tr>';
            
$checked_out_text     .= '<tr><td>'$time .'</td></tr>';
            
$checked_out_text     .= '</table>';
            
$hover 'onMouseOver="return overlib(\''$checked_out_text .'\', CAPTION, \'Checked Out\', BELOW, RIGHT);" onMouseOut="return nd();"';
        }
        
$checked             '<img src="images/checked_out.png" '$hover .'/>';

        return 
$checked;
    }

    
/*
    * Loads all necessary files for JS Overlib tooltips
    */
    
function loadOverlib() {
        global  
$mosConfig_live_site$mainframe;

        if ( !
$mainframe->get'loadOverlib' ) ) {
        
// check if this function is already loaded
            
?>
            <script language="javascript" type="text/javascript" src="<?php echo $mosConfig_live_site;?>/includes/js/overlib_mini.js"></script>
            <script language="javascript" type="text/javascript" src="<?php echo $mosConfig_live_site;?>/includes/js/overlib_hideform_mini.js"></script>
            <div id="overDiv" style="position:absolute; visibility:hidden; z-index:10000;"></div>
            <?php
            
// change state so it isnt loaded a second time
            
$mainframe->set'loadOverlib'true );
        }
    }


    
/*
    * Loads all necessary files for JS Calendar
    */
    
function loadCalendar() {
        global  
$mosConfig_live_site;
        
?>
        <link rel="stylesheet" type="text/css" media="all" href="<?php echo $mosConfig_live_site;?>/includes/js/calendar/calendar-mos.css" title="green" />
        <!-- import the calendar script -->
        <script type="text/javascript" src="<?php echo $mosConfig_live_site;?>/includes/js/calendar/calendar_mini.js"></script>
        <!-- import the language module -->
        <script type="text/javascript" src="<?php echo $mosConfig_live_site;?>/includes/js/calendar/lang/calendar-en.js"></script>
        <?php
    
}

    function 
AccessProcessing( &$row$i ) {
        if ( !
$row->access ) {
            
$color_access 'style="color: green;"';
            
$task_access 'accessregistered';
        } else if ( 
$row->access == ) {
            
$color_access 'style="color: red;"';
            
$task_access 'accessspecial';
        } else {
            
$color_access 'style="color: black;"';
            
$task_access 'accesspublic';
        }

        
$href '
        <a href="javascript: void(0);" onclick="return listItemTask(\'cb'
$i .'\',\''$task_access .'\')" '$color_access .'>
        '
$row->groupname .'
        </a>'
        
;

        return 
$href;
    }

    function 
CheckedOutProcessing( &$row$i ) {
        global 
$my;

        if ( 
$row->checked_out && $row->checked_out != $my->id) {
            
$checked mosCommonHTML::checkedOut$row );
        } else {
            
$checked mosHTML::idBox$i$row->id, ($row->checked_out && $row->checked_out != $my->id ) );
        }

        return 
$checked;
    }

    function 
PublishedProcessing( &$row$i ) {
        
$img     $row->published 'publish_g.png' 'publish_x.png';
        
$task     $row->published 'unpublish' 'publish';
        
$alt     $row->published 'Published' 'Unpublished';
        
$action    $row->published 'Unpublish Item' 'Publish item';

        
$href '
        <a href="javascript: void(0);" onclick="return listItemTask(\'cb'
$i .'\',\''$task .'\')" title="'$action .'">
        <img src="images/'
$img .'" border="0" alt="'$alt .'" />
        </a>'
        
;

        return 
$href;
    }

    
/*
    * Special handling for newfeed encoding and possible conflicts with page encoding and PHP version
    * Added 1.0.8
    * Static Function
    */    
    
function newsfeedEncoding$rssDoc ) {    
        
// test if PHP 5
        
if ( phpversion() >= ) {        
            
// test if page is utf-8
            
if ( strpos(_ISO,'utf')!== false || strpos(_ISO,'UTF') !== false ) {
                
$encoding 'html_entity_decode';
            } else {
            
// non utf-8 page
                
$encoding 'utf8_decode';
            }
        } else {
        
// handling for PHP 4
            // determine encoding of feed
            
$text         $rssDoc->toNormalizedString(true);
            
$text         substr$text0100 );
            
$utf8         strpos$text'encoding=&quot;utf-8&quot;' );
            
            
// test if feed is utf-8
            
if ( $utf8 !== false ) {
                
// test if page is utf-8
                
if ( strpos(_ISO,'utf')!== false || strpos(_ISO,'UTF') !== false ) {
                    
$encoding 'html_entity_decode';
                } else {
                    
// non utf-8 page
                    
$encoding 'utf8_decode';
                }
            } else {
            
// handling for non utf-8 feed
                // test if page is utf-8
                
if ( strpos(_ISO,'utf') !== false || strpos(_ISO,'UTF') !== false ) {
                    
$encoding 'utf8_encode';
                } else {
                    
// non utf-8 page
                    
$encoding 'html_entity_decode';
                }
            }                                
        }
        
        return 
$encoding;
    }
}

/**
* Sorts an Array of objects
*/
function SortArrayObjects_cmp( &$a, &$b ) {
    global 
$csort_cmp;

    if ( 
$a->$csort_cmp['key'] > $b->$csort_cmp['key'] ) {
        return 
$csort_cmp['direction'];
    }

    if ( 
$a->$csort_cmp['key'] < $b->$csort_cmp['key'] ) {
        return -
$csort_cmp['direction'];
    }

    return 
0;
}

/**
* Sorts an Array of objects
* sort_direction [1 = Ascending] [-1 = Descending]
*/
function SortArrayObjects( &$a$k$sort_direction=) {
    global 
$csort_cmp;

    
$csort_cmp = array(
        
'key'          => $k,
        
'direction'    => $sort_direction
    
);

    
usort$a'SortArrayObjects_cmp' );

    unset( 
$csort_cmp );
}

/**
* Sends mail to admin
*/
function mosSendAdminMail$adminName$adminEmail$email$type$title$author ) {
    global 
$mosConfig_mailfrom$mosConfig_fromname$mosConfig_live_site;

    
$subject _MAIL_SUB." '$type'";
    
$message _MAIL_MSG;
    eval (
"\$message = \"$message\";");
    
    
mosMail($mosConfig_mailfrom$mosConfig_fromname$adminEmail$subject$message);
}

/*
* Includes pathway file
*/
function mosPathWay() {
    
$Itemid mosGetParam($_REQUEST,'Itemid','');
    require 
$GLOBALS['mosConfig_absolute_path'] . '/includes/pathway.php';
}

/**
* Displays a not authorised message
*
* If the user is not logged in then an addition message is displayed.
*/
function mosNotAuth() {
    global 
$my;

    echo 
_NOT_AUTH;
    if (
$my->id 1) {
        echo 
"<br />" _DO_LOGIN;
    }
}

/**
* Replaces &amp; with & for xhtml compliance
*
* Needed to handle unicode conflicts due to unicode conflicts
*/
function ampReplace$text ) {
    
$text str_replace'&&''*--*'$text );
    
$text str_replace'&#''*-*'$text );
    
$text str_replace'&amp;''&'$text );
    
$text preg_replace'|&(?![\w]+;)|''&amp;'$text );
    
$text str_replace'*-*''&#'$text );
    
$text str_replace'*--*''&&'$text );

    return 
$text;
}
/**
* Prepares results from search for display
* @param string The source string
* @param int Number of chars to trim
* @param string The searchword to select around
* @return string
*/
function mosPrepareSearchContent$text$length=200$searchword ) {
    
// strips tags won't remove the actual jscript
    
$text preg_replace"'<script[^>]*>.*?</script>'si"""$text );
    
$text preg_replace'/{.+?}/'''$text);
    
//$text = preg_replace( '/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is','\2', $text );
    // replace line breaking tags with whitespace
    
$text preg_replace"'<(br[^/>]*?/|hr[^/>]*?/|/(div|h[1-6]|li|p|td))>'si"' '$text );

    return 
mosSmartSubstrstrip_tags$text ), $length$searchword );
}

/**
* returns substring of characters around a searchword
* @param string The source string
* @param int Number of chars to return
* @param string The searchword to select around
* @return string
*/
function mosSmartSubstr($text$length=200$searchword) {
  
$wordpos strpos(strtolower($text), strtolower($searchword));
  
$halfside intval($wordpos $length/strlen($searchword));
  if (
$wordpos && $halfside 0) {
    return 
'...' substr($text$halfside$length) . '...';
  } else {
    return 
substr$text0$length);
  }
}

/**
* Chmods files and directories recursively to given permissions. Available from 1.0.0 up.
* @param path The starting file or directory (no trailing slash)
* @param filemode Integer value to chmod files. NULL = dont chmod files.
* @param dirmode Integer value to chmod directories. NULL = dont chmod directories.
* @return TRUE=all succeeded FALSE=one or more chmods failed
*/
function mosChmodRecursive($path$filemode=NULL$dirmode=NULL)
{
    
$ret TRUE;
    if (
is_dir($path)) {
        
$dh opendir($path);
        while (
$file readdir($dh)) {
            if (
$file != '.' && $file != '..') {
                
$fullpath $path.'/'.$file;
                if (
is_dir($fullpath)) {
                    if (!
mosChmodRecursive($fullpath$filemode$dirmode))
                        
$ret FALSE;
                } else {
                    if (isset(
$filemode))
                        if (!@
chmod($fullpath$filemode))
                            
$ret FALSE;
                } 
// if
            
// if
        
// while
        
closedir($dh);
        if (isset(
$dirmode))
            if (!@
chmod($path$dirmode))
                
$ret FALSE;
    } else {
        if (isset(
$filemode))
            
$ret = @chmod($path$filemode);
    } 
// if
    
return $ret;
// mosChmodRecursive

/**
* Chmods files and directories recursively to mos global permissions. Available from 1.0.0 up.
* @param path The starting file or directory (no trailing slash)
* @param filemode Integer value to chmod files. NULL = dont chmod files.
* @param dirmode Integer value to chmod directories. NULL = dont chmod directories.
* @return TRUE=all succeeded FALSE=one or more chmods failed
*/
function mosChmod($path) {
    global 
$mosConfig_fileperms$mosConfig_dirperms;
    
$filemode NULL;
    if (
$mosConfig_fileperms != '')
        
$filemode octdec($mosConfig_fileperms);
    
$dirmode NULL;
    if (
$mosConfig_dirperms != '')
        
$dirmode octdec($mosConfig_dirperms);
    if (isset(
$filemode) || isset($dirmode))
        return 
mosChmodRecursive($path$filemode$dirmode);
    return 
TRUE;
// mosChmod

/**
 * Function to convert array to integer values
 * @param array
 * @param int A default value to assign if $array is not an array
 * @return array
 */
function mosArrayToInts( &$array$default=null ) {
    if (
is_array$array )) {
        
$n count$array );
        for (
$i 0$i $n$i++) {
            
$array[$i] = intval$array[$i] );
        }
    } else {
        if (
is_null$default )) {
            return array();
        } else {
            return array( 
$default );
        }
    }
}

/**
 * Utility class for helping with patTemplate
 */
class patHTML {
    
/**
     * Converts a named array to an array or named rows suitable to option lists
     * @param array The source array[key] = value
     * @param mixed A value or array of selected values
     * @param string The name for the value field
     * @param string The name for selected attribute (use 'checked' for radio of box lists)
     */
    
function selectArray( &$source$selected=null$valueName='value'$selectedAttr='selected' ) {
        if (!
is_array$selected )) {
            
$selected = array( $selected );
        }
        foreach (
$source as $i => $row) {
            if (
is_object$row )) {
                
$source[$i]->selected in_array$row->$valueName$selected ) ? $selectedAttr '="true"' '';
            } else {
                
$source[$i]['selected'] = in_array$row[$valueName], $selected ) ? $selectedAttr '="true"' '';
            }
        }
    }

    
/**
     * Converts a named array to an array or named rows suitable to checkbox or radio lists
     * @param array The source array[key] = value
     * @param mixed A value or array of selected values
     * @param string The name for the value field
     */
    
function checkArray( &$source$selected=null$valueName='value' ) {
        
patHTML::selectArray$source$selected$valueName'checked' );
    }

    
/**
     * @param mixed The value for the option
     * @param string The text for the option
     * @param string The name of the value parameter (default is value)
     * @param string The name of the text parameter (default is text)
     */
    
function makeOption$value$text$valueName='value'$textName='text' ) {
        return array(
            
$valueName => $value,
            
$textName => $text
        
);
    }

    
/**
     * Writes a radio pair
     * @param object Template object
     * @param string The template name
     * @param string The field name
     * @param int The value of the field
     * @param array Array of options
     * @param string Optional template variable name
     */
    
function radioSet( &$tmpl$template$name$value$a$varname=null ) {
        
patHTML::checkArray$a$value );

        
$tmpl->addVar'radio-set''name'$name );
        
$tmpl->addRows'radio-set'$a );
        
$tmpl->parseIntoVar'radio-set'$templateis_null$varname ) ? $name $varname );
    }

    
/**
     * Writes a radio pair
     * @param object Template object
     * @param string The template name
     * @param string The field name
     * @param int The value of the field
     * @param string Optional template variable name
     */
    
function yesNoRadio( &$tmpl$template$name$value$varname=null ) {
        
$a = array(
            
patHTML::makeOption0'No' ),
            
patHTML::makeOption1'Yes' )
        );
        
patHTML::radioSet$tmpl$template$name$value$a$varname );
    }
}

/**
 * Provides a secure hash based on a seed
 * @param string Seed string
 * @return string
 */
function mosHash$seed ) {
    return 
md5$GLOBALS['mosConfig_secret'] . md5$seed ) );
}

/**
 * Format a backtrace error
 * @since 1.0.5
 */
function mosBackTrace() {
    if (
function_exists'debug_backtrace' )) {
        echo 
'<div align="left">';
        foreach( 
debug_backtrace() as $back) {
            if (@
$back['file']) {
                echo 
'<br />' str_replace$GLOBALS['mosConfig_absolute_path'], ''$back['file'] ) . ':' $back['line'];
            }
        }
        echo 
'</div>';
    }
}

// ----- NO MORE CLASSES OR FUNCTIONS PASSED THIS POINT -----
// Post class declaration initialisations
// some version of PHP don't allow the instantiation of classes
// before they are defined

/** @global mosPlugin $_MAMBOTS */
$_MAMBOTS = new mosMambotHandler();
?>