* @package instance * @link https://www.zentao.net */ namespace zin; if($customFields) { h::css(<<autocomplete)) { $ref = explode('.', $field->autocomplete); if(count($ref) == 2 && empty($field->value)) { switch($field->autocomplete) { case 'zentao.http_protocol': $field->value = strstr(getWebRoot(true), ':', true); break; case 'zentao.http_host': $field->value = trim(strstr(getWebRoot(true), ':', false), ':/'); break; case 'zentao.webroot': $field->value = getWebRoot(); break; case 'zentao.xxd_token': $field->value = zget($config->xuanxuan, 'key', ''); break; default: break; } } } if($field->type == 'switch') $field->type = 'switcher'; $isInput = in_array($field->type, array('text', 'password', 'number')); $isSelect = in_array($field->type, array('select', 'radio', 'checkbox')); if($isSelect) { if(!empty($field->options_api)) $field->options = $this->instance->getOptionsByApi($field->options_api); $field->options = array_column($field->options, 'text', 'value'); if($field->type == 'radio') $field->type = 'radioList'; if($field->type == 'select') $field->type = 'picker'; if($field->type == 'checkbox') $field->type = 'checkList'; } $value = empty($field->value) ? $field->default : $field->value; if($field->type == 'switcher') $value = 1; if($field->type == 'checkList' || $field->style == 'multi') $value = is_array($value) ? $value : explode(zget($field, 'separator', ','), (string)$value); return control(setClass('custom-field'), set::type($field->type), set::name($field->name . ($field->type == 'checkList' ? '[]' : '')), set::value($value), set::placeholder($field->desc), set::required($field->required), $field->type == 'switcher' && ($field->default || !empty($field->value)) ? set::checked((bool)zget($field, 'value', $field->default)) : null, $isInput ? set::placeholder($field->desc) : null, $isInput ? set::autocomplete('new-password') : null, $isInput ? set::maxlength(zget($field, 'length', 255)) : null, $field->type == 'number' ? set::min(zget($field, 'min', 0)) : null, $field->type == 'number' ? set::min(zget($field, 'min', 0)) : null, $field->type == 'number' ? set::step(zget($field, 'step', 1)) : null, $isSelect ? set::items($field->options) : null, strpos($field->type, 'List') ? set::inline($field->style == 'inline') : null, $field->type == 'picker' ? set::multiple($field->style == 'multi') : null); }; $dependFields = array(); foreach($customFields as $field) { if(!empty($field->depends)) { foreach($field->depends as $dependField) $dependFields[$dependField->key][] = $field->name; } if(!hasPriv('instance', 'manage') && $field->type == 'password') $field->value = preg_replace('/./', '*', $field->value); $fields[] = h::tr ( setClass("{$field->name}-row-tr", empty($field->depends) ? null : 'hidden'), h::td ( setClass('custom-field-label', !empty($field->required) ? 'required' : null), zget($lang->instance, $field->name, $field->label) ), h::td ( setClass('custom-field-value', in_array($field->type, array('text', 'password', 'number')) ? 'input-box' : null), hasPriv('instance', 'manage') ? $buildFormWg($field) : $field->value ), $instanceID ? h::td($field->desc) : null ); } jsVar('dependFields', $dependFields); jsVar('customFields', array_column($customFields, null, 'name')); h::table ( setID('customFieldsTable'), setClass('table w-full max-w-full', $instanceID ? 'bordered mt-4' : null), on::input('#customFieldsTable input')->call('window.setCustomField', jsRaw('this')), on::change('#customFieldsTable .picker-box input, #customFieldsTable select')->call('window.setCustomField', jsRaw('this')), $instanceID ? h::tr ( h::th(setClass('w-1/3'), $lang->instance->custom->name), h::th($lang->instance->custom->value), h::th(setClass('w-1/3'), $lang->instance->custom->desc) ) : null, $fields, $instanceID && hasPriv('instance', 'manage') ? h::tr ( h::td( set::colspan(3), setClass('no-label text-center'), btn ( setClass('primary custom-btn disabled'), $lang->save ) ) ) : null ); }