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
|
<?php
/*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2010 - 2024 Roland Gruber
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* Interface between modules and other parts of LAM.
*
* @package metaHTML
* @author Roland Gruber
*/
/**
* Returns the marker for required values.
*
* @return string HTML code for required marker
*/
function htmlGetRequiredMarker(): string {
return '<span class="lam-required" title="' . _('required') . '">*</span>';
}
/**
* Returns the marker for required values.
*
* @return htmlSpan HTML code for required marker
*/
function htmlGetRequiredMarkerElement(): htmlSpan {
$span = new htmlSpan(new htmlOutputText('*'), ['lam-required']);
$span->setTitle(_('required'));
return $span;
}
/**
* Represents a HTML element.
* This is used to build HTML code by using objects.
*
* @package metaHTML
*/
abstract class htmlElement {
/** align to top */
public const ALIGN_TOP = 0;
/** align to left */
public const ALIGN_LEFT = 1;
/** align to right */
public const ALIGN_RIGHT = 2;
/** align to bottom */
public const ALIGN_BOTTOM = 3;
/** align to center */
public const ALIGN_CENTER = 4;
/** alignment when inside a table */
public $alignment;
/** colspan if inside a table */
public $colspan;
/** rowspan if inside a table */
public $rowspan;
/** CSS classes */
protected $cssClasses = [];
/** table cell CSS classes */
protected $tableCellCssClasses = [];
/** data attributes */
private $dataAttributes = [];
/** accessibility label */
private ?string $accessibilityLabel = null;
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
abstract function generateHTML($module, $input, $values, $restricted, $scope);
/**
* Returns the HTML attributes for the alignment.
*
* @return String alignment HTML attributes (e.g. align="right" valign="top")
*/
public function getAlignmentString() {
$align = '';
if ($this->alignment !== null) {
switch ($this->alignment) {
case htmlElement::ALIGN_BOTTOM:
$align = 'valign="bottom"';
break;
case htmlElement::ALIGN_TOP:
$align = 'valign="top"';
break;
case htmlElement::ALIGN_LEFT:
$align = 'align="left"';
break;
case htmlElement::ALIGN_RIGHT:
$align = 'align="right"';
break;
case htmlElement::ALIGN_CENTER:
$align = 'align="center"';
break;
}
}
return $align;
}
/**
* Returns the HTML attribute for the colspan.
*
* @return String colspan HTML attribute (e.g. colspan=3)
*/
public function getColspanString() {
if ($this->colspan == null) {
return '';
}
else {
return 'colspan="' . $this->colspan . '"';
}
}
/**
* Returns the HTML attribute for the rowspan.
*
* @return String rowspan HTML attribute (e.g. rowspan=3)
*/
public function getRowspanString() {
if ($this->rowspan == null) {
return '';
}
else {
return 'rowspan="' . $this->rowspan . '"';
}
}
/**
* Returns the CSS classes of this element.
*
* @return array $classes CSS class names
*/
public function getCSSClasses() {
return $this->cssClasses;
}
/**
* Adds CSS classes to this element.
*
* @param array $classes CSS class names
*/
public function setCSSClasses($classes) {
$this->cssClasses = $classes;
}
/**
* Adds CSS classes to the surrounding table cell for this element.
*
* @param array $classes CSS class names
*/
public function setTableCellCSSClasses($classes) {
$this->tableCellCssClasses = $classes;
}
/**
* Returns the CSS classes of the surrounding table cell for this element.
*
* @return array CSS classes
*/
public function getTableCellCSSClasses() {
return $this->tableCellCssClasses;
}
/**
* Adds a data attribute.
*
* @param string $key attribute name (without "data-")
* @param string $value attribute value
*/
public function addDataAttribute($key, $value) {
$this->dataAttributes[$key] = $value;
}
/**
* Returns the data attributes as rendered string.
*
* @return string data attributes
*/
protected function getDataAttributesAsString() {
$result = '';
foreach ($this->dataAttributes as $key => $value) {
$result .= ' data-' . htmlspecialchars($key) . '="' . htmlspecialchars($value) . '"';
}
return $result;
}
/**
* Sets the accessibility label.
*
* @param string|null $accessibilityLabel label
*/
public function setAccessibilityLabel(?string $accessibilityLabel): void {
$this->accessibilityLabel = $accessibilityLabel;
}
/**
* Returns the markup for the accessibility data.
*
* @return string markup to be included in HTML tag (starting with space)
*/
public function getAccessibilityMarkup(): string {
if (empty($this->accessibilityLabel)) {
return '';
}
return ' aria-label="' . htmlspecialchars($this->accessibilityLabel) . '"';
}
}
/**
* Structures elements using a table.
*
* @package metaHTML
*/
class htmlTable extends htmlElement {
/** table footer */
private const FOOTER = "</table>\n";
/** new line */
private const NEWLINE = "</tr><tr>\n";
/** list of subelements */
private $elements = [];
/** specifies if currently a row is open */
private $rowOpen = false;
/** table width */
private $width;
/** HTML ID */
private $id;
/**
* Constructor
*
* @param String $width table width (e.g. 100%)
* @see htmlElement
*/
function __construct($width = null, $id = null) {
$this->width = $width;
$this->id = $id;
}
/**
* Adds an element to the table.
*
* @param htmlElement $element htmlElement object or a simple string
* @param bool $newLine adds a new line after the element (optional, default false)
* @param bool $isTableHeadElement specifies if this is a head or body element (default: body)
*/
public function addElement(htmlElement $element, bool $newLine = false, bool $isTableHeadElement = false): void {
// check if a row needs to be opened
if (!$this->rowOpen) {
$this->elements[] = "<tr>\n";
$this->rowOpen = true;
}
// check if alignment option was given
$align = $element->getAlignmentString();
$colspan = $element->getColspanString();
$rowspan = $element->getRowspanString();
$css = '';
if (sizeof($element->getTableCellCSSClasses()) > 0) {
$css = 'class="' . implode(' ', $element->getTableCellCSSClasses()) . '"';
}
$tagName = 'td';
if ($isTableHeadElement) {
$tagName = 'th';
}
$this->elements[] = "<$tagName $align $colspan $rowspan $css>\n";
$this->elements[] = $element;
$this->elements[] = "</$tagName>\n";
if ($newLine) {
$this->addNewLine();
}
}
/**
* Adds another line to the table.
*/
public function addNewLine() {
if (!$this->rowOpen) {
$this->elements[] = "<tr>\n";
}
else {
$this->elements[] = self::NEWLINE;
}
}
/**
* Adds an htmlSpacer with the given width.
*
* @param String $width width (e.g. 10px)
*/
public function addSpace($width) {
$this->addElement(new htmlSpacer($width, null));
}
/**
* Adds an htmlSpacer with the given height and ends the row.
*
* @param String $height height (e.g. 10px)
*/
public function addVerticalSpace($height) {
$this->addElement(new htmlSpacer(null, $height), true);
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
public function generateHTML($module, $input, $values, $restricted, $scope) {
$return = [];
$width = '';
if ($this->width != null) {
$width = ' width="' . htmlspecialchars($this->width) . '"';
}
$id = '';
if (!empty($this->id)) {
$id = ' id="' . $this->id . '"';
}
$classAttr = '';
if (sizeof($this->cssClasses) > 0) {
$classAttr = ' class="' . implode(' ', $this->cssClasses) . '"';
}
echo "<table" . $width . $id . $classAttr . ">\n";
// print all contained elements
for ($i = 0; $i < sizeof($this->elements); $i++) {
// print htmlElement objects
if ($this->elements[$i] instanceof htmlElement) {
$fields = $this->elements[$i]->generateHTML($module, $input, $values, $restricted, $scope);
$return = array_merge($return, $fields);
}
// print simple Strings
else {
if ($i != (sizeof($this->elements) - 1) || !($this->elements[$i] == self::NEWLINE)) {
echo $this->elements[$i];
}
}
}
if ($this->rowOpen) {
echo "</tr>\n";
}
echo self::FOOTER;
return $return;
}
/**
* Merges the content of another htmlTable object into this table.
*
* @param htmlTable $table table to get elements
*/
public function mergeTableElements(htmlTable $table) {
// remove obsolete new lines at the end
if ($table->elements[sizeof($table->elements) - 1] == self::NEWLINE) {
unset($table->elements[sizeof($table->elements) - 1]);
}
// close last row of other table if needed
if ($table->rowOpen) {
$table->elements[] = "</tr>\n";
}
// close last own row if needed
if ($this->rowOpen) {
if ($this->elements[sizeof($this->elements) - 1] == self::NEWLINE) {
unset($this->elements[sizeof($this->elements) - 1]);
}
else {
$this->elements[] = "</tr>\n";
}
$this->rowOpen = false;
}
$this->elements = array_merge($this->elements, $table->elements);
}
}
/**
* Table component for client-side controlled data tables.
*/
class htmlDataTable extends htmlElement {
public const DATA_AJAX_URL = 'ajaxurl';
public const DATA_TOKEN_NAME = 'tokenname';
public const DATA_TOKEN_VALUE = 'tokenvalue';
public const DATA_ACTION = 'action';
public const DATA_OK_TEXT = 'oktext';
private string $id;
private int $height;
private array $columns;
/**
* Constructor
*
* @param string $id table ID
* @param htmlDataTableColumn[] $columns columns
* @param int $height table height
*/
public function __construct(string $id, array $columns, int $height = 300) {
$this->id = htmlspecialchars($id);
$this->height = $height;
$this->columns = $columns;
}
/**
* @inheritDoc
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
echo '<link href="../../style/tabulator/tabulator.css" rel="stylesheet">';
echo '<script type="text/javascript" src="../../templates/lib/extra/tabulator/tabulator.js.js"></script>';
echo '<div id="' . $this->id . '" class="lam-data-table" ' . $this->getDataAttributesAsString() . '></div>';
$columnOptions = [];
foreach ($this->columns as $column) {
$headerFilter = $column->filterable ? ', headerFilter: "input"' : '';
$columnOptions[] = '{
title: "' . $column->label . '",
field: "' . $column->name . '",
headerTooltip: "' . $column->label . '",
formatter: "textarea"
' . $headerFilter . '
}';
}
$columnsCode = implode(', ', $columnOptions);
echo '<script type="text/javascript">
window.lam.datatable.init("' . $this->id . '", new Tabulator("#' . $this->id . '", {
height: ' . $this->height . ',
layout: "fitColumns",
pagination:"local",
paginationSize:50,
paginationSizeSelector:[50, 100, 250, 500],
columns: [' . $columnsCode . '],
data: [],
locale: "en-gb",
langs: {
"en-gb": {
"pagination": {
"page_size": "",
"page_title": "",
"first": "↤",
"first_title": "",
"last": "↦",
"last_title": "",
"prev": "←",
"prev_title": "",
"next": "→",
"next_title": ""
}
}
}
}));
</script>';
return [];
}
}
/**
* Column for data table.
*/
class htmlDataTableColumn {
public string $label;
public string $name;
public bool $filterable;
/**
* @param string $label column label text
* @param string $name column ID
* @param bool $filterable can be filtered
*/
public function __construct(string $label, string $name, bool $filterable = true) {
$this->label = htmlspecialchars($label);
$this->name = htmlspecialchars($name);
$this->filterable = $filterable;
}
}
/**
* A standard input field.
*
* @package metaHTML
*/
class htmlInputField extends htmlElement {
/** unique field name */
protected $fieldName;
/** field value */
protected $fieldValue = '';
/** field size (default 30) */
protected $fieldSize = 30;
/** field max length (default 1000) */
protected $fieldMaxLength = 1000;
/** on keypress event */
protected $onKeyPress;
/** on keyupp event */
protected $onKeyUp;
/** oninput event */
protected $onInput;
/** password field */
protected $isPassword = false;
/** check password strength */
protected $checkPasswordStrength = false;
/** disables browser autofilling of password fields */
protected $disableAutoFill = false;
/** enabled or disabled */
protected $isEnabled = true;
/** indicates that the value should be saved in obfuscated form */
protected $obfuscate = false;
/** indicates that this field should not automatically be saved in the self service or server profile */
protected $transient = false;
/** required field */
protected $required = false;
/** enable autocomplete */
protected $autocomplete = false;
/** autocompletion suggestions */
protected $autocompleteValues = [];
/** show calendar */
protected $showCalendar = false;
/** show DN selection */
protected $showDnSelection = false;
/** calendar format */
protected $calendarFormat = '';
/** calendar with time */
protected $calendarFormatWithTime = false;
/** calendar with seconds */
protected $calendarFormatWithSeconds = false;
/** title attribute */
protected $title;
/** field ID that needs to have same value (e.g. password field) */
protected $sameValueFieldID;
/** marks the input field as auto trimmed (remove spaces at start/end) */
protected $autoTrim = true;
/** minimum value */
protected $minValue;
/** maximum value */
protected $maxValue;
/** step for numeric values */
protected $stepValue;
/** id */
protected $id;
/** input type */
protected $type = 'text';
/** validation pattern */
protected $validationPattern;
/**
* Constructor
*
* @param String $fieldName unique field name
* @param String $fieldValue value of input field (optional)
* @param String $fieldSize input field length (default 30)
*/
function __construct($fieldName, $fieldValue = null, $fieldSize = null) {
if (isObfuscatedText($fieldValue)) {
$fieldValue = deobfuscateText($fieldValue);
}
$this->fieldName = htmlspecialchars($fieldName);
if ($fieldValue !== null) {
$this->fieldValue = htmlspecialchars($fieldValue);
}
if ($fieldSize !== null) {
$this->fieldSize = $fieldSize;
}
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
if ($this->isAutoTrim()) {
$this->cssClasses[] = 'lam-autotrim';
}
if (isset($values[$this->fieldName])) {
if (isObfuscatedText($values[$this->fieldName][0])) {
$this->fieldValue = htmlspecialchars(deobfuscateText($values[$this->fieldName][0]));
}
else {
$this->fieldValue = htmlspecialchars($values[$this->fieldName][0]);
}
}
$min = '';
if ($this->minValue !== null) {
$min = ' min="' . $this->minValue . '"';
}
$max = '';
if ($this->maxValue !== null) {
$max = ' max="' . $this->maxValue . '"';
}
$step = '';
if ($this->stepValue !== null) {
$step = ' step="' . $this->stepValue . '"';
}
$validationPattern = '';
if ($this->validationPattern !== null) {
$validationPattern = ' pattern="' . $this->validationPattern . '"';
}
// print input field
$required = '';
if ($this->required) {
$required = ' required';
}
$class = ' class="' . implode(' ', $this->cssClasses) . '"';
$name = ' name="' . $this->fieldName . '"';
$idValue = $this->id ?? $this->fieldName;
$id = ' id="' . $idValue . '"';
$value = '';
if ($this->fieldValue != null) {
$value = ' value="' . $this->fieldValue . '"';
}
$maxLength = '';
if ($this->fieldMaxLength != null) {
$maxLength = ' maxlength="' . $this->fieldMaxLength . '"';
}
$size = '';
if ($this->fieldSize != null) {
$size = ' size="' . $this->fieldSize . '"';
}
$inputType = $this->type;
if ($this->isPassword) {
$inputType = 'password';
}
elseif (($this->minValue !== null) || ($this->maxValue !== null)) {
$inputType = 'number';
}
$disabled = '';
if (!$this->isEnabled) {
$disabled = ' disabled';
}
$onKeyPress = '';
if ($this->onKeyPress != null) {
$onKeyPress = ' onkeypress="' . $this->onKeyPress . '"';
}
$onKeyUp = '';
if ($this->onKeyUp != null) {
$onKeyUp = ' onkeyup="' . $this->onKeyUp . '"';
}
$onInput = '';
if ($this->onInput != null) {
$onInput = ' oninput="' . $this->onInput . '"';
}
$title = '';
if (!empty($this->title)) {
$title = ' title="' . $this->title . '"';
}
$autoCompleteVal = '';
if ($this->disableAutoFill) {
$autoCompleteVal = ' autocomplete="new-password"';
}
$autoCompleteData = '';
if ($this->autocomplete && !empty($idValue)) {
if (($this->fieldValue !== null) && !in_array($this->fieldValue, $this->autocompleteValues)) {
array_unshift($this->autocompleteValues, $this->fieldValue);
}
echo '<datalist id="datalist_' . $idValue . '" autocomplete="off">';
foreach ($this->autocompleteValues as $autocompleteValue) {
echo '<option value="' . $autocompleteValue . '">';
}
echo '</datalist>';
$autoCompleteData = ' list="datalist_' . $idValue . '"';
}
if ($this->showDnSelection) {
echo '<span class="nowrap">';
}
echo '<input type="' . $inputType . '"' . $class . $name . $id . $value . $maxLength . $required
. $min . $max . $step . $validationPattern . $size . $onKeyPress . $onKeyUp
. $onInput . $title . $disabled . $this->getAccessibilityMarkup()
. $this->getDataAttributesAsString() . $autoCompleteVal . $autoCompleteData . '>';
if ($this->showDnSelection) {
echo '<img class="align-middle" src="../../graphics/search-color.svg"
width="16" height="16" title="' . _('Choose entry') . '"
onclick="window.lam.html.showDnSelection(\'' . $this->fieldName . '\', \'' . _('Choose entry') . '\'
, \'' . _('Ok') . '\', \'' . _('Cancel') . '\', \'' . getSecurityTokenName() . '\'
, \'' . getSecurityTokenValue() . '\');">';
echo '</span>';
}
// calendar
if ($this->showCalendar) {
$locale = 'en';
if (!empty($_SESSION['language'])) {
$sessionLanguage = $_SESSION['language'];
$sessionLanguage = str_replace('.utf8', '', $sessionLanguage);
if ($sessionLanguage === 'zh_TW') {
$locale = 'zh_tw';
}
else {
$sessionLanguageParts = explode('_', $sessionLanguage);
$locale = $sessionLanguageParts[0];
}
}
$calendarWithTime = $this->calendarFormatWithTime ? "enableTime: true, " : "";
$calendarWithSeconds = $this->calendarFormatWithSeconds ? "enableSeconds: true, " : "";
echo '<script type="text/javascript">
flatpickr("#' . $this->fieldName . '", {
dateFormat: "' . $this->calendarFormat . '",
hourIncrement: 1,
minuteIncrement: 1,
time_24hr: true,
' . $calendarWithTime . $calendarWithSeconds . '
locale: "' . $locale . '"
});
</script>
';
}
// check value against reference field
if ($this->sameValueFieldID != null) {
echo '<script type="text/javascript">
checkFieldsHaveSameValues("' . $this->fieldName . '", "' . $this->sameValueFieldID . '");
</script>
';
}
if ($this->checkPasswordStrength) {
$query = '?admin=1';
if (isSelfService()) {
$query = '?selfservice=1';
}
$ajaxPath = "../templates/misc/ajax.php";
if (is_file("../../templates/misc/ajax.php")) {
$ajaxPath = "../../templates/misc/ajax.php";
}
elseif (is_file("../../../templates/misc/ajax.php")) {
$ajaxPath = "../../../templates/misc/ajax.php";
}
$ajaxPath .= $query;
echo '<script type="text/javascript">
checkPasswordStrength("' . $this->fieldName . '", "' . $ajaxPath . '", "' . getSecurityTokenName() . '", "' . getSecurityTokenValue() . '");
</script>
';
}
if ($this->transient) {
return [];
}
if ($this->obfuscate) {
return [$this->fieldName => 'text_obfuscated'];
}
else {
return [$this->fieldName => 'text'];
}
}
/**
* Sets the maximum field length.
*
* @param int $fieldMaxLength length
*/
public function setFieldMaxLength($fieldMaxLength) {
$this->fieldMaxLength = $fieldMaxLength;
}
/**
* Sets the field size (default is 30).
*
* @param int $fieldSize size
*/
public function setFieldSize($fieldSize) {
$this->fieldSize = $fieldSize;
}
/**
* Specifies if this is a password field.
*
* @param boolean $isPassword password field
* @param boolean $checkStrength check if matches password policy (default: false)
* @param boolean $disableAutoFill prevent autofilling by browser
*/
public function setIsPassword($isPassword, $checkStrength = false, $disableAutoFill = false) {
$this->isPassword = $isPassword;
$this->checkPasswordStrength = $checkStrength;
$this->disableAutoFill = $disableAutoFill;
}
/**
* Specifies if this component is enabled and accepts user modification.
*
* @param boolean $isEnabled enabled if true
*/
public function setIsEnabled($isEnabled) {
$this->isEnabled = $isEnabled;
}
/**
* Specifies if the value should be saved in obfuscated form (e.g. self service profile).
*
* @param boolean $obfuscate obfuscate value
*/
public function setObfuscate($obfuscate) {
$this->obfuscate = $obfuscate;
}
/**
* Specifies that the value should not be automatically saved when used in self service or server profile (default: false).
*
* @param boolean $transient transient field
*/
public function setTransient($transient) {
$this->transient = $transient;
}
/**
* Specifies if the input field is required.
*
* @param boolean $required required
*/
public function setRequired($required) {
$this->required = $required;
}
/**
* Sets the field as number field with minimum and maximum values.
*
* @param integer $minimum minimum
* @param integer $maximum maximum
* @param int $step step value
*/
public function setMinimumAndMaximumNumber($minimum = 0, $maximum = null, int $step = 1) {
$this->minValue = $minimum;
$this->maxValue = $maximum;
$this->stepValue = $step;
}
/**
* Enables autocompletion for this input field.
*
* @param array $values list of values to suggest
*/
public function enableAutocompletion($values) {
$this->autocomplete = true;
$this->autocompleteValues = $values;
}
/**
* Sets the JavaScript for the onKeyPress event.
*
* @param String $onKeyPress JavaScript code
*/
public function setOnKeyPress($onKeyPress) {
$this->onKeyPress = $onKeyPress;
}
/**
* Sets the JavaScript for the onKeyUp event.
*
* @param String $onKeyUp JavaScript code
*/
public function setOnKeyUp($onKeyUp) {
$this->onKeyUp = $onKeyUp;
}
/**
* Sets the JavaScript for the onInput event.
*
* @param string $onInput JavaScript code
*/
public function setOnInput(string $onInput): void {
$this->onInput = $onInput;
}
/**
* Shows a calendar when the field is selected.
*
* @param String $format calendar format (e.g. "Y-m-d" or "Y-m-d H:i:S")
* @param bool $withTime activate time selection (default: false)
* @param bool $withSeconds show seconds (default: false)
*/
public function showCalendar($format, $withTime = false, $withSeconds = false) {
$this->showCalendar = true;
$this->calendarFormatWithTime = $withTime;
$this->calendarFormatWithSeconds = $withSeconds;
$format = str_replace('yy', 'Y', $format);
$format = str_replace('dd', 'd', $format);
$format = str_replace('mm', 'm', $format);
$this->calendarFormat = str_replace('\\', '\\\\', $format);
}
/**
* Shows a DN selection next to input field.
*/
public function showDnSelection() {
$this->showDnSelection = true;
}
/**
* Sets the title for the input field.
*
* @param String $title title value
*/
public function setTitle($title) {
$this->title = htmlspecialchars($title);
}
/**
* Specifies the ID of a second field that must have the same value as this field.
* This field is marked red if different or green if equal.
*
* @param String $sameValueFieldID ID of reference field
*/
public function setSameValueFieldID($sameValueFieldID) {
$this->sameValueFieldID = $sameValueFieldID;
}
/**
* Turns this field into a live filter for a select box.
* Cannot be used together with setOnKeyUp().
*
* @param String $name select box name
*/
public function filterSelectBox($name) {
$this->setOnKeyUp('window.lam.filterSelect.activate(\'' . $this->fieldName . '\', \'' . $name . '\', event);');
}
/**
* Returns if the field content should be auto-trimmed (remove spaces at start/end).
*
* @return boolean auto-trim input
*/
protected function isAutoTrim() {
return $this->autoTrim && !$this->isPassword;
}
public function disableAutoTrim() {
$this->autoTrim = false;
}
/**
* Sets the element ID.
*
* @param string $id id
*/
public function setId(string $id) {
$this->id = $id;
}
/**
* Sets the input type.
*
* @param string $type type (e.g. number)
*/
public function setType(string $type): void {
$this->type = $type;
}
/**
* Sets the validation pattern.
*
* @param string $pattern pattern (e.g. "[0-9]{3}")
*/
public function setValidationPattern(string $pattern): void {
$this->validationPattern = $pattern;
}
/**
* Sets the step value for number fields.
*
* @param int $step step value (e.g. 1)
*/
public function setStepValue(int $step): void {
$this->stepValue = $step;
}
}
/**
* Renders a help link.
*
* @package metaHTML
*/
class htmlHelpLink extends htmlElement {
/** help ID */
private $helpID;
/** module name if it should be forced */
private $module;
/** account type if it should be forced */
private $scope;
/**
* Constructor
*
* @param String $helpID help ID
* @param String $module module name (optional, only if value from generateHTML() should be overwritten)
* @param String $scope account type (e.g. user) (optional, only if value from generateHTML() should be overwritten)
*/
function __construct($helpID, $module = null, $scope = null) {
$this->helpID = $helpID;
$this->module = $module;
$this->scope = $scope;
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
// overwrite module and scope if needed
if ($this->module != null) {
$module = $this->module;
}
if ($this->scope != null) {
$scope = $this->scope;
}
// print link
$helpEntry = getHelp($module, $this->helpID, $scope);
if (empty($helpEntry)) {
return [];
}
printHelpLink($helpEntry, $this->helpID, $module, $scope, $this->cssClasses);
return [];
}
}
/**
* Simple button.
*
* @package metaHTML
*/
class htmlButton extends htmlElement {
/** button name */
protected $name;
/** button text or image */
protected $value;
/** image button or text button */
protected $isImageButton;
/** title */
private $title;
/** enabled or disabled */
private $isEnabled = true;
/** onclick event */
private $onClick;
/** button type (default: "submit" if no onClick and "button" with onClick) */
private $type;
/** disable form validation */
private $noFormValidation = false;
/**
* Constructor.
*
* @param String $name button name
* @param String $value button text or image (16x16px, relative to graphics folder)
* @param String $isImageButton image or text button (default text)
*/
function __construct($name, $value, $isImageButton = false) {
$this->name = htmlspecialchars($name);
$this->value = htmlspecialchars($value);
$this->isImageButton = $isImageButton;
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
if ($restricted) {
// no buttons in restricted mode
logNewMessage(LOG_ERR, 'Meta HTML: Requested button in restricted mode.');
return [];
}
$style = '';
$classList = $this->cssClasses;
$class = '';
$title = '';
$name = ' name="' . $this->name . '"';
// image button
if ($this->isImageButton) {
$classList[] = 'smallImageButton';
$classList[] = 'align-middle';
$style = ' style="background-image: url(../../graphics/' . $this->value . ');"';
}
// button with text and icon
else {
$classList[] = 'margin5';
}
$class = ' class="' . implode(' ', $classList) . '"';
if ($this->title != null) {
$title = ' title="' . $this->title . '"';
}
$disabled = '';
if (!$this->isEnabled) {
$disabled = ' disabled';
}
$noFormValidation = '';
if ($this->noFormValidation) {
$noFormValidation = ' formnovalidate="formnovalidate"';
}
if ($this->type == null) {
$type = ' type="submit"';
}
else {
$type = ' type="' . $this->type . '"';
}
$onClick = '';
if ($this->onClick != null) {
if ($this->type == null) {
$type = ' type="button"';
}
$onClick = ' onclick="' . $this->onClick . '"';
}
$id = ' id="btn_' . preg_replace('/[^a-zA-Z0-9_-]/', '', $this->name) . '"';
if ($this->isImageButton) {
echo '<input type="submit" ' . $id . ' value=" "' . $name . $onClick . $style . $class
. $title . $disabled . $noFormValidation . $this->getDataAttributesAsString() . '>';
}
else {
echo '<button' . $id . $name . $type . $onClick . $style . $class . $title . $disabled
. $noFormValidation . $this->getDataAttributesAsString() . '>' . $this->value . '</button>';
}
return [$this->name => 'submit'];
}
/**
* Sets the button title (tooltip).
*
* @param String $title title
*/
public function setTitle($title) {
if ($title !== null) {
$this->title = htmlspecialchars($title);
}
}
/**
* Specifies if this component is enabled and accepts user modification.
*
* @param boolean $isEnabled enabled if true
*/
public function setIsEnabled($isEnabled) {
$this->isEnabled = $isEnabled;
}
/**
* Sets the onclick event code.
* This makes this button a simple button that does not submit a form.
*
* @param String $onClick JS code
*/
public function setOnClick($onClick) {
$this->onClick = $onClick;
}
/**
* Allows to override the default button type ("submit" if no onClick and "button" with onClick).
*/
public function setType($type) {
$this->type = $type;
}
/**
* Disables form validation (e.g. for cancel buttons).
*/
public function disableFormValidation(): void {
$this->noFormValidation = true;
}
}
/**
* Prints a button for the account pages.
*
* @package metaHTML
*/
class htmlAccountPageButton extends htmlButton {
/**
* Constructor
*
* @param string $targetModule module name which renders next page
* @param string $targetPage name of next page
* @param string $identifier identifier for button
* @param string $value button text or image (16x16px, relative to graphics folder)
* @param bool $isImageButton image or text button (default text)
* @param string|null $title title to show
*/
public function __construct(string $targetModule, string $targetPage, string $identifier, string $value, bool $isImageButton = false, ?string $title = null) {
parent::__construct('form_subpage_' . $targetModule . '_' . $targetPage . '_' . $identifier, $value, $isImageButton);
if ($title !== null) {
$this->setTitle($title);
}
}
}
/**
* Represents a select box.
*
* @package metaHTML
*/
class htmlSelect extends htmlElement {
/** name of select field */
protected $name;
/** size */
private $size;
/** allows multi-selection */
private $multiSelect = false;
/** elements */
private $elements;
/** selected elements */
private $selectedElements = [];
/** descriptive elements */
private $hasDescriptiveElements = false;
/** contains optgroups */
private $containsOptgroups = false;
/** sorting enabled */
private $sortElements = true;
/** right to left text direction */
private $rightToLeftTextDirection = false;
/** enabled or disabled */
private $isEnabled = true;
/** width of input element */
private $width = '';
/** transform select boxes with one element to text */
private $transformSingleSelect = true;
/** onchange event */
private $onchangeEvent;
/** indicates that this field should not automatically be saved in the self service or server profile */
private $transient = false;
/** list of enclosing table rows to hide when checked */
protected $tableRowsToHide = [];
/** list of enclosing table rows to show when checked */
protected $tableRowsToShow = [];
/** dynamic scrolling */
private $dynamicScrolling = false;
/** CSS classes for values */
private $optionCssClasses = [];
/**
* Constructor.
*
* <br>Examples:
* <br>
* <br>$select = new htmlSelect('myName', array('value1', 'value2'), array('value1'));
* <br>
* <br>$select = new htmlSelect('myName', array('label1' => 'value1', 'label2' => 'value2'), array('value1'));
* <br>$select->setHasDescriptiveElements(true);
* <br>
* <br>$select = new htmlSelect('myName', array('optgroupLabel' => array('value1', 'value2')), array('value1'));
* <br>$select->setHasDescriptiveElements(true);
* <br>$select->setContainsOptgroups(true);
*
* @param String $name element name
* @param array $elements list of elements array(label => value) or array(value1, value2) or array('optgroup' => array(...))
* @param array $selectedElements list of selected elements (optional, default none)
* @param int $size size (optional, default = 1)
*/
function __construct($name, $elements, $selectedElements = [], $size = 1) {
$this->name = htmlspecialchars($name);
$this->elements = $elements;
if ($selectedElements != null) {
$this->selectedElements = $selectedElements;
}
$this->size = htmlspecialchars($size);
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
if (isset($values[$this->name])) {
$this->selectedElements = $values[$this->name];
}
$multi = '';
$name = ' name="' . $this->name . '" id="' . $this->name . '"';
if ($this->multiSelect) {
$multi = ' multiple';
$name = ' name="' . $this->name . '[]" id="' . $this->name . '"';
}
$size = ' size="' . $this->size . '"';
$class = '';
$classList = $this->cssClasses;
if ($this->rightToLeftTextDirection) {
$classList[] = 'rightToLeftText';
}
$class = ' class="' . implode(' ', $classList) . '"';
$disabled = '';
if (!$this->isEnabled) {
$disabled = ' disabled';
}
$style = '';
if ($this->width != '') {
$style = ' style="width: ' . $this->width . '"';
}
$onchange = '';
if ($this->onchangeEvent != null) {
$onchange = $this->onchangeEvent;
}
if (($this->tableRowsToHide != null) || ($this->tableRowsToShow != null)) {
$this->printCodeForShowHideTableRows($onchange);
}
if ($onchange != '') {
$onchange = ' onchange="' . $onchange . '"';
}
// hide select boxes that contain less than 2 elements
if ((sizeof($this->elements) < 2) && !$this->multiSelect && !$this->containsOptgroups && $this->transformSingleSelect) {
echo '<div class="hidden">';
}
// print select box
echo '<select' . $this->getDataAttributesAsString() . $this->getAccessibilityMarkup() . $class . $style
. $name . $size . $multi . $disabled . $onchange . ">\n";
if ($this->containsOptgroups) {
foreach ($this->elements as $label => $elements) {
if (sizeof($elements) > 0) {
echo '<optgroup label="' . $label . '">';
$this->printOptionsHTML($elements);
echo '</optgroup>';
}
}
}
else {
$this->printOptionsHTML($this->elements);
}
echo "</select>\n";
// if select box has only one element then show it as text
if ((sizeof($this->elements) < 2) && !$this->multiSelect && !$this->containsOptgroups && $this->transformSingleSelect) {
echo '</div>';
if (sizeof($this->elements) == 1) {
echo ' ';
if ($this->hasDescriptiveElements) {
$keys = array_keys($this->elements);
echo $keys[0];
}
else {
echo $this->elements[0];
}
}
}
if ($this->transient) {
return [];
}
if ($this->multiSelect) {
return [$this->name => 'multiselect'];
}
else {
return [$this->name => 'select'];
}
}
/**
* Prints the HTML code of the option tags.
*
* @param array $elements list of options
*/
private function printOptionsHTML($elements) {
if ($this->dynamicScrolling) {
echo "<option value=\"#\">#</option>\n";
return;
}
// sorting
if ($this->sortElements) {
if ($this->hasDescriptiveElements) {
$labels = array_keys($elements);
natcasesort($labels);
$newElements = [];
foreach ($labels as $label) {
$newElements[$label] = $elements[$label];
}
$elements = $newElements;
}
else {
natcasesort($elements);
}
}
foreach ($elements as $key => $value) {
$selected = '';
$optionClass = '';
if (isset($this->optionCssClasses[$value])) {
$optionClass = 'class="' . $this->optionCssClasses[$value] . '"';
}
if (in_array($value, $this->selectedElements) || (empty($this->selectedElements) && empty($value))) {
$selected = ' selected';
}
if ($this->hasDescriptiveElements) {
echo "<option value=\"" . htmlspecialchars($value) . "\"$selected $optionClass>" . htmlspecialchars($key) . "</option>\n";
}
else {
echo "<option$selected $optionClass>" . htmlspecialchars($value) . "</option>\n";
}
}
}
/**
* Specifies if the elements are just a simple list or an associative array (default: simple list).
*
* @param boolean $hasDescriptiveElements activates descriptive elements
*/
public function setHasDescriptiveElements($hasDescriptiveElements) {
$this->hasDescriptiveElements = $hasDescriptiveElements;
}
/**
* Specifies if the elements are divided into optgroups.
* In this case the provided options are an array where the key is the optgroup label and the value is an array containing the options for the optgroup.
*
* @param boolean $containsOptgroups activates optgroups
*/
public function setContainsOptgroups($containsOptgroups) {
$this->containsOptgroups = $containsOptgroups;
}
/**
* Specifies if multi-selection is enabled (default: disabled).
*
* @param boolean $multiSelect allows multi-selection
*/
public function setMultiSelect($multiSelect) {
$this->multiSelect = $multiSelect;
}
/**
* Specifies if the elements should be sorted (default: sort).
*
* @param boolean $sortElements sort elements
*/
public function setSortElements($sortElements) {
$this->sortElements = $sortElements;
}
/**
* Specifies if the text direction should be set to right to left.
*
* @param boolean $rightToLeftTextDirection if true use right to left direction
*/
public function setRightToLeftTextDirection($rightToLeftTextDirection) {
$this->rightToLeftTextDirection = $rightToLeftTextDirection;
}
/**
* Specifies if this component is enabled and accepts user modification.
*
* @param boolean $isEnabled enabled if true
*/
public function setIsEnabled($isEnabled) {
$this->isEnabled = $isEnabled;
}
/**
* Specifies the width of this selection box.
*
* @param String $width width (e.g. 20em)
*/
public function setWidth($width) {
$this->width = htmlspecialchars($width);
}
/**
* Specifies if select boxes that contain only a single element should be transformed to a simple text field.
*
* @param boolean $transformSingleSelect transform single options to text
*/
public function setTransformSingleSelect($transformSingleSelect) {
$this->transformSingleSelect = $transformSingleSelect;
}
/**
* Sets the JavaScript code for the onchange event.
*
* @param String $onchangeEvent onchange event code (e.g. myfunction();)
*/
public function setOnchangeEvent($onchangeEvent) {
$this->onchangeEvent = htmlspecialchars($onchangeEvent);
}
/**
* Specifies that the value should not be automatically saved when used in self service or server profile (default: false).
*
* @param boolean $transient transient field
*/
public function setTransient($transient) {
$this->transient = $transient;
}
/**
* This will hide the given table rows when the select is changed to the specified value.
* The given IDs can be of any e.g. input element. Starting from this element
* the first parent "<tr>" element will be used to show/hide.
* <br>
* <br>
* <br>Example: <tr><td><input type="checkbox" id="mycheckbox"></td></tr>
* <br> Using "mycheckbox" will use this "tr" to hide/show.
* <br>
* <br> Example for $tableRowsToHide:
* <br> array('yes' => array('option1', 'option2'), 'no' => array('option3'))
*
* @param array $tableRowsToHide array of select value => array of IDs of child elements to hide
*/
public function setTableRowsToHide($tableRowsToHide) {
$this->tableRowsToHide = $tableRowsToHide;
}
/**
* This will show the given table rows when the select is changed to the specified value.
* The given IDs can be of any e.g. input element. Starting from this element
* the first parent "<tr>" element will be used to show/hide.
* <br>
* <br>
* <br>Example: <tr><td><input type="checkbox" id="mycheckbox"></td></tr>
* <br> Using "mycheckbox" will use this "tr" to hide/show.
* <br>
* <br> Example for $tableRowsToShow:
* <br> array('yes' => array('option1', 'option2'), 'no' => array('option3'))
*
* @param array $tableRowsToShow array of select value => array of IDs of child elements to show
*/
public function setTableRowsToShow($tableRowsToShow) {
$this->tableRowsToShow = $tableRowsToShow;
}
/**
* Creates the JavaScript code to hide/show table rows based on the select value.
*
* @param String $onChange onChange code
*/
private function printCodeForShowHideTableRows(&$onChange) {
if ((sizeof($this->tableRowsToHide) == 0) && (sizeof($this->tableRowsToShow) == 0)) {
return;
}
$values = [];
if (!empty($this->tableRowsToHide)) {
$values = array_merge($values, array_keys($this->tableRowsToHide));
}
if (!empty($this->tableRowsToShow)) {
$values = array_merge($values, array_keys($this->tableRowsToShow));
}
$selector = $this->getShowHideSelector();
// build Java script to show/hide depending fields
foreach ($values as $val) {
// build onChange listener
$onChange .= 'if (document.getElementById(\'' . $this->name . '\').value == \'' . $val . '\') {';
if (isset($this->tableRowsToShow[$val])) {
for ($i = 0; $i < sizeof($this->tableRowsToShow[$val]); $i++) {
$onChange .= 'document.getElementById(\'' . $this->tableRowsToShow[$val][$i] . '\')?.closest(\'' . $selector . '\').classList.remove(\'hidden\');';
}
}
if (isset($this->tableRowsToHide[$val])) {
for ($i = 0; $i < sizeof($this->tableRowsToHide[$val]); $i++) {
$onChange .= 'document.getElementById(\'' . $this->tableRowsToHide[$val][$i] . '\')?.closest(\'' . $selector . '\').classList.add(\'hidden\');';
}
}
$onChange .= '};';
}
// build script to set initial state
$script = '<script type="text/javascript">window.lam.utility.documentReady(function() {' . "\n";
if (isset($this->tableRowsToShow[$this->selectedElements[0]])) {
for ($i = 0; $i < sizeof($this->tableRowsToShow[$this->selectedElements[0]]); $i++) {
$classType = 'remove';
$script .= 'document.getElementById(\'' . $this->tableRowsToShow[$this->selectedElements[0]][$i] . '\')?.closest(\'' . $selector . '\').classList.' . $classType . '(\'hidden\');' . "\n";
}
}
if (isset($this->tableRowsToHide[$this->selectedElements[0]])) {
for ($i = 0; $i < sizeof($this->tableRowsToHide[$this->selectedElements[0]]); $i++) {
$classType = 'add';
$script .= 'document.getElementById(\'' . $this->tableRowsToHide[$this->selectedElements[0]][$i] . '\')?.closest(\'' . $selector . '\').classList.' . $classType . '(\'hidden\');' . "\n";
}
}
$script .= '});</script>';
echo $script;
}
/**
* Returns the selector to use to find the show/hide elements.
*
* @return string selector
*/
protected function getShowHideSelector() {
return 'tr';
}
/**
* Enable dynamic scrolling. This limits the number of select options to 10000 by dynamically adding/removing options.
* This will not be enabled when optgroups are used or the option size is less than 10000.
*/
public function enableDynamicScrolling() {
// not possible for optgroups and smaller option lists
if ((sizeof($this->elements) < 10000) || $this->containsOptgroups) {
return;
}
$this->dynamicScrolling = true;
$elementData = [];
$counter = 0;
foreach ($this->elements as $key => $value) {
$elementData[] = [
'label' => $key,
'value' => $value,
'selected' => in_array($value, $this->selectedElements),
'index' => $counter];
$counter++;
}
$this->addDataAttribute('dynamic-options', json_encode($elementData));
$this->cssClasses[] = 'lam-dynamicOptions';
}
/**
* Sets CSS classes for option values.
*
* @param array $optionCssClasses array('option value' => 'CSS class(es)')
*/
public function setOptionCssClasses(array $optionCssClasses): void {
$this->optionCssClasses = $optionCssClasses;
}
}
/**
* Represents a radio selection.
*
* @package metaHTML
*/
class htmlRadio extends htmlElement {
/** name of select field */
private $name;
/** elements */
private $elements;
/** selected element */
private $selectedElement;
/** enabled or disabled */
private $isEnabled = true;
/** on change code */
private $onchangeEvent;
/** list of enclosing table rows to hide when checked */
protected $tableRowsToHide = [];
/** list of enclosing table rows to show when checked */
protected $tableRowsToShow = [];
/**
* Constructor.
*
* <br>Examples:
* <br>
* <br>$radio = new htmlRadio('myName', array('label1' => 'value1', 'label2' => 'value2'), array('value1'));
*
* @param String $name element name
* @param array $elements list of elements array(label => value)
* @param String $selectedElement value of selected element (optional, default none)
*/
function __construct($name, $elements, $selectedElement = null) {
$this->name = htmlspecialchars($name);
$this->elements = $elements;
if ($selectedElement != null) {
$this->selectedElement = $selectedElement;
}
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
if (isset($values[$this->name][0])) {
$this->selectedElement = $values[$this->name][0];
}
$name = ' name="' . $this->name . '"';
$disabled = '';
if (!$this->isEnabled) {
$disabled = ' disabled';
}
if (($this->tableRowsToHide != null) || ($this->tableRowsToShow != null)) {
$this->printInitialState();
}
// print radio list
$counter = 0;
foreach ($this->elements as $label => $value) {
$showHideOnchange = '';
if (($this->tableRowsToHide != null) || ($this->tableRowsToShow != null)) {
$showHideOnchange = $this->getOnchangeCodeForShowHideTableRows($counter);
}
$onchange = '';
if ($this->onchangeEvent != null) {
$onchange = ' onchange="' . $this->onchangeEvent . '"';
}
elseif (!empty($showHideOnchange)) {
$onchange = ' onchange="' . $showHideOnchange . '"';
}
echo '<div class="nowrap">';
$selected = '';
if ($value == $this->selectedElement) {
$selected = ' checked';
}
echo '<input type="radio" id="' . $this->name . $counter . '"' . $name . $disabled . $selected . $onchange . ' value="' . $value . '"> ';
echo '<label for="' . $this->name . $counter . '">' . $label . '</label>';
echo '</div>';
$counter++;
}
return [$this->name => 'select'];
}
/**
* Specifies if this component is enabled and accepts user modification.
*
* @param boolean $isEnabled enabled if true
*/
public function setIsEnabled($isEnabled) {
$this->isEnabled = $isEnabled;
}
/**
* Sets the JavaScript code for the onchange event.
*
* @param String $onchangeEvent onchange event code (e.g. myfunction();)
*/
public function setOnchangeEvent($onchangeEvent) {
$this->onchangeEvent = htmlspecialchars($onchangeEvent);
}
/**
* Returns the selector to use to find the show/hide elements.
*
* @return string selector
*/
protected function getShowHideSelector() {
return 'tr';
}
/**
* Creates the JavaScript code to hide/show table rows based on the select value.
*
* @param int $counter index
* @return string onChange code
*/
private function getOnchangeCodeForShowHideTableRows($counter): string {
$onChange = '';
if ((sizeof($this->tableRowsToHide) == 0) && (sizeof($this->tableRowsToShow) == 0)) {
return $onChange;
}
$values = [];
if (!empty($this->tableRowsToHide)) {
$values = array_merge($values, array_keys($this->tableRowsToHide));
}
if (!empty($this->tableRowsToShow)) {
$values = array_merge($values, array_keys($this->tableRowsToShow));
}
$values = array_unique($values);
$selector = $this->getShowHideSelector();
// build Java script to show/hide depending fields
foreach ($values as $val) {
// build onChange listener
$onChange .= 'if (document.getElementById(\'' . $this->name . $counter . '\').value == \'' . $val . '\') {';
if (isset($this->tableRowsToShow[$val])) {
for ($i = 0; $i < sizeof($this->tableRowsToShow[$val]); $i++) {
$onChange .= 'document.getElementById(\'' . $this->tableRowsToShow[$val][$i] . '\')?.closest(\'' . $selector . '\').classList.remove(\'hidden\');';
}
}
if (isset($this->tableRowsToHide[$val])) {
for ($i = 0; $i < sizeof($this->tableRowsToHide[$val]); $i++) {
$onChange .= 'document.getElementById(\'' . $this->tableRowsToHide[$val][$i] . '\')?.closest(\'' . $selector . '\').classList.add(\'hidden\');';
}
}
$onChange .= '};';
}
return $onChange;
}
private function printInitialState() {
$selector = $this->getShowHideSelector();
// build script to set initial state
$script = '<script type="text/javascript">window.lam.utility.documentReady(function() {' . "\n";
if (isset($this->tableRowsToShow[$this->selectedElement])) {
for ($i = 0; $i < sizeof($this->tableRowsToShow[$this->selectedElement]); $i++) {
$script .= 'document.getElementById(\'' . $this->tableRowsToShow[$this->selectedElement][$i] . '\')?.closest(\'' . $selector . '\').classList.remove(\'hidden\');' . "\n";
}
}
if (isset($this->tableRowsToHide[$this->selectedElement])) {
for ($i = 0; $i < sizeof($this->tableRowsToHide[$this->selectedElement]); $i++) {
$script .= 'document.getElementById(\'' . $this->tableRowsToHide[$this->selectedElement][$i] . '\')?.closest(\'' . $selector . '\').classList.add(\'hidden\');' . "\n";
}
}
$script .= '});</script>';
echo $script;
}
/**
* This will hide the given table rows when the radio is changed to the specified value.
* The given IDs can be of any e.g. input element. Starting from this element
* the first parent "<tr>" element will be used to show/hide.
* <br>
* <br>
* <br> Example for $tableRowsToHide:
* <br> array('val1' => array('option1', 'option2'), 'val2' => array('option3'))
*
* @param array $tableRowsToHide array of select value => array of IDs of child elements to hide
*/
public function setTableRowsToHide($tableRowsToHide) {
$this->tableRowsToHide = $tableRowsToHide;
}
/**
* This will show the given table rows when the radio is changed to the specified value.
* The given IDs can be of any e.g. input element. Starting from this element
* the first parent "<tr>" element will be used to show/hide.
* <br>
* <br>
* <br> Example for $tableRowsToShow:
* <br> array('val1' => array('option1', 'option2'), 'val2' => array('option3'))
*
* @param array $tableRowsToShow array of select value => array of IDs of child elements to show
*/
public function setTableRowsToShow($tableRowsToShow) {
$this->tableRowsToShow = $tableRowsToShow;
}
}
/**
* Prints the text and escapes contained HTML code by default.
*
* @package metaHTML
*/
class htmlOutputText extends htmlElement {
/** the text to print */
private $string;
/** specifies if HTML code should be escaped */
private $escapeHTML;
/** bold text */
private $isBold = false;
/** mark as required */
private $markAsRequired = false;
/** no wrap */
private $noWrap = false;
/** preformatted */
private $isPreformatted = false;
/** title */
private $title;
/**
* Constructor.
*
* @param String $string output text
* @param boolean $escapeHTML escape HTML code (default yes)
* @param boolean $markAsRequired mark text like a required field
*/
function __construct($string, $escapeHTML = true, $markAsRequired = false) {
$this->string = $string;
$this->escapeHTML = $escapeHTML;
$this->markAsRequired = $markAsRequired;
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
$cssClasses = empty($this->cssClasses) ? '' : 'class="' . implode(' ', $this->cssClasses) . '"';
if (!empty($this->title)) {
echo '<span title="' . $this->title . '">';
}
if ($this->noWrap) {
echo "<div class=\"nowrap\">";
}
if ($this->isBold) {
echo "<b>";
}
if ($this->isPreformatted) {
echo "<pre $cssClasses>";
}
elseif (!empty($cssClasses)) {
echo "<span $cssClasses>";
}
if ($this->escapeHTML) {
echo htmlspecialchars($this->string);
}
else {
echo $this->string;
}
if ($this->markAsRequired) {
echo htmlGetRequiredMarker();
}
if ($this->isPreformatted) {
echo "</pre>";
}
elseif (!empty($cssClasses)) {
echo "</span>";
}
if ($this->isBold) {
echo "</b>";
}
if ($this->noWrap) {
echo "</div>";
}
if (!empty($this->title)) {
echo "</span>";
}
return [];
}
/**
* Specifies if the whole text should be printed in bold.
*
* @param boolean $isBold bold text
*/
public function setIsBold($isBold) {
$this->isBold = $isBold;
}
/**
* Adds a marker that indicates a required field.
*
* @param boolean $markAsRequired add marker
*/
public function setMarkAsRequired($markAsRequired) {
$this->markAsRequired = $markAsRequired;
}
/**
* Specifies if word wrap is allowed for this text.
*
* @param boolean $noWrap no wrapping if set to true (default false)
*/
public function setNoWrap($noWrap) {
$this->noWrap = $noWrap;
}
/**
* Sets if the text is preformatted.
*
* @param boolean $preformatted is preformatted (default true)
*/
public function setPreformatted($preformatted = true) {
$this->isPreformatted = $preformatted;
}
/**
* Sets a title for this text.
*
* @param string|null $title title
*/
public function setTitle(?string $title): void {
$this->title = $title;
}
}
/**
* Prints the HTML code for a checkbox.
*
* @package metaHTML
*/
class htmlInputCheckbox extends htmlElement {
/** unique name of input element */
protected $name;
/** value */
protected $checked;
/** enabled or disabled */
protected $isEnabled = true;
/** list of enclosing table rows to hide when checked */
protected $tableRowsToHide = [];
/** list of enclosing table rows to show when checked */
protected $tableRowsToShow = [];
/** indicates that this field should not automatically be saved in the self service or server profile */
private $transient = false;
/** list of input elements to enable when checked */
protected $elementsToEnable = [];
/** list of input elements to disable when checked */
protected $elementsToDisable = [];
/** onclick event code */
private $onClick;
/** title */
private ?string $title = null;
/**
* Constructor.
*
* @param string $name unique name
* @param bool $checked checked
*/
function __construct(string $name, bool $checked) {
$this->name = htmlspecialchars($name);
$this->checked = $checked;
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
if (isset($values[$this->name])) {
if ($values[$this->name][0] == 'true') {
$this->checked = true;
}
else {
$this->checked = false;
}
}
$checked = '';
if ($this->checked) {
$checked = ' checked';
}
$title = '';
if ($this->title !== null) {
$title = ' title="' . $this->title . '"';
}
$disabled = '';
if (!$this->isEnabled) {
$disabled = ' disabled';
}
$classes = ' ';
if (!empty($this->cssClasses)) {
$classes = ' class="' . implode(' ', $this->cssClasses) . '"';
}
// build Java script to show/hide depending fields
$onChange = '';
$script = '';
$selector = $this->getShowHideSelector();
if ((sizeof($this->tableRowsToShow) > 0) || (sizeof($this->tableRowsToHide) > 0)) {
// build onChange listener
$onChange .= 'if (document.querySelector(\'#' . $this->name . ':checked\') !== null) {';
for ($i = 0; $i < sizeof($this->tableRowsToShow); $i++) {
$onChange .= 'document.getElementById(\'' . $this->tableRowsToShow[$i] . '\')?.closest(\'' . $selector . '\').classList.remove(\'hidden\');';
}
for ($i = 0; $i < sizeof($this->tableRowsToHide); $i++) {
$onChange .= 'document.getElementById(\'' . $this->tableRowsToHide[$i] . '\')?.closest(\'' . $selector . '\').classList.add(\'hidden\');';
}
$onChange .= '}';
$onChange .= 'else {';
for ($i = 0; $i < sizeof($this->tableRowsToShow); $i++) {
$onChange .= 'document.getElementById(\'' . $this->tableRowsToShow[$i] . '\')?.closest(\'' . $selector . '\').classList.add(\'hidden\');';
}
for ($i = 0; $i < sizeof($this->tableRowsToHide); $i++) {
$onChange .= 'document.getElementById(\'' . $this->tableRowsToHide[$i] . '\')?.closest(\'' . $selector . '\').classList.remove(\'hidden\');';
}
$onChange .= '};';
// build script to set initial state
$script .= '<script type="text/javascript">window.lam.utility.documentReady(function() {';
for ($i = 0; $i < sizeof($this->tableRowsToShow); $i++) {
$classType = 'add';
if ($this->checked) {
$classType = 'remove';
}
$script .= 'document.getElementById(\'' . $this->tableRowsToShow[$i] . '\')?.closest(\'' . $selector . '\').classList.' . $classType . '(\'hidden\');';
}
for ($i = 0; $i < sizeof($this->tableRowsToHide); $i++) {
$classType = 'remove';
if ($this->checked) {
$classType = 'add';
}
$script .= 'document.getElementById(\'' . $this->tableRowsToHide[$i] . '\')?.closest(\'' . $selector . '\').classList.' . $classType . '(\'hidden\');';
}
$script .= '});</script>';
}
// build Java script to enable/disable elements
if ((sizeof($this->elementsToEnable) > 0) || (sizeof($this->elementsToDisable) > 0)) {
// build onChange listener
$onChange .= 'if (document.querySelector(\'#' . $this->name . ':checked\') !== null) {';
for ($i = 0; $i < sizeof($this->elementsToEnable); $i++) {
$onChange .= 'document.getElementById(\'' . $this->elementsToEnable[$i] . '\').disabled = false;';
}
for ($i = 0; $i < sizeof($this->elementsToDisable); $i++) {
$onChange .= 'document.getElementById(\'' . $this->elementsToDisable[$i] . '\').disabled = true;';
}
$onChange .= '}';
$onChange .= 'else {';
for ($i = 0; $i < sizeof($this->elementsToEnable); $i++) {
$onChange .= 'document.getElementById(\'' . $this->elementsToEnable[$i] . '\').disabled = true;';
}
for ($i = 0; $i < sizeof($this->elementsToDisable); $i++) {
$onChange .= 'document.getElementById(\'' . $this->elementsToDisable[$i] . '\').disabled = false;';
}
$onChange .= '};';
// build script to set initial state
$script .= '<script type="text/javascript">window.lam.utility.documentReady(function() {';
for ($i = 0; $i < sizeof($this->elementsToEnable); $i++) {
$classType = 'true';
if ($this->checked) {
$classType = 'false';
}
$script .= 'document.getElementById(\'' . $this->elementsToEnable[$i] . '\').disabled = ' . $classType . ';';
}
for ($i = 0; $i < sizeof($this->elementsToDisable); $i++) {
$classType = 'false';
if ($this->checked) {
$classType = 'true';
}
$script .= 'document.getElementById(\'' . $this->elementsToDisable[$i] . '\').disabled = ' . $classType . ';';
}
$script .= '});</script>';
}
if (!empty($onChange)) {
$onChange = ' onChange="' . $onChange . '"';
}
$onClick = '';
if (!empty($this->onClick)) {
$onClick = ' onclick="' . $this->onClick . '"';
}
echo '<input type="checkbox" id="' . $this->name . '" name="' . $this->name . '"' . $classes
. $this->getAccessibilityMarkup() . $this->getDataAttributesAsString() . $onChange . $onClick . $title . $checked . $disabled . '>';
echo $script;
if ($this->transient) {
return [];
}
return [$this->name => 'checkbox'];
}
/**
* Specifies if this component is enabled and accepts user modification.
*
* @param boolean $isEnabled enabled if true
*/
public function setIsEnabled($isEnabled) {
$this->isEnabled = $isEnabled;
}
/**
* This will hide the given table rows when the checkbox is checked.
* The given IDs can be of any e.g. input element. Starting from this element
* the first parent "<tr>" element will be used to show/hide.
* <br>
* <br>
* <br>Example: <tr><td><input type="checkbox" id="mycheckbox"></td></tr>
* <br> Using "mycheckbox" will use this "tr" to hide/show.
*
* @param array $tableRowsToHide IDs of child elements to hide
*/
public function setTableRowsToHide($tableRowsToHide) {
$this->tableRowsToHide = $tableRowsToHide;
}
/**
* This will show the given table rows when the checkbox is checked.
* The given IDs can be of any e.g. input element. Starting from this element
* the first parent "<tr>" element will be used to show/hide.
* <br>
* <br>
* <br>Example: <tr><td><input type="checkbox" id="mycheckbox"></td></tr>
* <br> Using "mycheckbox" will use this "tr" to hide/show.
*
* @param array $tableRowsToShow IDs of child elements to show
*/
public function setTableRowsToShow($tableRowsToShow) {
$this->tableRowsToShow = $tableRowsToShow;
}
/**
* Specifies that the value should not be automatically saved when used in self service or server profile (default: false).
*
* @param boolean $transient transient field
*/
public function setTransient($transient) {
$this->transient = $transient;
}
/**
* This will disable the given input elements when the checkbox is checked.
* The given IDs can be of any input element (e.g. select, checkbox, ...).
*
* @param array $elements IDs of elements to disable
*/
public function setElementsToDisable($elements) {
$this->elementsToDisable = $elements;
}
/**
* This will enable the given input elements when the checkbox is checked.
* The given IDs can be of any input element (e.g. select, checkbox, ...).
*
* @param array $elements IDs of elements to enable
*/
public function setElementsToEnable($elements) {
$this->elementsToEnable = $elements;
}
/**
* Returns the CSS selector to use to find show/hide elements.
*/
protected function getShowHideSelector() {
return 'tr';
}
/**
* Sets the onclick code.
*
* @param string $code JS code
*/
public function setOnClick($code) {
$this->onClick = $code;
}
/**
* Returns the checkbox name.
*
* @return string name
*/
protected function getName(): string {
return $this->name;
}
/**
* Sets the title.
*
* @param string|null $title title
*/
public function setTitle(?string $title): void {
$this->title = $title;
}
}
/**
* Prints the HTML code for a file upload field.
*
* @package metaHTML
*/
class htmlInputFileUpload extends htmlElement {
/** unique name of input element */
private $name;
/** enabled or disabled */
private $isEnabled = true;
/** required */
protected $required = false;
/** onchange event */
protected $onChange = '';
/**
* Constructor.
*
* @param String $name unique name
*/
function __construct($name) {
$this->name = htmlspecialchars($name);
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
$disabled = '';
if (!$this->isEnabled) {
$disabled = ' disabled';
}
$required = '';
if ($this->required) {
$required = ' required="required"';
}
$onChange = '';
if (!empty($this->onChange)) {
$onChange = ' onchange="' . $this->onChange . '"';
}
$classValue = '';
if (!empty($this->cssClasses)) {
$classValue = ' class="' . implode(' ', $this->cssClasses) . '"';
}
echo '<input type="file" id="' . $this->name . '" name="' . $this->name . '"' . $classValue .
$onChange . $disabled . $required . $this->getDataAttributesAsString() . '>';
return [$this->name => 'file'];
}
/**
* Specifies if this component is enabled and accepts user modification.
*
* @param boolean $isEnabled enabled if true
*/
public function setIsEnabled($isEnabled) {
$this->isEnabled = $isEnabled;
}
/**
* Sets the field required.
*
* @param bool $required field is required (default: true)
*/
public function setRequired($required = true): void {
$this->required = $required;
}
/**
* Sets the onChange event.
*
* @param string $onChange onChange code
*/
public function setOnChange(string $onChange): void {
$this->onChange = $onChange;
}
}
/**
* Prints the HTML code for a textarea.
*
* @package metaHTML
*/
class htmlInputTextarea extends htmlElement {
/** unique name of input element */
protected $name;
/** value */
private $value;
/** column count */
private $colCount;
/** row count */
private $rowCount;
/** enabled or disabled */
private $isEnabled = true;
/** specifies if LAM should display this field with a WYSIWYG editor */
protected $richEdit = false;
/** required field */
protected $required = false;
/**
* Constructor.
*
* @param String $name unique name
* @param String $value value
* @param int $colCount number of characters per line
* @param int $rowCount number of rows
*/
function __construct($name, $value, $colCount, $rowCount) {
$this->name = htmlspecialchars($name);
$this->value = htmlspecialchars($value);
$this->colCount = htmlspecialchars($colCount);
$this->rowCount = htmlspecialchars($rowCount);
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
if (isset($values[$this->name])) {
$this->value = htmlspecialchars(implode("\r\n", $values[$this->name]));
}
$colCount = ($this->colCount != null) ? ' cols="' . $this->colCount . '"' : '';
$rowCount = ($this->rowCount != null) ? ' rows="' . $this->rowCount . '"' : '';
$disabled = '';
if (!$this->isEnabled) {
$disabled = ' disabled';
}
$classList = $this->cssClasses;
if ($this->richEdit) {
$classList[] = 'lam-rich-edit';
}
$required = '';
if ($this->required) {
$required = ' required';
}
$classes = ' class="' . implode(' ', $classList) . '"';
echo '<textarea name="' . $this->name . '" id="' . $this->name . '"' . $classes . $colCount .
$rowCount . $this->getDataAttributesAsString() . $this->getAccessibilityMarkup() . $required . $disabled . '>' .
$this->value . '</textarea>';
return [$this->name => 'textarea'];
}
/**
* Specifies if this component is enabled and accepts user modification.
*
* @param boolean $isEnabled enabled if true
*/
public function setIsEnabled($isEnabled) {
$this->isEnabled = $isEnabled;
}
/**
* Specifies if the textarea should be displayed with a WYSIWYG editor.
* <br>This requires that the page which displays the textarea also includes the JS for the rich editing.
* <br>Rich editing is disabled by default.
*
* @param boolean $richEdit rich edit or standard
*/
public function setIsRichEdit($richEdit) {
$this->richEdit = $richEdit;
}
/**
* Specifies if the input field is required.
*
* @param boolean $required required
*/
public function setRequired($required) {
$this->required = $required;
}
}
/**
* Prints the HTML code for a color picker field.
*
* @package metaHTML
*/
class htmlInputColorPicker extends htmlElement {
/** unique name of input element */
private $name;
/** color value */
private $color;
/** enabled or disabled */
private $isEnabled = true;
/**
* Constructor.
*
* @param string $name unique name
* @param string $colorValue color value (e.g. #000000)
*/
public function __construct($name, $colorValue = '#000000') {
$this->name = htmlspecialchars($name);
$this->color = htmlspecialchars($colorValue);
}
/**
* {@inheritDoc}
* @see htmlElement::generateHTML()
*/
public function generateHTML($module, $input, $values, $restricted, $scope) {
$disabled = '';
if (!$this->isEnabled) {
$disabled = ' disabled';
}
echo '<input type="color" value="' . $this->color . '" id="' . $this->name . '" name="' . $this->name . '"' . $disabled . '>';
return [$this->name => 'file'];
}
/**
* Specifies if this component is enabled and accepts user modification.
*
* @param boolean $isEnabled enabled if true
*/
public function setIsEnabled($isEnabled) {
$this->isEnabled = $isEnabled;
}
}
/**
* Color picker with descriptive label and help link.
*
* @package metaHTML
*/
class htmlResponsiveInputColorPicker extends htmlInputColorPicker {
/** descriptive label */
private $label;
/** help ID */
private $helpID;
/** help module */
private $helpModule;
/** render HTML of parent class */
private $renderParentHtml = false;
/**
* Constructor.
*
* @param string $name unique name
* @param string $colorValue color value (e.g. #000000)
* @param string $label descriptive label
* @param string $helpID help ID
*/
public function __construct($name, $colorValue, $label, $helpID = null) {
parent::__construct($name, $colorValue);
$this->label = htmlspecialchars($label);
if (is_string($helpID)) {
$this->helpID = $helpID;
}
elseif (is_array($helpID)) {
$this->helpID = $helpID[0];
$this->helpModule = $helpID[1];
}
}
/**
* {@inheritDoc}
* @see htmlInputColorPicker::generateHTML()
*/
public function generateHTML($module, $input, $values, $restricted, $scope) {
if ($this->renderParentHtml) {
return parent::generateHTML($module, $input, $values, $restricted, $scope);
}
// HTML of parent class is rendered on second call (done by htmlResponsiveRow)
$this->renderParentHtml = true;
$row = new htmlResponsiveRow();
// label text
$labelGroup = new htmlGroup();
$labelGroup->addElement(new htmlOutputText($this->label));
if (!empty($this->helpID)) {
$helpLinkLabel = new htmlHelpLink($this->helpID, $this->helpModule);
$helpLinkLabel->setCSSClasses(['hide-on-tablet', 'margin-left5']);
$labelGroup->addElement($helpLinkLabel);
}
$row->add($labelGroup, 12, 6, 6, 'responsiveLabel');
// input field
$fieldGroup = new htmlGroup();
$fieldGroup->addElement($this);
if (!empty($this->helpID)) {
$helpLinkField = new htmlHelpLink($this->helpID, $this->helpModule);
$helpLinkField->setCSSClasses(['hide-on-mobile']);
$fieldGroup->addElement($helpLinkField);
}
$row->add($fieldGroup, 12, 6, 6, 'responsiveField nowrap');
return $row->generateHTML($module, $input, $values, $restricted, $scope);
}
}
/**
* Prints the HTML code for an image.
*
* @package metaHTML
*/
class htmlImage extends htmlElement {
/** path to image */
private $path;
/** width */
private $width;
/** height */
private $height;
/** alt text */
private $alt;
/** title */
private $title;
/** onClick event */
private $onClick;
/** enable cropping */
private $crop = false;
/** enable lightbox */
private $lightbox = false;
/** @var string help popup title */
private $helpTitle;
/** @var htmlElement help popup content */
private $helpContent;
/**
* Constructor.
*
* @param String $path image location
* @param int $width image width (optional, default original size)
* @param int $height image height (optional, default original size)
* @param String $alt alt text (optional)
* @param String $onClick onClick code (optional)
*/
public function __construct($path, $width = null, $height = null, $alt = ' ', $title = null, $onClick = null) {
$this->path = htmlspecialchars($path);
$this->width = $width;
$this->height = $height;
$this->alt = htmlspecialchars($alt);
$this->title = $title;
$this->onClick = $onClick;
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
public function generateHTML($module, $input, $values, $restricted, $scope) {
$path = ' src="' . $this->path . '"';
$width = '';
if ($this->width != null) {
$width = ' width="' . $this->width . '"';
}
$height = '';
if ($this->height != null) {
$height = ' height="' . $this->height . '"';
}
$alt = ' alt="' . $this->alt . '"';
$title = '';
if (!empty($this->title)) {
$title = ' title="' . $this->title . '"';
}
if ($this->crop) {
$this->cssClasses[] = 'cropperjsImage';
}
if ($this->lightbox) {
$this->cssClasses[] = 'lam-lightbox';
$this->addDataAttribute('lightbox-label-close', _('Close'));
}
$classes = '';
if (!empty($this->cssClasses)) {
$classes = 'class="' . implode(' ', $this->cssClasses) . '"';
}
$onClick = '';
if ($this->onClick != null) {
$onClick = ' onclick="' . $this->onClick . '"';
}
$helpTitleValue = '';
$helpContentValue = '';
if ($this->helpTitle !== null) {
$helpTitleValue = ' helptitle="' . $this->helpTitle . '"';
ob_start();
$this->helpContent->generateHTML($module, $input, $values, $restricted, $scope);
$helpContentString = ob_get_contents();
ob_end_clean();
$helpContentValue = ' helpdata="' . htmlspecialchars($helpContentString) . '"';
}
echo '<img' . $path . $width . $height . $alt . $title . $classes . $onClick . $helpTitleValue . $helpContentValue . $this->getDataAttributesAsString() . ">";
if ($this->lightbox) {
echo '</a>';
}
if ($this->crop) {
echo '<script type="text/javascript">
window.lam.html.initCropping();
</script>';
echo '<input id="croppingDataX" type="hidden" name="croppingDataX" value="0"/>';
echo '<input id="croppingDataY" type="hidden" name="croppingDataY" value="0"/>';
echo '<input id="croppingDataWidth" type="hidden" name="croppingDataWidth" value="0"/>';
echo '<input id="croppingDataHeight" type="hidden" name="croppingDataHeight" value="0"/>';
}
return [];
}
/**
* Enables cropping feature.
* This will display a cropping box on the image. The cropping data
* can be found in POST data (croppingDataX, croppingDataY, croppingDataWidth, croppingDataHeight).
*/
public function enableCropping() {
$this->crop = true;
}
/**
* Enables lightbox feature.
*/
public function enableLightbox() {
$this->lightbox = true;
}
/**
* Activates the help popup on hover.
*
* @param string $title title
* @param htmlElement $content help content
*/
public function setHelpData(string $title, htmlElement $content) {
$this->helpTitle = htmlspecialchars($title);
$this->helpContent = $content;
}
/**
* Sets the onClick event code.
*
* @param string $code JS code
*/
public function setOnClick(string $code): void {
$this->onClick = $code;
}
}
/**
* Adds an empty space with given width and height.
*
* @package metaHTML
*/
class htmlSpacer extends htmlElement {
/** width of spacer in px */
private $width;
/** height of spacer in px */
private $height;
/**
* Constructor.
*
* @param string $width width (e.g. 10px)
* @param string|null $height height (e.g. 10px)
* @param array|null $cssClasses CSS classes
*/
function __construct($width, $height = null, ?array $cssClasses = []) {
if ($width !== null) {
$this->width = htmlspecialchars($width);
}
if ($height !== null) {
$this->height = htmlspecialchars($height);
}
if (!empty($cssClasses)) {
$this->setCSSClasses($cssClasses);
}
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
$width = '';
if ($this->width !== null) {
$width = 'width: ' . $this->width . ';';
}
$height = '';
if ($this->height !== null) {
$height = 'height: ' . $this->height . ';';
}
$classes = '';
if (!empty($this->cssClasses)) {
$classes = 'class="' . implode(' ', $this->cssClasses) . '"';
}
echo "<div $classes style=\"$width $height display: inline-block;\"></div>\n";
return [];
}
}
/**
* Prints a status message (e.g. error message).
*
* @package metaHTML
*/
class htmlStatusMessage extends htmlElement {
/** message type (e.g. ERROR) */
private $type;
/** message title */
private $title;
/** message text */
private $text;
/** message parameters */
private $params;
/**
* Constructor.
*
* @param String $type message type (e.g. ERROR)
* @param String $title message title
* @param String $text message (optional)
* @param array $params additional message parameters
*/
public function __construct($type, $title, $text = null, $params = null) {
$this->type = $type;
$this->title = $title;
$this->text = $text;
$this->params = $params;
}
/**
* Constructor with parameter array.
*
* @param array $params parameters in same order as normal constructor
* @return htmlStatusMessage
*/
public static function fromParamArray($params) {
if (sizeof($params) < 2) {
throw new BadMethodCallException("Invalid parameter count");
}
$count = count($params);
return match ($count) {
2 => new htmlStatusMessage($params[0], $params[1]),
3 => new htmlStatusMessage($params[0], $params[1], $params[2]),
4 => new htmlStatusMessage($params[0], $params[1], $params[2], $params[3]),
default => throw new BadMethodCallException("Invalid parameter count"),
};
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
public function generateHTML($module, $input, $values, $restricted, $scope) {
if (!empty($this->cssClasses)) {
echo '<div class="' . implode(' ', $this->cssClasses) . '">';
}
StatusMessage($this->type, $this->title, $this->text, $this->params);
if (!empty($this->cssClasses)) {
echo '</div>';
}
return [];
}
/**
* Returns the message type.
*
* @return String type
*/
public function getType() {
return $this->type;
}
}
/**
* Generates a title line. This is used for page titles.
*
* @package metaHTML
*/
class htmlTitle extends htmlElement {
/** descriptive label */
private $label;
/**
* Constructor.
*
* @param String $label label
*/
function __construct($label) {
$this->label = htmlspecialchars($label);
// the title should not end at a table cell
$this->colspan = 100;
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
echo "<div class=\"title\">\n";
echo "<h2 class=\"titleText\">\n";
echo $this->label;
echo "</h2>\n";
echo "</div>\n";
return [];
}
}
/**
* Generates a subtitle line. This is used to group multiple fields.
*
* @package metaHTML
*/
class htmlSubTitle extends htmlElement {
/** descriptive label */
private $label;
/** optional image */
private $image;
/** optional ID for this element (e.g. to use for JavaScript) */
private $id;
/** show large icon */
private $largeIcon = false;
/** help ID */
private $helpId;
/**
* Constructor.
*
* @param String $label label
* @param String $image optional image
* @param String $id optional ID for this element (e.g. to use for JavaScript)
* @param bool $largeIcon show large (32x32px) icon instead of small one (16x16px)
*/
public function __construct($label, $image = null, $id = null, $largeIcon = false) {
$this->label = htmlspecialchars($label);
if ($image !== null) {
$this->image = htmlspecialchars($image);
}
if ($id !== null) {
$this->id = htmlspecialchars($id);
}
// the title should not end at a table cell
$this->colspan = 100;
$this->largeIcon = $largeIcon;
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
public function generateHTML($module, $input, $values, $restricted, $scope) {
$idValue = '';
if ($this->id != null) {
$idValue = ' id="' . $this->id . '"';
}
echo "<div $idValue class=\"subTitle\">\n";
echo "<h4 class=\"subTitleText\">\n";
if ($this->image != null) {
$size = $this->largeIcon ? 32 : 16;
echo '<img height=' . $size . ' width=' . $size . ' src="' . $this->image . '" alt="' . $this->label . '"> ';
}
echo $this->label;
if ($this->helpId !== null) {
$spacer = new htmlSpacer('0.5rem', null);
$spacer->generateHTML($module, $input, $values, $restricted, $scope);
$helpLink = new htmlHelpLink($this->helpId);
$helpLink->generateHTML($module, $input, $values, $restricted, $scope);
}
echo "</h4>\n";
echo "</div>\n";
return [];
}
/**
* Sets an additional help id.
*
* @param string|array $helpId
*/
public function setHelpId($helpId) {
$this->helpId = $helpId;
}
}
/**
* Generates a hidden input field.
*
* @package metaHTML
*/
class htmlHiddenInput extends htmlElement {
/** field name */
private $name;
/** field value */
private $value;
/**
* Constructor.
*
* @param string $name input name
* @param string $value input value
*/
function __construct($name, $value = '') {
$this->name = htmlspecialchars($name);
if ($value !== null) {
$this->value = htmlspecialchars($value);
}
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
echo '<input type="hidden" name="' . $this->name . '" id="' . $this->name . '" value="' . $this->value . '">';
return [$this->name => 'hidden'];
}
}
/**
* Generates a link.
* The link can include an optional image in front of the link text.
*
* @package metaHTML
*/
class htmlLink extends htmlElement {
/** link text */
private $text;
/** link target */
protected $target;
/** optional image */
private $image;
/** title */
private $title;
/** target window */
private $targetWindow;
/** onClick event */
private $onClick;
/** onMouseOver event */
private $onMouseOver;
/** link id */
private $id;
/**
* Constructor.
*
* @param String $text label
* @param String $target target URL
* @param String $image URL of optional image
*/
function __construct($text, $target, $image = null) {
if ($text !== null) {
$this->text = htmlspecialchars($text);
}
if ($target !== null) {
$this->target = htmlspecialchars($target);
}
if ($image !== null) {
$this->image = htmlspecialchars($image);
}
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
$text = $this->getContent();
$image = '';
if ($this->image != null) {
$image = '<img class="align-middle" src="' . $this->image . '" alt="' . $this->getAlt() . '">';
if (!empty($text)) {
$image .= ' ';
}
}
$title = '';
if ($this->title != null) {
$title = ' title="' . $this->title . '"';
}
$targetWindow = '';
if ($this->targetWindow != null) {
$targetWindow = ' target="' . $this->targetWindow . '"';
}
$onClick = '';
if ($this->onClick != null) {
$onClick = ' onclick="' . $this->onClick . '"';
}
$onMouseOver = '';
if ($this->onMouseOver != null) {
$onMouseOver = ' onmouseover="' . $this->onMouseOver . '"';
}
$idAttr = '';
if (!empty($this->id)) {
$idAttr = ' id="' . $this->id . '"';
}
$classAttr = '';
if (sizeof($this->cssClasses) > 0) {
$classAttr = ' class="' . implode(' ', $this->cssClasses) . '"';
}
echo '<a href="' . $this->target . '"' . $idAttr . $classAttr . $title . $targetWindow . $onClick . $onMouseOver . $this->getDataAttributesAsString() . '>' . $image . $text . '</a>';
return [];
}
/**
* Returns the value for the alt attribute.
*
* @return string alt value
*/
protected function getAlt() {
if (!empty($this->text)) {
return $this->text;
}
return $this->title;
}
/**
* Returns the value for the link content.
*
* @return string content
*/
protected function getContent() {
return $this->text;
}
/**
* Sets the link title.
*
* @param String $title title
*/
public function setTitle($title) {
$this->title = htmlspecialchars($title);
}
/**
* Sets the target window (e.g. _blank).
*
* @param String $window target window (e.g. _blank)
*/
public function setTargetWindow($window) {
$this->targetWindow = htmlspecialchars($window);
}
/**
* Sets the onClick event.
*
* @param String $event JavaScript code
*/
public function setOnClick($event) {
$this->onClick = htmlspecialchars($event);
}
/**
* Sets the onMouseOver event.
*
* @param String $event JavaScript code
*/
public function setOnMouseOver($event) {
$this->onMouseOver = htmlspecialchars($event);
}
/**
* Sets the element id.
*
* @param string $id unique id
*/
public function setId($id) {
$this->id = $id;
}
}
/**
* Generates a link around a htmlElement.
*
* @package metaHTML
*/
class htmlContentLink extends htmlLink {
private $content;
private $contentText = '';
/**
* Constructor
*
* @param htmlElement $content content to link
* @param String $target link target
* @param boolean $highlightOnHover highlight content on hover
*/
function __construct($content, $target) {
$this->content = $content;
$this->target = htmlspecialchars($target);
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
ob_start();
parseHtml($module, $this->content, $values, $restricted, $scope);
$this->contentText = ob_get_contents();
ob_end_clean();
return parent::generateHTML($module, $input, $values, $restricted, $scope);
}
/**
* Returns the value for the alt attribute.
*
* @return string alt value
*/
protected function getAlt() {
return '';
}
/**
* Returns the value for the link content.
*
* @return string content
*/
protected function getContent() {
return $this->contentText;
}
}
/**
* Groups multiple htmlElements.
* This is useful if multiple elements should be included in a single table cell.
* The HTML code of the subelements is printed in the order they were added. No additional code is added.
*
* @package metaHTML
*/
class htmlGroup extends htmlElement {
/** link text */
private $subelements = [];
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
$return = [];
for ($i = 0; $i < sizeof($this->subelements); $i++) {
$return = array_merge($return, $this->subelements[$i]->generateHTML($module, $input, $values, $restricted, $scope));
}
return $return;
}
/**
* Adds a subelement.
*
* @param htmlElement $sub subelement
*/
public function addElement($sub) {
$this->subelements[] = $sub;
}
}
/**
* Prints a horizontal line.
*
* @package metaHTML
*/
class htmlHorizontalLine extends htmlElement {
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
$return = [];
echo "<hr>";
return $return;
}
}
/**
* Creates a simple DIV element.
*
* @package metaHTML
*/
class htmlDiv extends htmlElement {
/** unique ID */
private $id;
/** htmlElement that generates inner content */
private $content;
/**
* Constructor.
*
* @param String $id unique ID
* @param htmlElement $content inner content
* @param array $classes CSS classes
* @param string[] $cssClasses CSS classes
*/
function __construct($id, $content, $cssClasses = null) {
if ($id !== null) {
$this->id = htmlspecialchars($id);
}
$this->content = $content;
$this->cssClasses = $cssClasses;
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
$return = [];
$idValue = '';
if ($this->id != null) {
$idValue = ' id="' . $this->id . '"';
}
$classesValue = '';
if (($this->cssClasses != null) && (sizeof($this->cssClasses) > 0)) {
$classesValue = ' class="' . implode(' ', $this->cssClasses) . '"';
}
echo '<div' . $idValue . $classesValue . $this->getDataAttributesAsString() . '>';
if ($this->content != null) {
$return = $this->content->generateHTML($module, $input, $values, $restricted, $scope);
}
echo '</div>';
return $return;
}
}
/**
* Creates a simple SPAN element.
*
* @package metaHTML
*/
class htmlSpan extends htmlElement {
/** htmlElement that generates inner content */
private $content;
/** onclick handler */
private $onclick;
/** title */
private $title;
/**
* Constructor.
*
* @param htmlElement $content inner content
* @param array $classes CSS classes
* @param string[] $cssClasses CSS classes
*/
function __construct($content, $cssClasses = null) {
$this->content = $content;
$this->cssClasses = $cssClasses;
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
$return = [];
$classesValue = '';
if (($this->cssClasses != null) && (sizeof($this->cssClasses) > 0)) {
$classesValue = ' class="' . implode(' ', $this->cssClasses) . '"';
}
$onclickHandler = '';
if (!empty($this->onclick)) {
$onclickHandler = ' onclick="' . $this->onclick . '"';
}
$titleCode = '';
if ($this->title !== null) {
$titleCode = ' title="' . $this->title . '"';
}
echo '<span' . $classesValue . $titleCode . $onclickHandler . '>';
if ($this->content != null) {
$return = $this->content->generateHTML($module, $input, $values, $restricted, $scope);
}
echo '</span>';
return $return;
}
/**
* Sets the onclick event.
*
* @param string $event event handler code
*/
public function setOnclick($event) {
$this->onclick = $event;
}
/**
* Sets the title.
*
* @param string|null $title title
*/
public function setTitle(?string $title): void {
$this->title = htmlspecialchars($title);
}
}
/**
* Creates a JavaScript element.
*
* @package metaHTML
*/
class htmlJavaScript extends htmlElement {
/** htmlElement that generates inner content */
private $content;
/**
* Constructor.
*
* @param String $content script
*/
function __construct($content) {
$this->content = $content;
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
$return = [];
echo '<script type="text/javascript">';
echo $this->content;
echo '</script>';
return $return;
}
}
/**
* Creates a iframe element.
*
* @package metaHTML
*/
class htmlIframe extends htmlElement {
/** HTML id */
private $id;
/**
* Constructor.
*
* @param String $content script
*/
function __construct($id = null) {
$this->id = $id;
}
/**
* {@inheritDoc}
* @see htmlElement::generateHTML()
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
$return = [];
$idAttr = '';
if (!empty($this->id)) {
$idAttr = ' id="' . $this->id . '"';
}
echo '<iframe ' . $idAttr . $this->getDataAttributesAsString() . '>';
echo '</iframe>';
return $return;
}
}
/**
* Creates a Script element to integrate external JavaScript files.
*
* @package metaHTML
*/
class htmlScript extends htmlElement {
/** src value */
private $src;
/** is async */
private $async = false;
/** execute after page is parsed */
private $defer = false;
/**
* Constructor.
*
* @param String $src script path
* @param boolean $isAsync script will be executed while the page continues the parsing (default true)
* @param boolean $isDeferred script is executed when the page has finished parsing (default true)
*/
function __construct($src, $isAsync = true, $isDeferred = true) {
$this->src = $src;
$this->async = $isAsync;
$this->defer = $isDeferred;
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
$return = [];
$async = $this->async ? ' async' : '';
$defer = $this->defer ? ' defer="defer"' : '';
echo '<script src="' . $this->src . '"' . $async . $defer . '>';
echo '</script>';
return $return;
}
}
/**
* Creates a link element to integrate external CSS files.
*
* @package metaHTML
*/
class htmlLinkCss extends htmlElement {
/** src value */
private $src;
/**
* Constructor.
*
* @param String $src script path
*/
function __construct($src) {
$this->src = $src;
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
$return = [];
echo '<link href="' . $this->src . '" type="text/css" rel="stylesheet"/>';
return $return;
}
}
/**
* Creates a list of elements that can be sorted by the user via drag'n'drop.
*
* @package metaHTML
*/
class htmlSortableList extends htmlElement {
/** list of elements */
private $elements;
/** HTML ID */
private $id;
/** on update event */
private $onUpdate;
/**
* Constructor.
*
* @param string[] $elements list of elements as text (HTML special chars must be escaped already) or htmlElement
* @param string HTML ID
*/
function __construct(array $elements, string $id) {
$this->elements = $elements;
$this->id = htmlspecialchars($id);
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
if (sizeof($this->elements) == 0) {
return [];
}
$return = [];
$classesValue = '';
if (!empty($this->cssClasses)) {
$classesValue = ' class="' . implode(' ', $this->cssClasses) . '"';
}
echo '<ul' . $classesValue . ' id="' . $this->id . '">';
for ($i = 0; $i < sizeof($this->elements); $i++) {
$element = $this->elements[$i];
echo '<li data-position-orig="' . $i . '">';
echo '<span class="lam-sortable-list-icon"></span>';
if ($element instanceof htmlElement) {
parseHtml($module, $element, $values, $restricted, $scope);
}
else {
echo $element;
}
echo '</li>';
}
echo '</ul>';
$onUpdate = '';
if ($this->onUpdate != null) {
$onUpdate = 'onUpdate: ' . $this->onUpdate;
}
$scriptContent = '
Sortable.create(
document.getElementById("' . $this->id . '"),
{
' . $onUpdate . '
}
);';
$script = new htmlJavaScript($scriptContent);
$script->generateHTML($module, $input, $values, $restricted, $scope);
return $return;
}
/**
* Sets the JS code that is executed when the element order was changed.
*
* @param String $onUpdate JS code
*/
public function setOnUpdate($onUpdate) {
$this->onUpdate = $onUpdate;
}
}
/**
* Creates a list of content elements in accordion style.
* HTML special characters must be escaped before providing to htmlAccordion.
*/
class htmlAccordion extends htmlElement {
private $id;
private $elements;
private $openInitial;
private $saveState;
private bool $allowResorting = false;
/**
* Constructor.
*
* @param String $id HTML ID
* @param array $elements list of content elements array('title' => htmlElement)
* @param mixed $openInitial index of element that is initially opened (default: 0), set to 'false' to close all
*/
function __construct($id, $elements, mixed $openInitial = 0) {
$this->id = $id;
$this->elements = $elements;
$this->openInitial = $openInitial;
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
$result = [];
if ($this->openInitial !== false) {
$this->addDataAttribute('openinitial', $this->openInitial);
}
$cssClasses = $this->getCSSClasses();
$cssClasses[] = 'lam-accordion-container';
if ($this->saveState) {
$this->addDataAttribute('savestate', 'true');
}
echo '<div id="' . $this->id . '" class="' . implode(' ', $cssClasses) . '"' . $this->getDataAttributesAsString() . '>';
$contentIndex = 0;
foreach ($this->elements as $label => $content) {
echo '<button id="' . $this->id . '_' . $contentIndex . '" class="lam-accordion-button" onclick="return false;" data-index="' . $contentIndex . '">';
echo $label;
echo '</button>';
echo '<div class="lam-accordion-content" data-index="' . $contentIndex . '">';
echo '<div class="lam-accordion-content-inner">';
$result = array_merge($result, $content->generateHTML($module, $input, $values, $restricted, $scope));
echo '</div>';
echo '</div>';
$contentIndex++;
}
$hiddenIndexId = $this->id . "_index";
echo '<input type="hidden" name="' . $hiddenIndexId . '" id="' . $hiddenIndexId . '" value="false">';
echo '</div>';
if ($this->allowResorting) {
$onResorting = 'onUpdate: function() {
window.lam.html.updateAccordionSorting("' . $this->id . '");
}';
$scriptContent = '
Sortable.create(
document.getElementById("' . $this->id . '"),
{
' . $onResorting . '
}
);';
$resortingGroup = new htmlGroup();
$script = new htmlJavaScript($scriptContent);
$resortingGroup->addElement($script);
$resortingGroup->addElement(new htmlHiddenInput($this->id . '_sorting', ''));
$resortingGroup->generateHTML($module, $input, $values, $restricted, $scope);
}
return $result;
}
/**
* Saves the state of open/closed items over page reloads.
*
* @param bool $saveState save state
*/
public function saveState(bool $saveState = true): void {
$this->saveState = $saveState;
}
/**
* Allows the user to resort the accordion elements.
*/
public function allowResorting(): void {
$this->allowResorting = true;
}
}
/**
* Responsive row with 12 column layout.
*/
class htmlResponsiveRow extends htmlElement {
/** @var htmlResponsiveCell[] cells */
private $cells = [];
/** HTML ID */
private $id;
/**
* Creates a new responsive row.
*
* @param htmlElement $label label element if this is a simple label+field row
* @param htmlElement $field field element if this is a simple label+field row
*/
public function __construct($label = null, $field = null) {
$this->cells = [];
if ($label != null) {
$this->addLabel($label);
}
if ($field != null) {
$this->addField($field);
}
}
/**
* Sets the HTML id.
*
* @param string $id ID
*/
public function setId($id) {
$this->id = $id;
}
/**
* Adds a responsive cell at the end of the row.
*
* @param htmlResponsiveCell $cell cell
*/
public function addCell(htmlResponsiveCell $cell) {
$this->cells[] = $cell;
}
/**
* Adds a responsive cell at the beginning of the row.
*
* @param htmlResponsiveCell $cell cell
*/
public function addCellAtTheBeginning(htmlResponsiveCell $cell) {
array_unshift($this->cells, $cell);
}
/**
* Adds a cell with the given content and column counts.
*
* @param htmlElement $content content inside cell
* @param int $numMobile number of columns for mobile view
* @param int $numTablet number of columns for tablet view (set to mobile if null)
* @param int $numDesktop number of columns for desktop view (set to tablet if null)
* @param String $classes CSS classes separated by space
*/
public function add($content, $numMobile = 12, $numTablet = null, $numDesktop = null, $classes = '') {
$tabletCols = $numTablet ?? $numMobile;
$desktopCols = $numDesktop ?? $tabletCols;
$this->addCell(new htmlResponsiveCell($content, $numMobile, $tabletCols, $desktopCols, $classes));
}
/**
* Adds a cell at the beginning with the given content and column counts.
*
* @param htmlElement $content content inside cell
* @param int $numMobile number of columns for mobile view
* @param int $numTablet number of columns for tablet view (set to mobile if null)
* @param int $numDesktop number of columns for desktop view (set to tablet if null)
* @param String $classes CSS classes separated by space
*/
public function addAtTheBeginning($content, $numMobile = 12, $numTablet = null, $numDesktop = null, $classes = '') {
$tabletCols = $numTablet ?? $numMobile;
$desktopCols = $numDesktop ?? $tabletCols;
$this->addCellAtTheBeginning(new htmlResponsiveCell($content, $numMobile, $tabletCols, $desktopCols, $classes));
}
/**
* Adds the content as a typical label with 12/6/6 columns and CSS class "responsiveLabel".
*
* @param htmlElement $content label
* @param string $cssClasses additional CSS classes
*/
public function addLabel($content, $cssClasses = '') {
$this->add($content, 12, 6, 6, 'responsiveLabel nowrap ' . $cssClasses);
}
/**
* Adds the content as a typical field with 12/6/6 columns and CSS class "responsiveField".
*
* @param htmlElement $content field
* @param string $cssClasses CSS class names separated by space
*/
public function addField($content, $cssClasses = '') {
$this->add($content, 12, 6, 6, 'responsiveField ' . $cssClasses);
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
public function generateHTML($module, $input, $values, $restricted, $scope) {
$return = [];
$cssClasses = implode(' ', $this->cssClasses);
$idParam = '';
if ($this->id !== null) {
$idParam = ' id="' . $this->id . '"';
}
echo '<div class="row ' . $cssClasses . '"' . $this->getDataAttributesAsString() . $idParam . '>';
foreach ($this->cells as $cell) {
$return = array_merge($return, $cell->generateHTML($module, $input, $values, $restricted, $scope));
}
echo '</div>';
return $return;
}
/**
* Adds a vertical spacer with 12 columns.
*
* @param string $space space in px or rem
*/
public function addVerticalSpacer($space) {
$this->add(new htmlSpacer(null, $space));
}
/**
* Returns the current number of cells.
*
* @return int cell count
*/
public function getCellCount(): int {
return sizeof($this->cells);
}
}
/**
* Responsive cell inside htmlResponsiveRow with 12 column layout.
*/
class htmlResponsiveCell extends htmlElement {
private $content;
private $mobile;
private $tablet;
private $desktop;
private $classes = '';
/**
* Constructs a cell inside a responsive row with 12 columns.
*
* @param htmlElement $content content inside cell
* @param int $numMobile number of columns for mobile view
* @param int $numTablet number of columns for tablet view
* @param int $numDesktop number of columns for desktop view
* @param String $classes CSS classes separated by space
*/
public function __construct($content, $numMobile, $numTablet, $numDesktop, $classes = '') {
$this->content = $content;
$this->mobile = $numMobile;
$this->tablet = $numTablet;
$this->desktop = $numDesktop;
$this->classes = $classes;
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
public function generateHTML($module, $input, $values, $restricted, $scope) {
$clMobile = ($this->mobile > 0) ? 'small-' . $this->mobile : 'hide-for-small-only';
$clTablet = ($this->tablet > 0) ? 'medium-' . $this->tablet : 'hide-for-medium-only';
$clDesktop = ($this->desktop > 0) ? 'large-' . $this->desktop : 'hide-for-large-only';
echo '<div class="' . $clMobile . ' ' . $clTablet . ' ' . $clDesktop . ' columns ' . $this->classes . '">';
$return = $this->content->generateHTML($module, $input, $values, $restricted, $scope);
echo '</div>';
return $return;
}
}
/**
* A responsive input field that combines label, input field and help.
*
* @package metaHTML
*/
class htmlResponsiveInputField extends htmlInputField {
/** Descriptive label */
private $label;
/** help ID */
private $helpID;
/** help module name */
private $helpModule;
/** render HTML of parent class */
private $renderParentHtml = false;
/** short label */
private $shortLabel = false;
/**
* Constructor
*
* @param String $label descriptive label
* @param String $fieldName unique field name
* @param String $fieldValue value of input field (optional)
* @param String|array $helpID help ID or array of help ID + module name (optional)
* @param bool $required field is required
*/
function __construct($label, $fieldName, $fieldValue = null, $helpID = null, $required = false) {
parent::__construct($fieldName, $fieldValue);
$this->label = $label;
if (is_string($helpID)) {
$this->helpID = $helpID;
}
elseif (is_array($helpID)) {
$this->helpID = $helpID[0];
$this->helpModule = $helpID[1];
}
$this->fieldSize = null;
$this->required = $required;
}
/**
* {@inheritDoc}
* @see htmlInputField::generateHTML()
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
if ($this->renderParentHtml) {
return parent::generateHTML($module, $input, $values, $restricted, $scope);
}
// HTML of parent class is rendered on second call (done by htmlResponsiveRow)
$this->renderParentHtml = true;
$row = new htmlResponsiveRow();
// label text
$labelGroup = new htmlGroup();
$idValue = $this->id ?? $this->fieldName;
$labelGroup->addElement(new htmlLabel($idValue, $this->label));
if ($this->required) {
$labelGroup->addElement(htmlGetRequiredMarkerElement());
}
if (!empty($this->helpID)) {
$helpLinkLabel = new htmlHelpLink($this->helpID, $this->helpModule);
$helpLinkLabel->setCSSClasses(['hide-on-tablet', 'margin-left5']);
$labelGroup->addElement($helpLinkLabel);
}
$tabletDesktopLabelColumns = $this->shortLabel ? 4 : 6;
$row->add($labelGroup, 12, $tabletDesktopLabelColumns, $tabletDesktopLabelColumns, 'responsiveLabel');
// input field
$fieldGroup = new htmlGroup();
$fieldGroup->addElement($this);
if (!empty($this->helpID)) {
$helpLinkField = new htmlHelpLink($this->helpID, $this->helpModule);
$helpLinkField->setCSSClasses(['hide-on-mobile']);
$fieldGroup->addElement($helpLinkField);
}
$tabletDesktopFieldColumns = $this->shortLabel ? 8 : 6;
$row->add($fieldGroup, 12, $tabletDesktopFieldColumns, $tabletDesktopFieldColumns, 'responsiveField nowrap');
return $row->generateHTML($module, $input, $values, $restricted, $scope);
}
/**
* Use a short label (4 columns instead of 6) for tablet/desktop.
*/
public function setShortLabel() {
$this->shortLabel = true;
}
}
/**
* File upload with descriptive label and help link.
*
* @package metaHTML
*/
class htmlResponsiveInputFileUpload extends htmlInputFileUpload {
/** descriptive label */
private $label;
/** help ID */
private $helpID;
/** help module */
private $helpModule;
/** render HTML of parent class */
private $renderParentHtml = false;
/**
* Constructor.
*
* @param String $name unique name
* @param String $label descriptive label
* @param String $helpID help ID
* @param string $required required field
*/
function __construct($name, $label, $helpID = null, $required = false) {
parent::__construct($name);
$this->label = htmlspecialchars($label);
if (is_string($helpID)) {
$this->helpID = $helpID;
}
elseif (is_array($helpID)) {
$this->helpID = $helpID[0];
$this->helpModule = $helpID[1];
}
$this->required = $required;
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
if ($this->renderParentHtml) {
return parent::generateHTML($module, $input, $values, $restricted, $scope);
}
// HTML of parent class is rendered on second call (done by htmlResponsiveRow)
$this->renderParentHtml = true;
$row = new htmlResponsiveRow();
// label text
$labelGroup = new htmlGroup();
$labelGroup->addElement(new htmlOutputText($this->label));
if ($this->required) {
$labelGroup->addElement(htmlGetRequiredMarkerElement());
}
if (!empty($this->helpID)) {
$helpLinkLabel = new htmlHelpLink($this->helpID, $this->helpModule);
$helpLinkLabel->setCSSClasses(['hide-on-tablet', 'margin-left5']);
$labelGroup->addElement($helpLinkLabel);
}
$row->add($labelGroup, 12, 6, 6, 'responsiveLabel');
// input field
$fieldGroup = new htmlGroup();
$fieldGroup->addElement($this);
if (!empty($this->helpID)) {
$helpLinkField = new htmlHelpLink($this->helpID, $this->helpModule);
$helpLinkField->setCSSClasses(['hide-on-mobile']);
$fieldGroup->addElement($helpLinkField);
}
$row->add($fieldGroup, 12, 6, 6, 'responsiveField nowrap');
return $row->generateHTML($module, $input, $values, $restricted, $scope);
}
}
/**
* Responsive text area with label and help link.
*
* @package metaHTML
*/
class htmlResponsiveInputTextarea extends htmlInputTextarea {
/** descriptive label */
private $label;
/** help ID */
private $helpID;
/** help module */
private $helpModule;
/** render HTML of parent class */
private $renderParentHtml = false;
/** short label */
private $shortLabel = false;
/**
* Constructor.
*
* @param String $name unique name
* @param String $value value
* @param int $colCount number of characters per line
* @param int $rowCount number of rows
* @param String $label descriptive label
* @param String|array $helpID help ID
*/
function __construct($name, $value, $colCount, $rowCount, $label, $helpID = null) {
parent::__construct($name, $value, $colCount, $rowCount);
$this->label = htmlspecialchars($label);
if (is_string($helpID)) {
$this->helpID = $helpID;
}
elseif (is_array($helpID)) {
$this->helpID = $helpID[0];
$this->helpModule = $helpID[1];
}
$this->alignment = htmlElement::ALIGN_TOP;
}
/**
* {@inheritDoc}
* @see htmlInputField::generateHTML()
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
if ($this->renderParentHtml) {
return parent::generateHTML($module, $input, $values, $restricted, $scope);
}
// HTML of parent class is rendered on second call (done by htmlResponsiveRow)
$this->renderParentHtml = true;
$row = new htmlResponsiveRow();
// label text
$labelGroup = new htmlGroup();
$labelGroup->addElement(new htmlLabel($this->name, $this->label));
if ($this->required) {
$labelGroup->addElement(htmlGetRequiredMarkerElement());
}
if (!empty($this->helpID)) {
$helpLinkLabel = new htmlHelpLink($this->helpID, $this->helpModule);
$helpCssClasses = ['margin-left5'];
if (!$this->richEdit) {
$helpCssClasses[] = 'hide-on-tablet';
}
$helpLinkLabel->setCSSClasses($helpCssClasses);
$labelGroup->addElement($helpLinkLabel);
}
$tabletDesktopLabelColumns = $this->shortLabel ? 4 : 6;
$row->add($labelGroup, 12, $tabletDesktopLabelColumns, $tabletDesktopLabelColumns, 'responsiveLabel');
// input field
$fieldGroup = new htmlGroup();
$fieldGroup->addElement($this);
if (!empty($this->helpID) && !$this->richEdit) {
$helpLink = new htmlHelpLink($this->helpID, $this->helpModule);
$helpLink->setCSSClasses(['align-top', 'hide-on-mobile']);
$fieldGroup->addElement($helpLink);
}
$tabletDesktopFieldColumns = $this->shortLabel ? 8 : 6;
$row->add($fieldGroup, 12, $tabletDesktopFieldColumns, $tabletDesktopFieldColumns, 'responsiveField nowrap');
return $row->generateHTML($module, $input, $values, $restricted, $scope);
}
/**
* Use a short label (4 columns instead of 6) for tablet/desktop.
*/
public function setShortLabel() {
$this->shortLabel = true;
}
}
/**
* Responsive select with label and help link.
*
* @package metaHTML
*/
class htmlResponsiveSelect extends htmlSelect {
/** descriptive label */
private $label;
/** help ID */
private $helpID;
/** help module name */
private $helpModule;
/** render HTML of parent class */
private $renderParentHtml = false;
/** short label */
private $shortLabel = false;
/**
* Constructor.
*
* @param String $name element name
* @param array $elements list of elements
* @param array $selectedElements list of selected elements
* @param String $label descriptive label
* @param String|array $helpID help ID or array of help ID + module name (optional)
* @param int $size size (optional, default = 1)
*/
function __construct($name, $elements, $selectedElements, $label, $helpID = null, $size = 1) {
parent::__construct($name, $elements, $selectedElements, $size);
$this->label = $label;
if (is_string($helpID)) {
$this->helpID = $helpID;
}
elseif (is_array($helpID)) {
$this->helpID = $helpID[0];
$this->helpModule = $helpID[1];
}
}
/**
* {@inheritDoc}
* @see htmlInputField::generateHTML()
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
if ($this->renderParentHtml) {
return parent::generateHTML($module, $input, $values, $restricted, $scope);
}
// HTML of parent class is rendered on second call (done by htmlResponsiveRow)
$this->renderParentHtml = true;
$row = new htmlResponsiveRow();
// label text
$labelGroup = new htmlGroup();
$labelGroup->addElement(new htmlLabel($this->name, $this->label));
if (!empty($this->helpID)) {
$helpLinkLabel = new htmlHelpLink($this->helpID, $this->helpModule);
$helpLinkLabel->setCSSClasses(['hide-on-tablet', 'margin-left5']);
$labelGroup->addElement($helpLinkLabel);
}
$tabletDesktopLabelColumns = $this->shortLabel ? 4 : 6;
$row->add($labelGroup, 12, $tabletDesktopLabelColumns, $tabletDesktopLabelColumns, 'responsiveLabel');
// input field
$fieldGroup = new htmlGroup();
$fieldGroup->addElement($this);
if (!empty($this->helpID)) {
$helpLink = new htmlHelpLink($this->helpID, $this->helpModule);
$helpLink->setCSSClasses(['hide-on-mobile']);
$fieldGroup->addElement($helpLink);
}
$tabletDesktopFieldColumns = $this->shortLabel ? 8 : 6;
$row->add($fieldGroup, 12, $tabletDesktopFieldColumns, $tabletDesktopFieldColumns, 'responsiveField nowrap');
return $row->generateHTML($module, $input, $values, $restricted, $scope);
}
/**
* {@inheritDoc}
* @see htmlSelect::getShowHideSelector()
*/
protected function getShowHideSelector() {
return '.row';
}
/**
* Use a short label (4 columns instead of 6) for tablet/desktop.
*/
public function setShortLabel() {
$this->shortLabel = true;
}
}
/**
* Responsive select with label and help link.
*
* @package metaHTML
*/
class htmlResponsiveRadio extends htmlRadio {
/** descriptive label */
private $label;
/** help ID */
private $helpID;
/** render HTML of parent class */
private $renderParentHtml = false;
/**
* Constructor.
*
* @param String $name element name
* @param array $elements list of elements
* @param array $selectedElements list of selected elements
* @param String $label descriptive label
* @param String $helpID help ID (optional, default none)
* @param int $size size (optional, default = 1)
*/
function __construct($label, $name, $elements, $selectedElement = null, $helpID = null) {
parent::__construct($name, $elements, $selectedElement);
$this->label = htmlspecialchars($label);
$this->helpID = $helpID;
}
/**
* {@inheritDoc}
* @see htmlInputField::generateHTML()
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
if ($this->renderParentHtml) {
return parent::generateHTML($module, $input, $values, $restricted, $scope);
}
// HTML of parent class is rendered on second call (done by htmlResponsiveRow)
$this->renderParentHtml = true;
$row = new htmlResponsiveRow();
// label text
$labelGroup = new htmlGroup();
$labelGroup->addElement(new htmlOutputText($this->label));
if (!empty($this->helpID)) {
$helpLinkLabel = new htmlHelpLink($this->helpID);
$helpLinkLabel->setCSSClasses(['hide-on-tablet', 'margin-left5']);
$labelGroup->addElement($helpLinkLabel);
}
$row->add($labelGroup, 12, 6, 6, 'responsiveLabel');
// input field
$fieldGroup = new htmlGroup();
$fieldGroup->addElement(new htmlDiv(null, $this, ['float-left']));
if (!empty($this->helpID)) {
$helpLink = new htmlHelpLink($this->helpID);
$helpLink->setCSSClasses(['hide-on-mobile']);
$fieldGroup->addElement(new htmlDiv(null, $helpLink));
}
$row->add($fieldGroup, 12, 6, 6, 'responsiveField nowrap');
return $row->generateHTML($module, $input, $values, $restricted, $scope);
}
/**
* Returns the selector to use to find the show/hide elements.
*
* @return string selector
*/
protected function getShowHideSelector() {
return '.row';
}
}
/**
* Responsive checkbox with descriptive label and help link.
*
* @package metaHTML
*/
class htmlResponsiveInputCheckbox extends htmlInputCheckbox {
/** descriptive label */
private $label;
/** help ID */
private $helpID;
/** help module name */
private $helpModule;
/** render HTML of parent class */
private $renderParentHtml = false;
/** long label */
private $longLabel = false;
/** label after checkbox */
private $labelAfterCheckbox = false;
/** short label */
private $shortLabel = false;
/**
* Constructor.
*
* @param String $name unique name
* @param boolean $checked checked
* @param String $label descriptive label
* @param String|array $helpID help ID or array of help ID + module name (optional)
* @param bool $longLabel more space for label (default: false)
*/
function __construct($name, $checked, $label, $helpID = null, $longLabel = false) {
parent::__construct($name, $checked);
$this->label = $label;
if (is_string($helpID)) {
$this->helpID = $helpID;
}
elseif (is_array($helpID)) {
$this->helpID = $helpID[0];
$this->helpModule = $helpID[1];
}
$this->longLabel = $longLabel;
}
/**
* {@inheritDoc}
* @see htmlInputField::generateHTML()
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
if ($this->renderParentHtml) {
return parent::generateHTML($module, $input, $values, $restricted, $scope);
}
// HTML of parent class is rendered on second call (done by htmlResponsiveRow)
$this->renderParentHtml = true;
$row = new htmlResponsiveRow();
$tabletColumnsLabel = 6;
$tabletColumnsBox = 6;
$mobileColumnsLabel = 10;
$mobileColumnsBox = 2;
if ($this->longLabel) {
$tabletColumnsLabel = 10;
$tabletColumnsBox = 2;
}
if ($this->shortLabel) {
$tabletColumnsLabel = 4;
$tabletColumnsBox = 8;
}
// label text
$text = new htmlLabel($this->getName(), $this->label);
$text->setCSSClasses($this->cssClasses);
// input field
$fieldGroup = new htmlGroup();
$fieldGroup->addElement($this);
if (!empty($this->helpID)) {
$helpLink = new htmlHelpLink($this->helpID, $this->helpModule);
$helpLink->setCSSClasses(['margin-left5 align-unset-img']);
$fieldGroup->addElement($helpLink);
}
if ($this->labelAfterCheckbox) {
$row->add($fieldGroup, $mobileColumnsBox, $tabletColumnsBox, $tabletColumnsBox, 'responsiveLabel nowrap');
$row->add($text, $mobileColumnsLabel, $tabletColumnsLabel, $tabletColumnsLabel, 'responsiveField');
}
else {
$row->add($text, $mobileColumnsLabel, $tabletColumnsLabel, $tabletColumnsLabel, 'responsiveLabel');
$row->add($fieldGroup, $mobileColumnsBox, $tabletColumnsBox, $tabletColumnsBox, 'responsiveField nowrap');
}
return $row->generateHTML($module, $input, $values, $restricted, $scope);
}
/**
* {@inheritDoc}
* @see htmlInputCheckbox::getShowHideSelector()
*/
protected function getShowHideSelector() {
return '.row';
}
/**
* Sets if the label should be shown after the checkbox instead before it.
*
* @param bool $labelAfterCheckbox show label after box
*/
public function setLabelAfterCheckbox($labelAfterCheckbox = true) {
$this->labelAfterCheckbox = $labelAfterCheckbox;
}
/**
* Use a short label (4 columns instead of 6) for tablet/desktop.
*/
public function setShortLabel() {
$this->shortLabel = true;
}
}
/**
* Responsive table.
*
* @author roland Gruber
*/
class htmlResponsiveTable extends htmlElement {
/** @var string[] row titles */
private $titles;
/** htmlElement[][] data rows */
private $data;
/** widthes of the columns */
private $widths = [];
/** highlighted rows */
private $highlighted = [];
/** CSS class for odd row numbers */
private $cssOddRow;
/** CSS class for even row numbers */
private $cssEvenRow;
/** onclick code (row number => code) */
private $onClick = [];
/** ondoubleclick code (row number => code) */
private $onDoubleClick = [];
/**
* Creates the table.
*
* @param string[] $titles row titles
* @param htmlElement[][] $data data rows
* @param int[] $highlighted list of row numbers that should be highlighted (starting at 0)
*/
public function __construct($titles, $data, $highlighted = null) {
$this->titles = $titles;
$this->data = $data;
if (!empty($highlighted) && is_array($highlighted)) {
$this->highlighted = $highlighted;
}
}
/**
* {@inheritDoc}
* @see htmlElement::generateHTML()
*/
public function generateHTML($module, $input, $values, $restricted, $scope) {
$return = [];
$classes = $this->cssClasses;
$classes[] = 'responsive-table';
echo '<table class="' . implode(' ', $classes) . '">';
echo '<thead>';
$headClass = empty($this->cssOddRow) ? '' : ' class="' . $this->cssOddRow . '"';
echo '<tr ' . $headClass . '>';
$counter = 0;
foreach ($this->titles as $title) {
$width = '';
if (isset($this->widths[$counter])) {
$width = 'width="' . $this->widths[$counter] . '"';
}
echo '<th ' . $width . '>' . htmlspecialchars($title) . '</th>';
$counter++;
}
echo '</tr>';
echo '</thead>';
echo '<tbody>';
$titleCount = sizeof($this->titles);
$counter = 0;
foreach ($this->data as $row) {
$cssClass = '';
$cssClasses = [];
if (in_array($counter, $this->highlighted)) {
$cssClasses[] = 'highlighted';
}
if (!empty($this->cssEvenRow) && ($counter % 2 === 0)) {
$cssClasses[] = $this->cssEvenRow;
}
if (!empty($this->cssOddRow) && ($counter % 2 === 1)) {
$cssClasses[] = $this->cssOddRow;
}
if (!empty($cssClasses)) {
$cssClass = ' class="' . implode(' ', $cssClasses) . '"';
}
$onClick = '';
if (!empty($this->onClick[$counter])) {
$onClick = ' onclick="' . $this->onClick[$counter] . '"';
}
$onDoubleClick = '';
if (!empty($this->onDoubleClick[$counter])) {
$onDoubleClick = ' ondblclick="' . $this->onDoubleClick[$counter] . '"';
}
echo '<tr ' . $cssClass . $onClick . $onDoubleClick . '>';
for ($i = 0; $i < $titleCount; $i++) {
echo '<td data-label="' . $this->titles[$i] . '">';
$ids = parseHtml($module, $row[$i], $values, $restricted, $scope);
$return = array_merge($return, $ids);
echo '</td>';
}
echo '</tr>';
$counter++;
}
echo '</tbody>';
echo '</table>';
return $return;
}
/**
* Sets the width of each column.
*
* @param string[] $widths widths
*/
public function setWidths($widths) {
$this->widths = $widths;
}
/**
* Sets the CSS classes for odd and even rows.
* The title row counts as row number -1.
*
* @param string $oddClass class for odd rows
* @param string $evenClass class for even rows
*/
public function setRowClasses($oddClass, $evenClass) {
$this->cssOddRow = $oddClass;
$this->cssEvenRow = $evenClass;
}
/**
* Sets the onclick code for the rows.
*
* @param array $calls row number => code
*/
public function setOnClickEvents($calls) {
$this->onClick = $calls;
}
/**
* Sets the ondoubleclick code for the rows.
*
* @param array $calls row number => code
*/
public function setOnDoubleClickEvents($calls) {
$this->onDoubleClick = $calls;
}
}
/**
* Renders a canvas.
*
* @author Roland Gruber
*/
class htmlCanvas extends htmlElement {
private $id;
/**
* Constructor
*
* @param string $id html id
*/
public function __construct($id) {
$this->id = $id;
}
/**
* @inheritDoc
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
$classesValue = '';
if (!empty($this->cssClasses)) {
$classesValue = ' class="' . implode(' ', $this->cssClasses) . '"';
}
echo '<canvas id="' . $this->id . '" ' . $classesValue . '>';
echo '</canvas>';
return [];
}
}
/**
* Renders a video.
*
* @author Roland Gruber
*/
class htmlVideo extends htmlElement {
private $id;
/**
* Constructor
*
* @param string $id html id
*/
public function __construct($id) {
$this->id = $id;
}
/**
* @inheritDoc
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
$classesValue = '';
if (!empty($this->cssClasses)) {
$classesValue = ' class="' . implode(' ', $this->cssClasses) . '"';
}
echo '<video id="' . $this->id . '" ' . $classesValue . '>';
echo '</video>';
return [];
}
}
/**
* Creates a form element for POST.
*
* @package metaHTML
*/
class htmlForm extends htmlElement {
/** form name */
private $name;
/** submit target */
private $action;
/** inner content */
private $content;
/**
* Constructor.
*
* @param string $name name
* @param string $action target URL
*/
function __construct(string $name, string $action, htmlElement $content) {
$this->name = $name;
$this->action = $action;
$this->content = $content;
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
$return = [];
echo '<form name="' . $this->name . '" action="' . $this->action . '" method="post" enctype="multipart/form-data">';
if ($this->content != null) {
$return = $this->content->generateHTML($module, $input, $values, $restricted, $scope);
}
echo '</form>';
return $return;
}
}
/**
* Represents a (un)ordered list.
*/
class htmlList extends htmlElement {
private array $elements = [];
private bool $isOrdered = false;
private ?string $id = '';
/**
* Constructor.
*
* @param htmlElement[] $elements elements to render
* @param string|null $id HTML unique id
* @param bool|null $isOrdered is an ordered list
*/
public function __construct(array $elements, ?string $id = null, ?bool $isOrdered = false) {
$this->elements = $elements;
$this->id = $id;
$this->isOrdered = $isOrdered;
}
/**
* {@inheritDoc}
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
$parentTag = $this->isOrdered ? 'ol' : 'ul';
$idValue = empty($this->id) ? '' : ' id="' . $this->id . '"';
$classesValue = '';
if (!empty($this->cssClasses)) {
$classesValue = ' class="' . implode(' ', $this->cssClasses) . '"';
}
echo '<' . $parentTag . $idValue . $classesValue . '>';
$return = [];
foreach ($this->elements as $element) {
echo '<li>';
$return = array_merge($return, $element->generateHTML($module, $input, $values, $restricted, $scope));
echo '</li>';
}
echo '</' . $parentTag . '>';
return $return;
}
}
/**
* Represents a label.
*/
class htmlLabel extends htmlElement {
private $for;
private $text;
/** mark as required */
private bool $markAsRequired = false;
/**
* Constructor.
*
* @param string $for target element
* @param string $text label text
*/
function __construct(string $for, string $text) {
$this->for = htmlspecialchars($for);
$this->text = htmlspecialchars($text);
}
/**
* {@inheritDoc}
*/
function generateHTML($module, $input, $values, $restricted, $scope): array {
$classesValue = '';
if (!empty($this->cssClasses)) {
$classesValue = ' class="' . implode(' ', $this->cssClasses) . '"';
}
echo '<label for="' . $this->for . '"' . $classesValue . '>';
echo $this->text;
echo '</label>';
if ($this->markAsRequired) {
echo htmlGetRequiredMarker();
}
return [];
}
/**
* Adds a marker that indicates a required field.
*
* @param bool $markAsRequired add marker
*/
public function setMarkAsRequired(bool $markAsRequired = true): void {
$this->markAsRequired = $markAsRequired;
}
}
/**
* Represents a progress bar.
*/
class htmlProgressbar extends htmlElement {
private $id;
private $progress;
/**
* Constructor.
*
* @param string $id HTML id
* @param int $progress initial progress
*/
function __construct(string $id = null, int $progress = 0) {
$this->id = htmlspecialchars($id);
$this->progress = htmlspecialchars($progress);
}
/**
* {@inheritDoc}
*/
function generateHTML($module, $input, $values, $restricted, $scope): array {
$extraClasses = '';
if (!empty($this->cssClasses)) {
$extraClasses = implode(' ', $this->cssClasses);
}
$idValue = '';
if ($this->id !== null) {
$idValue = ' id="' . $this->id . '"';
}
echo '<div ' . $idValue . ' class="lam-progressbar ' . $extraClasses . '">';
echo '<div class="lam-progressbar-bar" style="width: ' . $this->progress . '%">';
echo '</div>';
echo '</div>';
return [];
}
}
|