/** * 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. */ public function addInput($id, $label, $value, $options = array()) { global $gL10n, $gPreferences, $g_root_path, $gDebug; $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' => ''); $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 = ''; $datepickerOptions = ''; // 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 === false || $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($g_root_path . '/adm_program/libs/bootstrap-datepicker/css/bootstrap-datepicker3.css'); $this->htmlPage->addJavascriptFile($g_root_path . '/adm_program/libs/bootstrap-datepicker/js/bootstrap-datepicker.js'); $this->htmlPage->addJavascriptFile($g_root_path . '/adm_program/libs/bootstrap-datepicker/locales/bootstrap-datepicker.' . $gL10n->getLanguageIsoCode() . '.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['property'] !== FIELD_HIDDEN) { $this->closeControlStructure($optionsAll['helpTextIdInline']); } }
}); }); } '); $page->addJavascript(' $(".admMemberInfo").click(function () { showHideMembershipInformation($(this)) }); $("#profile_authorizations_box_body").mouseout(function () { profileJS.deleteShowInfo()}); $("#menu_item_password").attr("data-toggle", "modal"); $("#menu_item_password").attr("data-target", "#admidio_modal"); $("#menu_item_role_memberships_change").attr("data-toggle", "modal"); $("#menu_item_role_memberships_change").attr("data-target", "#admidio_modal"); $("input[data-provide=\'datepicker\']").datepicker({ language: "' . $gL10n->getLanguageIsoCode() . '", format: "' . DateTimeExtended::getDateFormatForDatepicker($gPreferences['system_date']) . '", todayHighlight: "true", autoclose: "true" }); formSubmitEvent(); ', true); // get module menu $profileMenu = $page->getMenu(); // show back link // @ptabaden: Changed Icon if ($gNavigation->count() > 1) { $profileMenu->addItem('menu_item_back', $gNavigation->getPreviousUrl(), '<i class="fa fa-arrow-left" alt="' . $gL10n->get('SYS_BACK') . '" title="' . $gL10n->get('SYS_BACK') . '"></i><div class="iconDescription">' . $gL10n->get('SYS_BACK') . '</div>', ''); } // if user has right then show link to edit profile if ($gCurrentUser->hasRightEditProfile($user)) { // @ptabaden: Changed Icon $profileMenu->addItem('menu_item_new_entry', $g_root_path . '/adm_program/modules/profile/profile_new.php?user_id=' . $user->getValue('usr_id'), '<i class="fa fa-pencil" alt="' . $gL10n->get('PRO_EDIT_PROFILE') . '" title="' . $gL10n->get('PRO_EDIT_PROFILE') . '"></i><div class="iconDescription">' . $gL10n->get('PRO_EDIT_PROFILE') . '</div>', '');