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
<?php
/**
***********************************************************************************************
* @copyright 2004-2016 The Admidio Team
* @see http://www.admidio.org/
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2.0 only
***********************************************************************************************
*/
// constants for field property
define('FIELD_DEFAULT', 0);
define('FIELD_REQUIRED', 1);
define('FIELD_DISABLED', 2);
define('FIELD_READONLY', 3);
define('FIELD_HIDDEN', 4);
/**
* @class HtmlForm
* @brief Creates an Admidio specific form with special elements
*
* This class inherits the common HtmlFormBasic class and extends their elements
* with custom Admidio form elements. The class should be used to create the
* html part of all Admidio forms. The Admidio elements will contain
* the label of fields and some other specific features like a identification
* of mandatory fields, help buttons and special css classes for every
* element.
* @par Examples
* @code // create a simple form with one input field and a button
* $form = new HtmlForm('simple-form', 'next_page.php');
* $form->openGroupBox('gbSimpleForm', $gL10n->get('SYS_SIMPLE_FORM'));
* $form->addInput('name', $gL10n->get('SYS_NAME'), $formName);
* $form->addSelectBox('type', $gL10n->get('SYS_TYPE'), array('simple' => 'SYS_SIMPLE', 'very-simple' => 'SYS_VERY_SIMPLE'),
* array('defaultValue' => 'simple', 'showContextDependentFirstEntry' => true));
* $form->closeGroupBox();
* $form->addSubmitButton('next-page', $gL10n->get('SYS_NEXT'), array('icon' => 'layout/forward.png'));
* $form->show(); @endcode
*/
class HtmlForm extends HtmlFormBasic
{
protected $flagRequiredFields; ///< Flag if this form has required fields. Then a notice must be written at the end of the form
protected $flagFieldListOpen; ///< Flag if a field list was created. This must be closed later
protected $showRequiredFields; ///< Flag if required fields should get a special css class to make them more visible to the user.
protected $htmlPage; ///< A HtmlPage object that will be used to add javascript code or files to the html output page.
protected $countElements; ///< Number of elements in this form
protected $datepickerInitialized; ///< Flag if datepicker is already initialized
protected $type; ///< Form type. Possible values are @b default, @b vertical or @b navbar.
protected $id; ///< Id of the form
protected $buttonGroupOpen; ///< Flag that indicates if a bootstrap button-group is open and should be closed later
/**
* Constructor creates the form element
* @param string $id Id of the form
* @param string $action Action attribute of the form
* @param \HtmlPage $htmlPage (optional) A HtmlPage object that will be used to add javascript code or files to the html output page.
* @param array $options (optional) An array with the following possible entries:
* - @b type : Set the form type. Every type has some special features:
* + @b default : A form that can be used to edit and save data of a database table. The label
* and the element have a horizontal orientation.
* + @b vertical : A form that can be used to edit and save data but has a vertical orientation.
* The label is positioned above the form element.
* + @b navbar : A form that should be used in a navbar. The form content will
* be send with the 'GET' method and this form should not get a default focus.
* - @b enableFileUpload : Set specific parameters that are necessary for file upload with a form
* - @b showRequiredFields : If this is set to @b true (default) then every required field got a special
* css class and also the form got a @b div that explains the required layout.
* If this is set to @b false then only the html flag @b required will be set.
* - @b setFocus : Default is set to @b true. Set the focus on page load to the first field
* of this form.
* - @b class : An additional css classname. The class @b form-horizontal
* is set as default and need not set with this parameter.
*/
public function __construct($id, $action, HtmlPage $htmlPage = null, array $options = array())
{
// create array with all options
$optionsDefault = array(
'type' => 'default',
'enableFileUpload' => false,
'showRequiredFields' => true,
'setFocus' => true,
'class' => ''
);
$optionsAll = array_replace($optionsDefault, $options);
// navbar forms should send the data as GET
if($optionsAll['type'] === 'navbar')
{
parent::__construct($action, $id, 'get');
}
else
{
parent::__construct($action, $id, 'post');
}
$this->flagRequiredFields = false;
$this->flagFieldListOpen = false;
$this->showRequiredFields = $optionsAll['showRequiredFields'];
$this->countElements = 0;
$this->datepickerInitialized = false;
$this->type = $optionsAll['type'];
$this->id = $id;
$this->buttonGroupOpen = false;
// set specific Admidio css form class
$this->addAttribute('role', 'form');
if($this->type === 'default')
{
$optionsAll['class'] .= ' form-horizontal form-dialog';
}
elseif($this->type === 'vertical')
{
$optionsAll['class'] .= ' admidio-form-vertical form-dialog';
}
elseif($this->type === 'navbar')
{
$optionsAll['class'] .= ' form-horizontal navbar-form navbar-left';
}
if($optionsAll['class'] !== '')
{
$this->addAttribute('class', $optionsAll['class']);
}
// Set specific parameters that are necessary for file upload with a form
if($optionsAll['enableFileUpload'])
{
$this->addAttribute('enctype', 'multipart/form-data');
}
if(is_object($htmlPage))
{
$this->htmlPage =& $htmlPage;
}
// if its not a navbar form and not a static form then first field of form should get focus
if($optionsAll['setFocus'])
{
if(is_object($htmlPage))
{
$this->htmlPage->addJavascript('$(".form-dialog:first *:input:enabled:first").focus();', true);
}
else
{
$this->addHtml('
<script type="text/javascript"><!--
$(function() {
$(".form-dialog:first *:input:enabled:first").focus();
});
//--></script>');
}
}
}
/**
* Add a new button with a custom text to the form. This button could have
* an icon in front of the text.
* @param string $id Id of the button. This will also be the name of the button.
* @param string $text Text of the button
* @param array $options (optional) An array with the following possible entries:
* - @b icon : Optional parameter. Path and filename of an icon.
* If set a icon will be shown in front of the text.
* - @b link : If set a javascript click event with a page load to this link
* will be attached to the button.
* - @b onClickText : A text that will be shown after a click on this button
* until the next page is loaded. The button will be disabled after click.
* - @b class : Optional an additional css classname. The class @b admButton
* is set as default and need not set with this parameter.
* - @b type : Optional a button type could be set. The default is @b button.
*/
public function addButton($id, $text, array $options = array())
{
++$this->countElements;
// create array with all options
$optionsDefault = array('icon' => '', 'link' => '', 'onClickText' => '', 'class' => '', 'type' => 'button', 'data-admidio' => '');
$optionsAll = array_replace($optionsDefault, $options);
// add text and icon to button
$value = $text;
if($optionsAll['icon'] !== '')
{
$value = '<img src="'.$optionsAll['icon'].'" alt="'.$text.'" />'.$value;
}
$this->addElement('button');
$this->addAttribute('class', 'btn btn-default');
if($optionsAll['data-admidio'] !== '')
{
$this->addAttribute('data-admidio', $optionsAll['data-admidio']);
}
if($optionsAll['onClickText'] !== '')
{
$this->addAttribute('data-loading-text', $optionsAll['onClickText']);
$this->addAttribute('autocomplete', 'off');
}
// add javascript for stateful button and/or
// a different link that should be loaded after click
if($optionsAll['onClickText'] !== '' || $optionsAll['link'] !== '')
{
$javascriptCode = '';
if($optionsAll['link'] !== '')
{
$javascriptCode .= '// disable default form submit
self.location.href="'.$optionsAll['link'].'";';
}
if($optionsAll['onClickText'] !== '')
{
$javascriptCode .= '$(this).button("loading");';
}
if($optionsAll['type'] === 'submit')
{
$javascriptCode .= '$(this).submit();';
}
$javascriptCode = '$("#'.$id.'").click(function(event) {
'.$javascriptCode.'
});';
// if a htmlPage object was set then add code to the page, otherwise to the current string
if(is_object($this->htmlPage))
{
$this->htmlPage->addJavascript($javascriptCode, true);
}
else
{
$this->addHtml('
<script type="text/javascript"><!--
$(function() {
'.$javascriptCode.'
});
//--></script>');
}
}
if($optionsAll['class'] !== '')
{
$this->addAttribute('class', $optionsAll['class']);
}
$this->addSimpleButton($id, $optionsAll['type'], $value, $id);
}
/**
* Add a captcha with an input field to the form. The captcha could be a picture with a character code
* or a simple mathematical calculation that must be solved.
* @param string $id Id of the captcha field. This will also be the name of the captcha field.
* @param string $class (optional) An additional css classname. The class @b admTextInput
* is set as default and need not set with this parameter.
*/
public function addCaptcha($id, $class = '')
{
global $gL10n, $g_root_path;
$attributes = array('class' => 'captcha');
++$this->countElements;
// set specific css class for this field
if($class !== '')
{
$attributes['class'] .= ' '.$class;
}
// add a row with the captcha puzzle
$this->openControlStructure('captcha_puzzle', '');
$this->addHtml('<img id="captcha" src="'.$g_root_path.'/adm_program/libs/securimage/securimage_show.php" alt="CAPTCHA Image" />
<a class="admidio-icon-link" href="#" onclick="document.getElementById(\'captcha\').src=\''.$g_root_path.'/adm_program/libs/securimage/securimage_show.php?\' + Math.random(); return false"><img
src="'.THEME_PATH.'/icons/view-refresh.png" alt="'.$gL10n->get('SYS_RELOAD').'" title="'.$gL10n->get('SYS_RELOAD').'" /></a>');
$this->closeControlStructure();
// now add a row with a text field where the user can write the solution for the puzzle
$this->addInput($id, $gL10n->get('SYS_CAPTCHA_CONFIRMATION_CODE'), '', array('property' => FIELD_REQUIRED,
'helpTextIdLabel' => 'SYS_CAPTCHA_DESCRIPTION',
'class' => 'form-control-small'));
}
/**
* Add a new checkbox with a label to the form.
* @param string $id Id of the checkbox. This will also be the name of the checkbox.
* @param string $label The label of the checkbox.
* @param bool $checked A value for the checkbox. The value could only be @b 0 or @b 1. If the value is @b 1 then
* the checkbox will be checked when displayed.
* @param array $options (optional) An array with the following possible entries:
* - @b property : With this param you can set the following properties:
* + @b FIELD_DEFAULT : The field can accept an input.
* + @b FIELD_REQUIRED : The field will be marked as a mandatory field where the user must insert a value.
* + @b FIELD_DISABLED : The field will be disabled and could not accept an input.
* - @b helpTextIdLabel : A unique text id from the translation xml files that should be shown
* e.g. SYS_ENTRY_MULTI_ORGA. If set a help icon will be shown after the control label where
* the user can see the text if he hover over the icon. If you need an additional parameter
* for the text you can add an array. The first entry must be the unique text id and the second
* entry will be a parameter of the text id.
* - @b helpTextIdInline : A unique text id from the translation xml files that should be shown
* e.g. SYS_ENTRY_MULTI_ORGA. If set the complete text will be shown after the form element.
* If you need an additional parameter for the text you can add an array. The first entry must
* be the unique text id and the second entry will be a parameter of the text id.
* - @b icon : An icon can be set. This will be placed in front of the label.
* - @b class : An additional css classname. The class @b admSelectbox
* is set as default and need not set with this parameter.
*/
public function addCheckbox($id, $label, $checked = false, array $options = array())
{
global $gL10n;
$attributes = array('class' => '');
$htmlIcon = '';
$htmlHelpIcon = '';
$cssClasses = 'checkbox';
++$this->countElements;
// create array with all options
$optionsDefault = array(
'property' => FIELD_DEFAULT,
'helpTextIdLabel' => '',
'helpTextIdInline' => '',
'icon' => '',
'class' => ''
);
$optionsAll = array_replace($optionsDefault, $options);
// disable field
if($optionsAll['property'] === FIELD_DISABLED)
{
$attributes['disabled'] = 'disabled';
}
elseif($optionsAll['property'] === FIELD_REQUIRED)
{
$attributes['required'] = 'required';
}
// if checked = true then set checkbox checked
if($checked)
{
$attributes['checked'] = 'checked';
}
// set specific css class for this field
if($optionsAll['class'] !== '')
{
$attributes['class'] .= ' '.$optionsAll['class'];
}
if($optionsAll['icon'] !== '')
{
// create html for icon
if(strpos(admStrToLower($optionsAll['icon']), 'http') === 0 && strValidCharacters($optionsAll['icon'], 'url'))
{
$htmlIcon = '<img class="admidio-icon-info" src="'.$optionsAll['icon'].'" title="'.$label.'" alt="'.$label.'" />';
}
elseif(admStrIsValidFileName($optionsAll['icon'], true))
{
$htmlIcon = '<img class="admidio-icon-info" src="'.THEME_PATH.'/icons/'.$optionsAll['icon'].'" title="'.$label.'" alt="'.$label.'" />';
}
}
if($optionsAll['helpTextIdLabel'] !== '')
{
$htmlHelpIcon = self::getHelpTextIcon($optionsAll['helpTextIdLabel']);
}
// now create html for the field
$this->openControlStructure($id, '');
$this->addHtml('<div class="'.$cssClasses.'"><label>');
$this->addSimpleInput('checkbox', $id, $id, '1', $attributes);
$this->addHtml($htmlIcon.$label.$htmlHelpIcon.'</label></div>');
$this->closeControlStructure($optionsAll['helpTextIdInline']);
}
/**
* Add custom html content to the form within the default field structure.
* The Label will be set but instead of an form control you can define any html.
* If you don't need the field structure and want to add html then use the method addHtml()
* @param string $label The label of the custom content.
* @param string $content A simple Text or html that would be placed instead of an form element.
* @param array $options (optional) An array with the following possible entries:
* - @b referenceId : Optional the id of a form control if this is defined within the custom content
* - @b helpTextIdLabel : A unique text id from the translation xml files that should be shown
* e.g. SYS_ENTRY_MULTI_ORGA. If set a help icon will be shown after the control label where
* the user can see the text if he hover over the icon. If you need an additional parameter
* for the text you can add an array. The first entry must be the unique text id and the second
* entry will be a parameter of the text id.
* - @b helpTextIdInline : A unique text id from the translation xml files that should be shown
* e.g. SYS_ENTRY_MULTI_ORGA. If set the complete text will be shown after the form element.
* If you need an additional parameter for the text you can add an array. The first entry must
* be the unique text id and the second entry will be a parameter of the text id.
* - @b icon : An icon can be set. This will be placed in front of the label.
* - @b class : An additional css classname. The class @b admSelectbox
* is set as default and need not set with this parameter.
*/
public function addCustomContent($label, $content, array $options = array())
{
++$this->countElements;
// create array with all options
$optionsDefault = array(
'referenceId' => '',
'helpTextIdLabel' => '',
'helpTextIdInline' => '',
'icon' => '',
'class' => ''
);
$optionsAll = array_replace($optionsDefault, $options);
// set specific css class for this field
// if($optionsAll['class'] !== '')
// {
// $attributes['class'] .= ' '.$optionsAll['class'];
// }
$this->openControlStructure($optionsAll['referenceId'], $label, FIELD_DEFAULT,
$optionsAll['helpTextIdLabel'], $optionsAll['icon'], 'form-custom-content');
$this->addHtml($content);
$this->closeControlStructure($optionsAll['helpTextIdInline']);
}
/**
* Add a line with a custom description to the form. No form elements will be displayed in this line.
* @param string $text The (html) text that should be displayed.
*/
public function addDescription($text)
{
$this->addHtml('<p>'.$text.'</p>');
}
/**
* Add a new CKEditor element to the form.
* @param string $id Id of the password field. This will also be the name of the password field.
* @param string $label The label of the password field.
* @param string $value A value for the editor field. The editor will contain this value when created.
* @param array $options (optional) An array with the following possible entries:
* - @b property : With this param you can set the following properties:
* + @b FIELD_DEFAULT : The field can accept an input.
* + @b FIELD_REQUIRED : The field will be marked as a mandatory field where the user must insert a value.
* - @b toolbar : Optional set a predefined toolbar for the editor. Possible values are
* @b AdmidioDefault, @b AdmidioGuestbook and @b AdmidioPlugin_WC
* - @b height : Optional set the height in pixel of the editor. The default will be 300px.
* - @b labelVertical : If set to @b true (default) then the label will be display above the control and the control get a width of 100%.
* Otherwise the label will be displayed in front of the control.
* - @b helpTextIdLabel : A unique text id from the translation xml files that should be shown
* e.g. SYS_ENTRY_MULTI_ORGA. If set a help icon will be shown after the control label where
* the user can see the text if he hover over the icon. If you need an additional parameter
* for the text you can add an array. The first entry must be the unique text id and the second
* entry will be a parameter of the text id.
* - @b helpTextIdInline : A unique text id from the translation xml files that should be shown
* e.g. SYS_ENTRY_MULTI_ORGA. If set the complete text will be shown after the form element.
* If you need an additional parameter for the text you can add an array. The first entry must
* be the unique text id and the second entry will be a parameter of the text id.
* - @b icon : An icon can be set. This will be placed in front of the label.
* - @b class : An additional css classname. The class @b admSelectbox
* is set as default and need not set with this parameter.
*/
public function addEditor($id, $label, $value, array $options = array())
{
global $gPreferences, $g_root_path, $gL10n;
++$this->countElements;
$attributes = array('class' => 'editor');
$flagLabelVertical = $this->type;
// create array with all options
$optionsDefault = array(
'property' => FIELD_DEFAULT,
'toolbar' => 'AdmidioDefault',
'height' => '300px',
'helpTextIdLabel' => '',
'helpTextIdInline' => '',
'labelVertical' => true,
'icon' => '',
'class' => ''
);
$optionsAll = array_replace($optionsDefault, $options);
if($optionsAll['labelVertical'])
{
$this->type = 'vertical';
}
if ($optionsAll['property'] === FIELD_REQUIRED)
{
$attributes['required'] = 'required';
}
// set specific css class for this field
if($optionsAll['class'] !== '')
{
$attributes['class'] .= ' '.$optionsAll['class'];
}
$javascriptCode = '
CKEDITOR.replace("'.$id.'", {
toolbar: "'.$optionsAll['toolbar'].'",
language: "'.$gL10n->getLanguageIsoCode().'",
uiColor: "'.$gPreferences['system_js_editor_color'].'",
filebrowserImageUploadUrl: "'.$g_root_path.'/adm_program/system/ckeditor_upload_handler.php"
});';
if($gPreferences['system_js_editor_enabled'] == 1)
{
// if a htmlPage object was set then add code to the page, otherwise to the current string
if(is_object($this->htmlPage))
{
$this->htmlPage->addJavascriptFile('adm_program/libs/ckeditor/ckeditor.js');
$this->htmlPage->addJavascript($javascriptCode, true);
}
else
{
$this->addHtml('
<script type="text/javascript">
$(function() {
'.$javascriptCode.'
});
</script>');
}
}
$this->openControlStructure($id, $label, $optionsAll['property'], $optionsAll['helpTextIdLabel'],
$optionsAll['icon'], 'form-group-editor');
$this->addHtml('
<div class="'.$attributes['class'].'">
<textarea id="'.$id.'" name="'.$id.'"style="width: 100%; height: '.$optionsAll['height'].';">'.$value.'</textarea>
</div>');
$this->closeControlStructure($optionsAll['helpTextIdInline']);
$this->type = $flagLabelVertical;
}
/**
* Add a field for file upload. If necessary multiple files could be uploaded.
* The fields for multiple upload could be added dynamically to the form by the user.
* @param string $id Id of the input field. This will also be the name of the input field.
* @param string $label The label of the input field.
* @param array $options (optional) An array with the following possible entries:
* - @b property : With this param you can set the following properties:
* + @b FIELD_DEFAULT : The field can accept an input.
* + @b FIELD_REQUIRED : The field will be marked as a mandatory field where the user must insert a value.
* + @b FIELD_DISABLED : The field will be disabled and could not accept an input.
* - @b allowedMimeTypes : An array with the allowed MIME types (https://wiki.selfhtml.org/wiki/Referenz:MIME-Typen).
* If this is set then the user can only choose the specified files with the browser file dialog.
* You should check the uploaded file against the MIME type because the file could be manipulated.
* - @b maxUploadSize : The size in byte that could be maximum uploaded.
* The default will be $gPreferences['max_file_upload_size'] * 1024 * 1024.
* - @b enableMultiUploads : If set to true a button will be added where the user can
* add new upload fields to upload more than one file.
* - @b multiUploadLabel : The label for the button who will add new upload fields to the form.
* - @b hideUploadField : Hide the upload field if multi uploads are enabled. Then the first
* upload field will be shown if the user will click the multi upload button.
* - @b helpTextIdLabel : A unique text id from the translation xml files that should be shown
* e.g. SYS_ENTRY_MULTI_ORGA. If set a help icon will be shown after the control label where
* the user can see the text if he hover over the icon. If you need an additional parameter
* for the text you can add an array. The first entry must be the unique text id and the second
* entry will be a parameter of the text id.
* - @b helpTextIdInline : A unique text id from the translation xml files that should be shown
* e.g. SYS_ENTRY_MULTI_ORGA. If set the complete text will be shown after the form element.
* If you need an additional parameter for the text you can add an array. The first entry must
* be the unique text id and the second entry will be a parameter of the text id.
* - @b icon : An icon can be set. This will be placed in front of the label.
* - @b class : An additional css classname. The class @b admSelectbox
* is set as default and need not set with this parameter.
*/
public function addFileUpload($id, $label, array $options = array())
{
global $gPreferences;
$attributes = array('class' => 'form-control');
++$this->countElements;
// create array with all options
$optionsDefault = array(
'property' => FIELD_DEFAULT,
'maxUploadSize' => $gPreferences['max_file_upload_size'] * 1024 * 1024,
'allowedMimeTypes' => array(),
'enableMultiUploads' => false,
'hideUploadField' => false,
'multiUploadLabel' => '',
'helpTextIdLabel' => '',
'helpTextIdInline' => '',
'icon' => '',
'class' => ''
);
$optionsAll = array_replace($optionsDefault, $options);
// disable field
if($optionsAll['property'] === FIELD_DISABLED)
{
$attributes['disabled'] = 'disabled';
}
elseif($optionsAll['property'] === FIELD_REQUIRED)
{
$attributes['required'] = 'required';
}
if(count($optionsAll['allowedMimeTypes']) > 0)
{
$attributes['accept'] = implode(',', $optionsAll['allowedMimeTypes']);
}
// set specific css class for this field
if($optionsAll['class'] !== '')
{
$attributes['class'] .= ' '.$optionsAll['class'];
}
// if multiple uploads are enabled then add javascript that will
// dynamically add new upload fields to the form
if($optionsAll['enableMultiUploads'])
{
$javascriptCode = '
// add new line to add new attachment to this mail
$("#btn_add_attachment_'.$id.'").click(function () {
newAttachment = document.createElement("input");
$(newAttachment).attr("type", "file");
$(newAttachment).attr("name", "userfile[]");
$(newAttachment).attr("class", "'.$attributes['class'].'");
$(newAttachment).hide();
$("#btn_add_attachment_'.$id.'").before(newAttachment);
$(newAttachment).show("slow");
});';
// if a htmlPage object was set then add code to the page, otherwise to the current string
if(is_object($this->htmlPage))
{
$this->htmlPage->addJavascript($javascriptCode, true);
}
else
{
$this->addHtml('
<script type="text/javascript"><!--
$(function() {
'.$javascriptCode.'
});
//--></script>');
}
}
$this->openControlStructure($id, $label, $optionsAll['property'], $optionsAll['helpTextIdLabel'],
$optionsAll['icon'], 'form-upload');
$this->addSimpleInput('hidden', 'MAX_FILE_SIZE', 'MAX_FILE_SIZE', $optionsAll['maxUploadSize']);
// if multi uploads are enabled then the file upload field could be hidden
// until the user will click on the button to add a new upload field
if(!$optionsAll['hideUploadField'] || !$optionsAll['enableMultiUploads'])
{
$this->addSimpleInput('file', 'userfile[]', null, '', $attributes);
}
if($optionsAll['enableMultiUploads'])
{
// show button to add new upload field to form
$this->addHtml('
<button type="button" id="btn_add_attachment_'.$id.'" class="btn btn-default">
<img src="'.THEME_PATH.'/icons/add.png" alt="'.$optionsAll['multiUploadLabel'].'" />'
.$optionsAll['multiUploadLabel'].
'</button>');
}
$this->closeControlStructure($optionsAll['helpTextIdInline']);
}
/**
* Add a new input field with a label to the form.
* @param string $id Id of the input field. This will also be the name of the input field.
* @param string $label The label of the input field.
* @param string $value A value for the text field. The field will be created with this value.
* @param array $options (optional) An array with the following possible entries:
* - @b type : Set the type if the field. Default will be @b text. Possible values are @b text,
* @b number, @b date, @b datetime or @b birthday. If @b date, @b datetime or @b birthday are set
* than a small calendar will be shown if the date field will be selected.
* - @b maxLength : The maximum number of characters that are allowed in a text field.
* - @b minNumber : The minimum number that is allowed in a number field.
* - @b maxNumber : The maximum number that is allowed in a number field.
* - @b step : The steps between two numbers that are allowed.
* E.g. if steps is set to 5 then only values 5, 10, 15 ... are allowed
* - @b property : With this param you can set the following properties:
* + @b FIELD_DEFAULT : The field can accept an input.
* + @b FIELD_REQUIRED : The field will be marked as a mandatory field where the user must insert a value.
* + @b FIELD_DISABLED : The field will be disabled and could not accept an input.
* + @b FIELD_HIDDEN : The field will not be shown. Useful to transport additional informations.
* - @b helpTextIdLabel : A unique text id from the translation xml files that should be shown
* e.g. SYS_ENTRY_MULTI_ORGA. If set a help icon will be shown after the control label where
* the user can see the text if he hover over the icon. If you need an additional parameter
* for the text you can add an array. The first entry must be the unique text id and the second
* entry will be a parameter of the text id.
* - @b helpTextIdInline : A unique text id from the translation xml files that should be shown
* e.g. SYS_ENTRY_MULTI_ORGA. If set the complete text will be shown after the form element.
* If you need an additional parameter for the text you can add an array. The first entry must
* be the unique text id and the second entry will be a parameter of the text id.
* - @b icon : An icon can be set. This will be placed in front of the label.
* - @b class : An additional css classname. The class @b admSelectbox
* is set as default and need not set with this parameter.
* - @b htmlAfter : Add html code after the input field.
*/
public function addInput($id, $label, $value, array $options = array())
{
global $gL10n, $gPreferences;
$attributes = array('class' => 'form-control');
++$this->countElements;
// create array with all options
$optionsDefault = array(
'type' => 'text',
'minLength' => null,
'maxLength' => 0,
'minNumber' => null,
'maxNumber' => null,
'step' => 1,
'property' => FIELD_DEFAULT,
'helpTextIdLabel' => '',
'helpTextIdInline' => '',
'icon' => '',
'class' => '',
'htmlAfter' => ''
);
$optionsAll = array_replace($optionsDefault, $options);
// set min/max input length
if($optionsAll['type'] === 'text' || $optionsAll['type'] === 'password' || $optionsAll['type'] === 'search' ||
$optionsAll['type'] === 'email' || $optionsAll['type'] === 'url' || $optionsAll['type'] === 'tel')
{
$attributes['minlength'] = $optionsAll['minLength'];
if($optionsAll['maxLength'] > 0)
{
$attributes['maxlength'] = $optionsAll['maxLength'];
}
}
elseif($optionsAll['type'] === 'number')
{
$attributes['min'] = $optionsAll['minNumber'];
$attributes['max'] = $optionsAll['maxNumber'];
$attributes['step'] = $optionsAll['step'];
}
// disable field
switch($optionsAll['property'])
{
case FIELD_DISABLED:
$attributes['disabled'] = 'disabled';
break;
case FIELD_READONLY:
$attributes['readonly'] = 'readonly';
break;
case FIELD_REQUIRED:
$attributes['required'] = 'required';
break;
case FIELD_HIDDEN:
$attributes['hidden'] = 'hidden';
$attributes['class'] .= ' hide';
break;
}
// set specific css class for this field
if($optionsAll['class'] !== '')
{
$attributes['class'] .= ' '.$optionsAll['class'];
}
// add a nice modern datepicker to date inputs
if($optionsAll['type'] === 'date' || $optionsAll['type'] === 'datetime' || $optionsAll['type'] === 'birthday')
{
$attributes['placeholder'] = DateTimeExtended::getDateFormatForDatepicker($gPreferences['system_date']);
$javascriptCode = '';
// if you have a birthday field than start with the years selection
if($optionsAll['type'] === 'birthday')
{
$attributes['data-provide'] = 'datepicker-birthday';
$datepickerOptions = ' startView: 2, ';
}
else
{
$attributes['data-provide'] = 'datepicker';
$datepickerOptions = ' todayBtn: "linked", ';
}
if(!$this->datepickerInitialized || $optionsAll['type'] === 'birthday')
{
$javascriptCode = '
$("input[data-provide=\''.$attributes['data-provide'].'\']").datepicker({
language: "'.$gL10n->getLanguageIsoCode().'",
format: "'.DateTimeExtended::getDateFormatForDatepicker($gPreferences['system_date']).'",
'.$datepickerOptions.'
todayHighlight: "true"
});';
if($optionsAll['type'] !== 'birthday')
{
$this->datepickerInitialized = true;
}
}
// if a htmlPage object was set then add code to the page, otherwise to the current string
if(is_object($this->htmlPage))
{
$this->htmlPage->addCssFile('adm_program/libs/bootstrap-datepicker/css/bootstrap-datepicker3.css');
$this->htmlPage->addJavascriptFile('adm_program/libs/bootstrap-datepicker/js/bootstrap-datepicker.js');
$this->htmlPage->addJavascriptFile('adm_program/libs/bootstrap-datepicker/locales/bootstrap-datepicker.'.$gL10n->getLanguageIsoCode().'.min.js');
$this->htmlPage->addJavascript($javascriptCode, true);
}
else
{
$this->addHtml('<script type="text/javascript">'.$javascriptCode.'</script>');
}
}
if($optionsAll['property'] !== FIELD_HIDDEN)
{
// now create html for the field
$this->openControlStructure($id, $label, $optionsAll['property'], $optionsAll['helpTextIdLabel'], $optionsAll['icon']);
}
// if datetime then add a time field behind the date field
if($optionsAll['type'] === 'datetime')
{
// first try to split datetime to a date and a time value
$datetime = DateTime::createFromFormat($gPreferences['system_date'].' '.$gPreferences['system_time'], $value);
$dateValue = $datetime->format($gPreferences['system_date']);
$timeValue = $datetime->format($gPreferences['system_time']);
// now add a date and a time field to the form
$attributes['class'] .= ' datetime-date-control';
$this->addSimpleInput('text', $id, $id, $dateValue, $attributes);
$attributes['class'] .= ' datetime-time-control';
$attributes['maxlength'] = '8';
$attributes['data-provide'] = '';
$this->addSimpleInput('text', $id.'_time', $id.'_time', $timeValue, $attributes);
}
else
{
// a date type has some problems with chrome so we set it as text type
if($optionsAll['type'] === 'date' || $optionsAll['type'] === 'birthday')
{
$optionsAll['type'] = 'text';
}
$this->addSimpleInput($optionsAll['type'], $id, $id, $value, $attributes);
}
if($optionsAll['htmlAfter'] !== '')
{
$this->addHtml($optionsAll['htmlAfter']);
}
if($optionsAll['property'] !== FIELD_HIDDEN)
{
$this->closeControlStructure($optionsAll['helpTextIdInline']);
}
}
/**
* Add a simple line to the form. This could be used to structure a form. The line has only a visual effect.
*/
public function addLine()
{
$this->addHtml('<hr />');
}
/**
* Add a new textarea field with a label to the form.
* @param string $id Id of the input field. This will also be the name of the input field.
* @param string $label The label of the input field.
* @param string $value A value for the text field. The field will be created with this value.
* @param int $rows The number of rows that the textarea field should have.
* @param array $options (optional) An array with the following possible entries:
* - @b maxLength : The maximum number of characters that are allowed in this field. If set
* then show a counter how many characters still available
* - @b property : With this param you can set the following properties:
* + @b FIELD_DEFAULT : The field can accept an input.
* + @b FIELD_REQUIRED : The field will be marked as a mandatory field where the user must insert a value.
* + @b FIELD_DISABLED : The field will be disabled and could not accept an input.
* - @b helpTextIdLabel : A unique text id from the translation xml files that should be shown
* e.g. SYS_ENTRY_MULTI_ORGA. If set a help icon will be shown after the control label where
* the user can see the text if he hover over the icon. If you need an additional parameter
* for the text you can add an array. The first entry must be the unique text id and the second
* entry will be a parameter of the text id.
* - @b helpTextIdInline : A unique text id from the translation xml files that should be shown
* e.g. SYS_ENTRY_MULTI_ORGA. If set the complete text will be shown after the form element.
* If you need an additional parameter for the text you can add an array. The first entry must
* be the unique text id and the second entry will be a parameter of the text id.
* - @b icon : An icon can be set. This will be placed in front of the label.
* - @b class : An additional css classname. The class @b admSelectbox
* is set as default and need not set with this parameter.
*/
public function addMultilineTextInput($id, $label, $value, $rows, array $options = array())
{
global $gL10n;
$attributes = array('class' => 'form-control');
++$this->countElements;
// create array with all options
$optionsDefault = array(
'property' => FIELD_DEFAULT,
'maxLength' => 0,
'helpTextIdLabel' => '',
'helpTextIdInline' => '',
'icon' => '',
'class' => ''
);
$optionsAll = array_replace($optionsDefault, $options);
// disable field
if($optionsAll['property'] === FIELD_DISABLED)
{
$attributes['disabled'] = 'disabled';
}
elseif($optionsAll['property'] === FIELD_REQUIRED)
{
$attributes['required'] = 'required';
}
// set specific css class for this field
if($optionsAll['class'] !== '')
{
$attributes['class'] .= ' '.$optionsAll['class'];
}
if($optionsAll['maxLength'] > 0)
{
$attributes['maxlength'] = $optionsAll['maxLength'];
// if max field length is set then show a counter how many characters still available
$javascriptCode = '
$(\'#'.$id.'\').NobleCount(\'#'.$id.'_counter\',{
max_chars: '.$optionsAll['maxLength'].',
on_negative: \'systeminfoBad\',
block_negative: true
});';
// if a htmlPage object was set then add code to the page, otherwise to the current string
if(is_object($this->htmlPage))
{
$this->htmlPage->addJavascriptFile('adm_program/libs/noblecount/jquery.noblecount.js');
$this->htmlPage->addJavascript($javascriptCode, true);
}
else
{
$this->addHtml('
<script type="text/javascript">
$(function() {
'.$javascriptCode.'
});
</script>');
}
}
$this->openControlStructure($id, $label, $optionsAll['property'], $optionsAll['helpTextIdLabel'], $optionsAll['icon']);
$this->addTextArea($id, $rows, 80, $value, $id, $attributes);
if($optionsAll['maxLength'] > 0)
{
// if max field length is set then show a counter how many characters still available
$this->addHtml('
<small class="characters-count">('
.$gL10n->get('SYS_STILL_X_CHARACTERS', '<span id="'.$id.'_counter" class="">255</span>').
')</small>');
}
$this->closeControlStructure($optionsAll['helpTextIdInline']);
}
/**
* Add a new radio button with a label to the form. The radio button could have different status
* which could be defined with an array.
* @param string $id Id of the radio button. This will also be the name of the radio button.
* @param string $label The label of the radio button.
* @param array $values Array with all entries of the radio button;
* Array key will be the internal value of the entry
* Array value will be the visual value of the entry
* @param array $options (optional) An array with the following possible entries:
* - @b property : With this param you can set the following properties:
* + @b FIELD_DEFAULT : The field can accept an input.
* + @b FIELD_REQUIRED : The field will be marked as a mandatory field where the user must insert a value.
* + @b FIELD_DISABLED : The field will be disabled and could not accept an input.
* - @b defaultValue : This is the value of that radio button that is preselected.
* - @b showNoValueButton : If set to true than one radio with no value will be set in front of the other array.
* This could be used if the user should also be able to set no radio to value.
* - @b helpTextIdLabel : A unique text id from the translation xml files that should be shown
* e.g. SYS_ENTRY_MULTI_ORGA. If set a help icon will be shown after the control label where
* the user can see the text if he hover over the icon. If you need an additional parameter
* for the text you can add an array. The first entry must be the unique text id and the second
* entry will be a parameter of the text id.
* - @b helpTextIdInline : A unique text id from the translation xml files that should be shown
* e.g. SYS_ENTRY_MULTI_ORGA. If set the complete text will be shown after the form element.
* If you need an additional parameter for the text you can add an array. The first entry must
* be the unique text id and the second entry will be a parameter of the text id.
* - @b icon : An icon can be set. This will be placed in front of the label.
* - @b class : An additional css classname. The class @b admSelectbox
* is set as default and need not set with this parameter.
*/
public function addRadioButton($id, $label, array $values, array $options = array())
{
$attributes = array('class' => '');
++$this->countElements;
// create array with all options
$optionsDefault = array(
'property' => FIELD_DEFAULT,
'defaultValue' => '',
'showNoValueButton' => false,
'helpTextIdLabel' => '',
'helpTextIdInline' => '',
'icon' => '',
'class' => ''
);
$optionsAll = array_replace($optionsDefault, $options);
// disable field
if($optionsAll['property'] === FIELD_DISABLED)
{
$attributes['disabled'] = 'disabled';
}
elseif($optionsAll['property'] === FIELD_REQUIRED)
{
$attributes['required'] = 'required';
}
// set specific css class for this field
if($optionsAll['class'] !== '')
{
$attributes['class'] .= ' '.$optionsAll['class'];
}
$this->openControlStructure('', $label, $optionsAll['property'], $optionsAll['helpTextIdLabel'], $optionsAll['icon']);
// set one radio button with no value will be set in front of the other array.
if($optionsAll['showNoValueButton'])
{
if($optionsAll['defaultValue'] === '')
{
$attributes['checked'] = 'checked';
}
$this->addHtml('<label for="'.($id.'_0').'" class="radio-inline">');
$this->addSimpleInput('radio', $id, $id.'_0', '', $attributes);
$this->addHtml('---</label>');
}
// for each entry of the array create an input radio field
foreach($values as $key => $value)
{
unset($attributes['checked']);
if($optionsAll['defaultValue'] == $key)
{
$attributes['checked'] = 'checked';
}
$this->addHtml('<label for="'.($id.'_'.$key).'" class="radio-inline">');
$this->addSimpleInput('radio', $id, $id.'_'.$key, $key, $attributes);
$this->addHtml($value.'</label>');
}
$this->closeControlStructure($optionsAll['helpTextIdInline']);
}
/**
* Add a new selectbox with a label to the form. The selectbox
* could have different values and a default value could be set.
* @param string $id Id of the selectbox. This will also be the name of the selectbox.
* @param string $label The label of the selectbox.
* @param array $values Array with all entries of the select box;
* Array key will be the internal value of the entry
* Array value will be the visual value of the entry
* @param array $options (optional) An array with the following possible entries:
* - @b property : With this param you can set the following properties:
* + @b FIELD_DEFAULT : The field can accept an input.
* + @b FIELD_REQUIRED : The field will be marked as a mandatory field where the user must insert a value.
* + @b FIELD_DISABLED : The field will be disabled and could not accept an input.
* - @b defaultValue : This is the value the selectbox shows when loaded. If @b multiselect is activated than
* an array with all default values could be set.
* - @b showContextDependentFirstEntry : If set to @b true the select box will get an additional first entry.
* If FIELD_REQUIRED is set than "Please choose" will be the first entry otherwise
* an empty entry will be added so you must not select something.
* - @b firstEntry : Here you can define a string that should be shown as firstEntry and will be the
* default value if no other value is set. This entry will only be added if @b showContextDependentFirstEntry
* is set to false!
* - @b multiselect : If set to @b true than the jQuery plugin Select2 will be used to create a selectbox
* where the user could select multiple values from the selectbox. Then an array will be
* created within the $_POST array.
* - @b maximumSelectionNumber : If @b multiselect is enabled then you can configure the maximum number
* of selections that could be done. If this limit is reached the user can't add another entry to the selectbox.
* - @b helpTextIdLabel : A unique text id from the translation xml files that should be shown
* e.g. SYS_ENTRY_MULTI_ORGA. If set a help icon will be shown after the control label where
* the user can see the text if he hover over the icon. If you need an additional parameter
* for the text you can add an array. The first entry must be the unique text id and the second
* entry will be a parameter of the text id.
* - @b helpTextIdInline : A unique text id from the translation xml files that should be shown
* e.g. SYS_ENTRY_MULTI_ORGA. If set the complete text will be shown after the form element.
* If you need an additional parameter for the text you can add an array. The first entry must
* be the unique text id and the second entry will be a parameter of the text id.
* - @b icon : An icon can be set. This will be placed in front of the label.
* - @b class : An additional css classname. The class @b admSelectbox
* is set as default and need not set with this parameter.
*/
public function addSelectBox($id, $label, array $values, array $options = array())
{
global $gL10n, $gPreferences;
$attributes = array('class' => 'form-control');
$name = $id;
if(count($values) > 0)
{
++$this->countElements;
}
// create array with all options
$optionsDefault = array(
'property' => FIELD_DEFAULT,
'defaultValue' => '',
'showContextDependentFirstEntry' => true,
'firstEntry' => '',
'multiselect' => false,
'maximumSelectionNumber' => 0,
'helpTextIdLabel' => '',
'helpTextIdInline' => '',
'icon' => '',
'class' => ''
);
$optionsAll = array_replace($optionsDefault, $options);
// disable field
if($optionsAll['property'] === FIELD_DISABLED)
{
$attributes['disabled'] = 'disabled';
}
// multiselect couldn't handle the required property
elseif($optionsAll['property'] === FIELD_REQUIRED && !$optionsAll['multiselect'])
{
$attributes['required'] = 'required';
}
$placeholder = '';
if($optionsAll['multiselect'])
{
$attributes['multiple'] = 'multiple';
$name = $id.'[]';
if($optionsAll['defaultValue'] !== '' && !is_array($optionsAll['defaultValue']))
{
$optionsAll['defaultValue'] = array($optionsAll['defaultValue']);
}
if($optionsAll['showContextDependentFirstEntry'] && $optionsAll['property'] === FIELD_REQUIRED)
{
$placeholder = $gL10n->get('SYS_SELECT_FROM_LIST');
// reset the preferences so the logic for not multiselect will not be performed
$optionsAll['showContextDependentFirstEntry'] = false;
}
}
// set specific css class for this field
if($optionsAll['class'] !== '')
{
$attributes['class'] .= ' '.$optionsAll['class'];
}
// now create html for the field
$this->openControlStructure($id, $label, $optionsAll['property'], $optionsAll['helpTextIdLabel'], $optionsAll['icon']);
$this->addSelect($name, $id, $attributes);
// add an additional first entry to the select box and set this as preselected if necessary
if($optionsAll['showContextDependentFirstEntry'] || $optionsAll['firstEntry'] !== '')
{
$defaultEntry = false;
if($optionsAll['defaultValue'] === '')
{
$defaultEntry = true;
}
if($optionsAll['firstEntry'] !== '')
{
$this->addOption('', '- '.$optionsAll['firstEntry'].' -', null, $defaultEntry);
}
elseif($optionsAll['showContextDependentFirstEntry'])
{
if($optionsAll['property'] === FIELD_REQUIRED)
{
$this->addOption('', '- '.$gL10n->get('SYS_PLEASE_CHOOSE').' -', null, $defaultEntry);
}
else
{
$this->addOption('', ' ', null, $defaultEntry);
}
}
}
$value = reset($values);
$arrayMax = count($values);
$optionGroup = null;
for($arrayCount = 0; $arrayCount < $arrayMax; ++$arrayCount)
{
// create entry in html
$defaultEntry = false;
// if each array element is an array then create option groups
if(is_array($value))
{
// add optiongroup if necessary
if($optionGroup !== $values[$arrayCount][2])
{
if($optionGroup !== null)
{
$this->closeOptionGroup();
}
$this->addOptionGroup($values[$arrayCount][2]);
$optionGroup = $values[$arrayCount][2];
}
// add option
if(!$optionsAll['multiselect'] && $optionsAll['defaultValue'] == $values[$arrayCount][0])
{
$defaultEntry = true;
}
$this->addOption($values[$arrayCount][0], $values[$arrayCount][1], null, $defaultEntry);
}
else
{
// array has only key and value then create a normal selectbox without optiongroups
if(!$optionsAll['multiselect'] && $optionsAll['defaultValue'] == key($values))
{
$defaultEntry = true;
}
$this->addOption(key($values), $value, null, $defaultEntry);
}
$value = next($values);
}
if($optionGroup !== null)
{
$this->closeOptionGroup();
}
if($optionsAll['multiselect'])
{
$maximumSelectionNumber = '';
if($optionsAll['maximumSelectionNumber'] > 0)
{
$maximumSelectionNumber = ' maximumSelectionLength: '.$optionsAll['maximumSelectionNumber'].', ';
}
$javascriptCode = '$("#'.$id.'").select2({
theme: "bootstrap",
allowClear: true,
'.$maximumSelectionNumber.'
placeholder: "'.$placeholder.'",
language: "'.$gPreferences['system_language'].'"
});';
// add default values to multi select
if(is_array($optionsAll['defaultValue']) && count($optionsAll['defaultValue']) > 0)
{
$htmlDefaultValues = '';
foreach($optionsAll['defaultValue'] as $key => $htmlDefaultValue)
{
$htmlDefaultValues .= '"'.$htmlDefaultValue.'",';
}
$htmlDefaultValues = substr($htmlDefaultValues, 0, -1);
$javascriptCode .= ' $("#'.$id.'").val(['.$htmlDefaultValues.']).trigger("change");';
}
// if a htmlPage object was set then add code to the page, otherwise to the current string
if(is_object($this->htmlPage))
{
$this->htmlPage->addCssFile('adm_program/libs/select2/dist/css/select2.css');
$this->htmlPage->addCssFile('adm_program/libs/select2-bootstrap-theme/dist/select2-bootstrap.css');
$this->htmlPage->addJavascriptFile('adm_program/libs/select2/dist/js/select2.js');
$this->htmlPage->addJavascriptFile('adm_program/libs/select2/dist/js/i18n/'.$gL10n->getLanguageIsoCode().'.js');
$this->htmlPage->addJavascript($javascriptCode, true);
}
else
{
$this->addHtml('<script type="text/javascript">'.$javascriptCode.'</script>');
}
}
$this->closeSelect();
$this->closeControlStructure($optionsAll['helpTextIdInline']);
}
/**
* Add a new selectbox with a label to the form. The selectbox get their data from a sql statement.
* You can create any sql statement and this method should create a selectbox with the found data.
* The sql must contain at least two columns. The first column represents the value and the second
* column represents the label of each option of the selectbox. Optional you can add a third column
* to the sql statement. This column will be used as label for an optiongroup. Each time the value
* of the third column changed a new optiongroup will be created.
* @param string $id Id of the selectbox. This will also be the name of the selectbox.
* @param string $label The label of the selectbox.
* @param \Database $database Object of the class Database. This should be the default global object @b $gDb.
* @param string $sql Any SQL statement that return 2 columns. The first column will be the internal value of the
* selectbox item and will be submitted with the form. The second column represents the
* displayed value of the item. Each row of the result will be a new selectbox entry.
* @param array $options (optional) An array with the following possible entries:
* - @b property : With this param you can set the following properties:
* + @b FIELD_DEFAULT : The field can accept an input.
* + @b FIELD_REQUIRED : The field will be marked as a mandatory field where the user must insert a value.
* + @b FIELD_DISABLED : The field will be disabled and could not accept an input.
* - @b defaultValue : This is the value the selectbox shows when loaded. If @b multiselect is activated than
* an array with all default values could be set.
* - @b showContextDependentFirstEntry : If set to @b true the select box will get an additional first entry.
* If FIELD_REQUIRED is set than "Please choose" will be the first entry otherwise
* an empty entry will be added so you must not select something.
* - @b firstEntry : Here you can define a string that should be shown as firstEntry and will be the
* default value if no other value is set. This entry will only be added if @b showContextDependentFirstEntry
* is set to false!
* - @b multiselect : If set to @b true than the jQuery plugin Select2 will be used to create a selectbox
* where the user could select multiple values from the selectbox. Then an array will be
* created within the $_POST array.
* - @b maximumSelectionNumber : If @b multiselect is enabled then you can configure the maximum number
* of selections that could be done. If this limit is reached the user can't add another entry to the selectbox.
* - @b helpTextIdLabel : A unique text id from the translation xml files that should be shown
* e.g. SYS_ENTRY_MULTI_ORGA. If set a help icon will be shown after the control label where
* the user can see the text if he hover over the icon. If you need an additional parameter
* for the text you can add an array. The first entry must be the unique text id and the second
* entry will be a parameter of the text id.
* - @b helpTextIdInline : A unique text id from the translation xml files that should be shown
* e.g. SYS_ENTRY_MULTI_ORGA. If set the complete text will be shown after the form element.
* If you need an additional parameter for the text you can add an array. The first entry must
* be the unique text id and the second entry will be a parameter of the text id.
* - @b icon : An icon can be set. This will be placed in front of the label.
* - @b class : An additional css classname. The class @b admSelectbox
* is set as default and need not set with this parameter.
*
* @par Examples
* @code // create a selectbox with all profile fields of a specific category
* $sql = 'SELECT usf_id, usf_name FROM '.TBL_USER_FIELDS.' WHERE usf_cat_id = 4711'
* $form = new HtmlForm('simple-form', 'next_page.php');
* $form->addSelectBoxFromSql('admProfileFieldsBox', $gL10n->get('SYS_FIELDS'), $gDb, $sql, array('defaultValue' => $gL10n->get('SYS_SURNAME'), 'showContextDependentFirstEntry' => true));
* $form->show(); @endcode
*/
public function addSelectBoxFromSql($id, $label, Database $database, $sql, array $options = array())
{
$selectboxEntries = array();
// execute the sql statement
$pdoStatement = $database->query($sql);
// create array from sql result
while ($row = $pdoStatement->fetch())
{
// if result has 3 columns then create a array in array
if (count($row) === 3)
{
$selectboxEntries[] = array($row[0], $row[1], $row[2]);
}
else
{
$selectboxEntries[$row[0]] = $row[1];
}
}
// now call default method to create a selectbox
$this->addSelectBox($id, $label, $selectboxEntries, $options);
}
/**
* Add a new selectbox with a label to the form. The selectbox could have
* different values and a default value could be set.
* @param string $id Id of the selectbox. This will also be the name of the selectbox.
* @param string $label The label of the selectbox.
* @param string $xmlFile Serverpath to the xml file
* @param string $xmlValueTag Name of the xml tag that should contain the internal value of a selectbox entry
* @param string $xmlViewTag Name of the xml tag that should contain the visual value of a selectbox entry
* @param array $options (optional) An array with the following possible entries:
* - @b property : With this param you can set the following properties:
* + @b FIELD_DEFAULT : The field can accept an input.
* + @b FIELD_REQUIRED : The field will be marked as a mandatory field where the user must insert a value.
* + @b FIELD_DISABLED : The field will be disabled and could not accept an input.
* - @b defaultValue : This is the value the selectbox shows when loaded. If @b multiselect is activated than
* an array with all default values could be set.
* - @b showContextDependentFirstEntry : If set to @b true the select box will get an additional first entry.
* If FIELD_REQUIRED is set than "Please choose" will be the first entry otherwise
* an empty entry will be added so you must not select something.
* - @b firstEntry : Here you can define a string that should be shown as firstEntry and will be the
* default value if no other value is set. This entry will only be added if @b showContextDependentFirstEntry
* is set to false!
* - @b multiselect : If set to @b true than the jQuery plugin Select2 will be used to create a selectbox
* where the user could select multiple values from the selectbox. Then an array will be
* created within the $_POST array.
* - @b maximumSelectionNumber : If @b multiselect is enabled then you can configure the maximum number
* of selections that could be done. If this limit is reached the user can't add another entry to the selectbox.
* - @b helpTextIdLabel : A unique text id from the translation xml files that should be shown
* e.g. SYS_ENTRY_MULTI_ORGA. If set a help icon will be shown after the control label where
* the user can see the text if he hover over the icon. If you need an additional parameter
* for the text you can add an array. The first entry must be the unique text id and the second
* entry will be a parameter of the text id.
* - @b helpTextIdInline : A unique text id from the translation xml files that should be shown
* e.g. SYS_ENTRY_MULTI_ORGA. If set the complete text will be shown after the form element.
* If you need an additional parameter for the text you can add an array. The first entry must
* be the unique text id and the second entry will be a parameter of the text id.
* - @b icon : An icon can be set. This will be placed in front of the label.
* - @b class : An additional css classname. The class @b admSelectbox
* is set as default and need not set with this parameter.
*/
public function addSelectBoxFromXml($id, $label, $xmlFile, $xmlValueTag, $xmlViewTag, array $options = array())
{
$selectboxEntries = array();
$xmlRootNode = new SimpleXMLElement($xmlFile, null, true);
foreach ($xmlRootNode->children() as $xmlChildNode)
{
$key = '';
$value = '';
foreach ($xmlChildNode->children() as $xmlChildChildNode)
{
if ($xmlChildChildNode->getName() === $xmlValueTag)
{
$key = (string) $xmlChildChildNode;
}
if ($xmlChildChildNode->getName() === $xmlViewTag)
{
$value = (string) $xmlChildChildNode;
}
}
$selectboxEntries[$key] = $value;
}
// now call default method to create a selectbox
$this->addSelectBox($id, $label, $selectboxEntries, $options);
}
/**
* Add a new selectbox with a label to the form. The selectbox get their data from table adm_categories.
* You must define the category type (roles, dates, links ...). All categories of this type will be shown.
* @param string $id Id of the selectbox. This will also be the name of the selectbox.
* @param string $label The label of the selectbox.
* @param \Database $database A Admidio database object that contains a valid connection to a database
* @param string $categoryType Type of category ('DAT', 'LNK', 'ROL', 'USF') that should be shown
* @param string $selectboxModus The selectbox could be shown in 2 different modus.
* - @b EDIT_CATEGORIES : First entry will be "Please choose" and default category will be preselected.
* - @b FILTER_CATEGORIES : First entry will be "All" and only categories with childs will be shown.
* @param array $options (optional) An array with the following possible entries:
* - @b property : With this param you can set the following properties:
* + @b FIELD_DEFAULT : The field can accept an input.
* + @b FIELD_REQUIRED : The field will be marked as a mandatory field where the user must insert a value.
* + @b FIELD_DISABLED : The field will be disabled and could not accept an input.
* - @b defaultValue : Id of category that should be selected per default.
* - @b showSystemCategory : Show user defined and system categories
* - @b helpTextIdLabel : A unique text id from the translation xml files that should be shown
* e.g. SYS_ENTRY_MULTI_ORGA. If set a help icon will be shown after the control label where
* the user can see the text if he hover over the icon. If you need an additional parameter
* for the text you can add an array. The first entry must be the unique text id and the second
* entry will be a parameter of the text id.
* - @b helpTextIdInline : A unique text id from the translation xml files that should be shown
* e.g. SYS_ENTRY_MULTI_ORGA. If set the complete text will be shown after the form element.
* If you need an additional parameter for the text you can add an array. The first entry must
* be the unique text id and the second entry will be a parameter of the text id.
* - @b icon : An icon can be set. This will be placed in front of the label.
* - @b class : An additional css classname. The class @b admSelectbox
* is set as default and need not set with this parameter.
*/
public function addSelectBoxForCategories($id, $label, Database $database, $categoryType, $selectboxModus, array $options = array())
{
global $gCurrentOrganization, $gValidLogin, $gL10n;
// create array with all options
$optionsDefault = array(
'property' => FIELD_DEFAULT,
'defaultValue' => '',
'showContextDependentFirstEntry' => true,
'multiselect' => false,
'showSystemCategory' => true,
'helpTextIdLabel' => '',
'helpTextIdInline' => '',
'icon' => '',
'class' => ''
);
$optionsAll = array_replace($optionsDefault, $options);
$sqlTables = '';
$sqlCondidtions = '';
// create sql conditions if category must have child elements
if($selectboxModus === 'FILTER_CATEGORIES')
{
$optionsAll['showContextDependentFirstEntry'] = false;
switch ($categoryType)
{
case 'DAT':
$sqlTables = ' INNER JOIN '.TBL_DATES.' ON cat_id = dat_cat_id ';
break;
case 'LNK':
$sqlTables = ' INNER JOIN '.TBL_LINKS.' ON cat_id = lnk_cat_id ';
break;
case 'ROL':
// don't show system categories
$sqlTables = ' INNER JOIN '.TBL_ROLES.' ON cat_id = rol_cat_id';
$sqlCondidtions = ' AND rol_visible = 1 ';
break;
case 'INF':
$sqlTables = ' INNER JOIN '.TBL_INVENT_FIELDS.' ON cat_id = inf_cat_id ';
break;
}
}
if(!$optionsAll['showSystemCategory'])
{
$sqlCondidtions .= ' AND cat_system = 0 ';
}
if(!$gValidLogin)
{
$sqlCondidtions .= ' AND cat_hidden = 0 ';
}
// the sql statement which returns all found categories
$sql = 'SELECT DISTINCT cat_id, cat_name, cat_default, cat_sequence
FROM '.TBL_CATEGORIES.'
'.$sqlTables.'
WHERE ( cat_org_id = '. $gCurrentOrganization->getValue('org_id'). '
OR cat_org_id IS NULL )
AND cat_type = \''.$categoryType.'\'
'.$sqlCondidtions.'
ORDER BY cat_sequence ASC';
$pdoStatement = $database->query($sql);
$countCategories = $pdoStatement->rowCount();
// if no or only one category exist and in filter modus, than don't show category
if(($countCategories === 0 || $countCategories === 1) && $selectboxModus === 'FILTER_CATEGORIES')
{
return;
}
$categoriesArray = array();
if($countCategories > 1 && $selectboxModus === 'FILTER_CATEGORIES')
{
$categoriesArray[0] = $gL10n->get('SYS_ALL');
}
while($row = $pdoStatement->fetch())
{
// if several categories exist than select default category
if($optionsAll['defaultValue'] === '' && ($countCategories === 1 || $row['cat_default'] === '1'))
{
$optionsAll['defaultValue'] = $row['cat_id'];
}
// if text is a translation-id then translate it
if(strpos($row['cat_name'], '_') === 3)
{
$categoriesArray[$row['cat_id']] = $gL10n->get(admStrToUpper($row['cat_name']));
}
else
{
$categoriesArray[$row['cat_id']] = $row['cat_name'];
}
}
// now call method to create selectbox from array
$this->addSelectBox($id, $label, $categoriesArray, $optionsAll);
}
/**
* Add a new static control to the form. A static control is only a simple text instead of an input field.
* This could be used if the value should not be changed by the user.
* @param string $id Id of the static control. This will also be the name of the static control.
* @param string $label The label of the static control.
* @param string $value A value of the static control. The control will be created with this value.
* @param array $options (optional) An array with the following possible entries:
* - @b helpTextIdLabel : A unique text id from the translation xml files that should be shown
* e.g. SYS_ENTRY_MULTI_ORGA. If set a help icon will be shown after the control label where
* the user can see the text if he hover over the icon. If you need an additional parameter
* for the text you can add an array. The first entry must be the unique text id and the second
* entry will be a parameter of the text id.
* - @b helpTextIdInline : A unique text id from the translation xml files that should be shown
* e.g. SYS_ENTRY_MULTI_ORGA. If set the complete text will be shown after the form element.
* If you need an additional parameter for the text you can add an array. The first entry must
* be the unique text id and the second entry will be a parameter of the text id.
* - @b icon : An icon can be set. This will be placed in front of the label.
* - @b class : An additional css classname. The class @b admSelectbox
* is set as default and need not set with this parameter.
*/
public function addStaticControl($id, $label, $value, array $options = array())
{
$attributes = array('class' => 'form-control-static');
++$this->countElements;
// create array with all options
$optionsDefault = array('helpTextIdLabel' => '', 'helpTextIdInline' => '', 'icon' => '', 'class' => '');
$optionsAll = array_replace($optionsDefault, $options);
// set specific css class for this field
if($optionsAll['class'] !== '')
{
$attributes['class'] .= ' '.$optionsAll['class'];
}
// now create html for the field
$this->openControlStructure('', $label, FIELD_DEFAULT, $optionsAll['helpTextIdLabel'], $optionsAll['icon']);
$this->addHtml('<p class="'.$attributes['class'].'">'.$value.'</p>');
$this->closeControlStructure($optionsAll['helpTextIdInline']);
}
/**
* Add a new button with a custom text to the form. This button could have
* an icon in front of the text. Different to addButton this method adds an
* additional @b div around the button and the type of the button is @b submit.
* @param string $id Id of the button. This will also be the name of the button.
* @param string $text Text of the button
* @param array $options (optional) An array with the following possible entries:
* - @b icon : Optional parameter. Path and filename of an icon.
* If set a icon will be shown in front of the text.
* - @b link : If set a javascript click event with a page load to this link
* will be attached to the button.
* - @b onClickText : A text that will be shown after a click on this button
* until the next page is loaded. The button will be disabled after click.
* - @b class : Optional an additional css classname. The class @b admButton
* is set as default and need not set with this parameter.
* - @b type : If set to true this button get the type @b submit. This will
* be the default.
*/
public function addSubmitButton($id, $text, array $options = array())
{
// create array with all options
$optionsDefault = array('icon' => '', 'link' => '', 'onClickText' => '', 'class' => '', 'type' => 'submit');
$optionsAll = array_replace($optionsDefault, $options);
// add default css class
$optionsAll['class'] .= ' btn-primary';
// now add button to form
$this->addButton($id, $text, $optionsAll);
if(!$this->buttonGroupOpen)
{
$this->addHtml('<div class="form-alert" style="display: none;"> </div>');
}
}
/**
* Close an open bootstrap btn-group
*/
public function closeButtonGroup()
{
$this->buttonGroupOpen = false;
$this->addHtml('</div><div class="form-alert" style="display: none;"> </div>');
}
/**
* Closes a field structure that was added with the method openControlStructure.
* @param string|string[] $helpTextId A unique text id from the translation xml files that should be shown e.g. SYS_ENTRY_MULTI_ORGA.
* If set the complete text will be shown after the form element.
* @param string[] $parameters If you need an additional parameter for the text you can set this array.
*/
protected function closeControlStructure($helpTextId = null, array $parameters = array())
{
global $gL10n;
// backwards compatibility
if (is_array($helpTextId))
{
$parameters = $helpTextId;
$helpTextId = array_shift($parameters);
}
if ($helpTextId !== null)
{
if (count($parameters) === 0)
{
// if text is a translation-id then translate it
if (strpos($helpTextId, '_') === 3)
{
$helpText = $gL10n->get($helpTextId);
}
else
{
$helpText = $helpTextId;
}
}
else
{
foreach ($parameters as &$parameter)
{
// if parameter is a translation-id then translate it
if (strpos($parameter, '_') === 3)
{
$parameter = $gL10n->get($parameter);
}
}
unset($parameter);
// PHP 5.6+ use: $helpText = $gL10n->get($helpTextId, ...$parameters);
if (count($parameters) === 1)
{
$helpText = $gL10n->get($helpTextId, $parameters[0]);
}
else
{
$helpText = $gL10n->get($helpTextId, $parameters[0], $parameters[1]);
}
}
$this->addHtml('<div class="help-block">'.$helpText.'</div>');
}
if ($this->type === 'vertical' || $this->type === 'navbar')
{
$this->addHtml('</div>');
}
else
{
$this->addHtml('</div></div>');
}
}
/**
* Close all html elements of a groupbox that was created before.
*/
public function closeGroupBox()
{
$this->addHtml('</div></div>');
}
/**
* Open a bootstrap btn-group if the form need more than one button.
*/
public function openButtonGroup()
{
$this->buttonGroupOpen = true;
$this->addHtml('<div class="btn-group" role="group">');
}
/**
* Creates a html structure for a form field. This structure contains the label and the div for the form element.
* After the form element is added the method closeControlStructure must be called.
* @param string $id The id of this field structure.
* @param string $label The label of the field. This string should already be translated.
* @param int $property (optional) With this param you can set the following properties:
* - @b FIELD_DEFAULT : The field can accept an input.
* - @b FIELD_REQUIRED : The field will be marked as a mandatory field where the user must insert a value.
* - @b FIELD_DISABLED : The field will be disabled and could not accept an input.
* @param string $helpTextId (optional) A unique text id from the translation xml files that should be shown e.g. SYS_ENTRY_MULTI_ORGA.
* If set a help icon will be shown where the user can see the text if he hover over the icon.
* If you need an additional parameter for the text you can add an array. The first entry
* must be the unique text id and the second entry will be a parameter of the text id.
* @param string $icon (optional) An icon can be set. This will be placed in front of the label.
* @param string $class (optional) An additional css classname for the row. The class @b admFieldRow
* is set as default and need not set with this parameter.
*/
protected function openControlStructure($id, $label, $property = FIELD_DEFAULT, $helpTextId = '', $icon = '', $class = '')
{
$cssClassRow = '';
$htmlIcon = '';
$htmlHelpIcon = '';
$htmlIdFor = '';
// set specific css class for this row
if($class !== '')
{
$cssClassRow .= ' '.$class;
}
// if necessary set css class for a mandatory element
if($property === FIELD_REQUIRED && $this->showRequiredFields)
{
$cssClassRow .= ' admidio-form-group-required';
$this->flagRequiredFields = true;
}
if($id !== '')
{
$htmlIdFor = ' for="'.$id.'"';
$this->addHtml('<div id="'.$id.'_group" class="form-group'.$cssClassRow.'">');
}
else
{
$this->addHtml('<div class="form-group'.$cssClassRow.'">');
}
if(strlen($icon) > 0)
{
// create html for icon
if(strpos(admStrToLower($icon), 'http') === 0 && strValidCharacters($icon, 'url'))
{
$htmlIcon = '<img class="admidio-icon-info" src="'.$icon.'" title="'.$label.'" alt="'.$label.'" />';
}
elseif(admStrIsValidFileName($icon, true))
{
$htmlIcon = '<img class="admidio-icon-info" src="'.THEME_PATH.'/icons/'.$icon.'" title="'.$label.'" alt="'.$label.'" />';
}
}
if($helpTextId !== '')
{
$htmlHelpIcon = self::getHelpTextIcon($helpTextId);
}
// add label element
if($this->type === 'vertical' || $this->type === 'navbar')
{
if($label !== '')
{
$this->addHtml('<label'.$htmlIdFor.'>'.$htmlIcon.$label.$htmlHelpIcon.'</label>');
}
}
else
{
if($label !== '')
{
$this->addHtml('<label'.$htmlIdFor.' class="col-sm-3 control-label">'.$htmlIcon.$label.$htmlHelpIcon.'</label>
<div class="col-sm-9">');
}
else
{
$this->addHtml('<div class="col-sm-offset-3 col-sm-9">');
}
}
}
/**
* Add a new groupbox to the form. This could be used to group some elements
* together. There is also the option to set a headline to this group box.
* @param string $id Id the the groupbox.
* @param string $headline (optional) A headline that will be shown to the user.
* @param string $class (optional) An additional css classname for the row. The class @b admFieldRow
* is set as default and need not set with this parameter.
*/
public function openGroupBox($id, $headline = null, $class = '')
{
$this->addHtml('<div id="'.$id.'" class="panel panel-default '.$class.'">');
// add headline to groupbox
if($headline !== null)
{
$this->addHtml('<div class="panel-heading">'.$headline.'</div>');
}
$this->addHtml('<div class="panel-body">');
}
/**
* Add a small help icon to the form at the current element which shows the
* translated text of the text-id on mouseover or when you click on the icon.
* @param string|string[] $textId A unique text id from the translation xml files that should be shown e.g. SYS_ENTRY_MULTI_ORGA.
* @param string $parameter If you need an additional parameter for the text you can set this parameter.
* @return string Return a html snippet that contains a help icon with a link to a popup box that shows the message.
*/
public static function getHelpTextIcon($textId, $parameter = null)
{
global $gL10n, $gProfileFields;
// backwards compatibility
if (is_array($textId))
{
list($textId, $parameter) = $textId;
}
if ($parameter === null)
{
$text = $gL10n->get($textId);
}
else
{
if ($textId === 'user_field_description')
{
$text = $gProfileFields->getProperty($parameter, 'usf_description');
}
else
{
$text = $gL10n->get($textId, $parameter);
}
}
return '<img class="admidio-icon-help" src="'.THEME_PATH.'/icons/help.png" title="'.$gL10n->get('SYS_NOTE').'" alt="Help"
data-toggle="popover" data-html="true" data-trigger="hover" data-placement="auto" data-content="'.htmlspecialchars($text).'" />';
}
/**
* This method send the whole html code of the form to the browser. Call this method
* if you have finished your form layout. If mandatory fields were set than a notice
* which marker represents the mandatory will be shown before the form.
* @param bool $directOutput (optional) If set to @b true (default) the form html will be directly send
* to the browser. If set to @b false the html will be returned.
* @return string|null If $directOutput is set to @b false this method will return the html code of the form.
*/
public function show($directOutput = true)
{
global $gL10n;
// if there are no elements in the form then return nothing
if($this->countElements === 0)
{
return null;
}
$html = '';
// If required fields were set than a notice which marker represents the required fields will be shown.
if($this->flagRequiredFields && $this->showRequiredFields)
{
$html .= '<div class="admidio-form-required-notice"><span>'.$gL10n->get('SYS_REQUIRED_FIELDS').'</span></div>';
}
// now get whole form html code
$html .= $this->getHtmlForm();
if($directOutput)
{
echo $html;
return null;
}
return $html;
}
}