예제 #1
0
function tpl_html_champ_membre($params)
{
    if (empty($params['config']) || empty($params['name'])) {
        throw new \BadFunctionCallException('Paramètres type et name obligatoires.');
    }
    $config = $params['config'];
    $type = $config['type'];
    if ($params['name'] == 'passe' || !empty($params['user_mode']) && !empty($config['private'])) {
        return '';
    }
    if ($type == 'select') {
        if (empty($config['options'])) {
            throw new \BadFunctionCallException('Paramètre options obligatoire pour champ de type select.');
        }
    } elseif ($type == 'country') {
        $type = 'select';
        $config['options'] = Utils::getCountryList();
        $params['default'] = Config::getInstance()->get('pays');
    } elseif ($type == 'date') {
        $params['pattern'] = '\\d{4}-\\d{2}-\\d{2}';
    } elseif ($type == 'multiple') {
        if (empty($config['options'])) {
            throw new \BadFunctionCallException('Paramètre options obligatoire pour champ de type multiple.');
        }
    }
    $field = '';
    $value = tpl_form_field($params);
    $attributes = 'name="' . htmlspecialchars($params['name'], ENT_QUOTES, 'UTF-8') . '" ';
    $attributes .= 'id="f_' . htmlspecialchars($params['name'], ENT_QUOTES, 'UTF-8') . '" ';
    if (!empty($params['disabled'])) {
        $attributes .= 'disabled="disabled" ';
    }
    if (!empty($config['mandatory'])) {
        $attributes .= 'required="required" ';
    }
    if (!empty($params['user_mode']) && empty($config['editable'])) {
        $out = '<dt>' . htmlspecialchars($config['title'], ENT_QUOTES, 'UTF-8') . '</dt>';
        $out .= '<dd>' . (trim($value) === '' ? 'Non renseigné' : tpl_display_champ_membre($value, $config)) . '</dd>';
        return $out;
    }
    if ($type == 'select') {
        $field .= '<select ' . $attributes . '>';
        foreach ($config['options'] as $k => $v) {
            if (is_int($k)) {
                $k = $v;
            }
            $field .= '<option value="' . htmlspecialchars($k, ENT_QUOTES, 'UTF-8') . '"';
            if ($value == $k || empty($value) && !empty($params['default'])) {
                $field .= ' selected="selected"';
            }
            $field .= '>' . htmlspecialchars($v, ENT_QUOTES, 'UTF-8') . '</option>';
        }
        $field .= '</select>';
    } elseif ($type == 'multiple') {
        if (is_array($value)) {
            $binary = 0;
            foreach ($value as $k => $v) {
                if (array_key_exists($k, $config['options']) && !empty($v)) {
                    $binary |= 0x1 << $k;
                }
            }
            $value = $binary;
        }
        foreach ($config['options'] as $k => $v) {
            $b = 0x1 << (int) $k;
            $field .= '<label><input type="checkbox" name="' . htmlspecialchars($params['name'], ENT_QUOTES, 'UTF-8') . '[' . (int) $k . ']" value="1" ' . ($value & $b ? 'checked="checked"' : '') . ' ' . $attributes . '/> ' . htmlspecialchars($v, ENT_QUOTES, 'UTF-8') . '</label><br />';
        }
    } elseif ($type == 'textarea') {
        $field .= '<textarea ' . $attributes . 'cols="30" rows="5">' . $value . '</textarea>';
    } else {
        if ($type == 'checkbox') {
            if (!empty($value)) {
                $attributes .= 'checked="checked" ';
            }
            $value = '1';
        }
        $field .= '<input type="' . $type . '" ' . $attributes . ' value="' . $value . '" />';
    }
    $out = '
    <dt>';
    if ($type == 'checkbox') {
        $out .= $field . ' ';
    }
    $out .= '<label for="f_' . htmlspecialchars($params['name'], ENT_QUOTES, 'UTF-8') . '">' . htmlspecialchars($config['title'], ENT_QUOTES, 'UTF-8') . '</label>';
    if (!empty($config['mandatory'])) {
        $out .= ' <b title="(Champ obligatoire)">obligatoire</b>';
    }
    $out .= '</dt>';
    if (!empty($config['help'])) {
        $out .= '
    <dd class="help">' . htmlspecialchars($config['help'], ENT_QUOTES, 'UTF-8') . '</dd>';
    }
    if ($type != 'checkbox') {
        $out .= '
    <dd>' . $field . '</dd>';
    }
    return $out;
}
예제 #2
0
파일: install.php 프로젝트: bontiv/intrateb
function tpl_pge_userinfo()
{
    extract($GLOBALS);
    ?>
    <h2><?php 
    echo $titles['userinfo'];
    ?>
</h2>
    <form role="form" method="POST" action="install.php?etape=userinfo">
        <?php 
    tpl_form_field('admin_user', 'Utilisateur admin');
    tpl_form_field('admin_pass', 'Mot de passe admin', 'password');
    ?>
      <button type="submit" class="btn btn-default">Valider</button>
    </form>


    <?php 
}
예제 #3
0
/**
 * 显示一个编辑器项
 * @param string $title 表单项标题
 * @param string $name 表单项名称
 * @param string $value 编辑器内容
 * @param string $comment 描述信息
 */
function tpl_form_field_editor($title, $name, $value = '', $comment = '') {
	static $editorid = 0;
	$editorid++;
	$s = '
	<link rel="stylesheet" href="kindeditor/skins/default.css" type="text/css" media="all" />
	<script type="text/javascript" src="static/kindeditor/kindeditor-min.js"></script>
	<script>
	KE.show({
		id : "editor' . $editorid . '",
		resizeMode:1,
		allowUpload:false,
		urlType:\'absolute\',
		items : [\'bold\',\'italic\',\'underline\',\'strikethrough\',\'textcolor\',\'bgcolor\',\'fontname\',\'fontsize\',\'removeformat\',\'wordpaste\',\'insertorderedlist\',\'insertunorderedlist\',\'indent\',\'outdent\',\'justifyleft\',\'justifycenter\',\'justifyright\',\'link\',\'unlink\',\'image\',\'flash\',\'advtable\',\'emoticons\',\'source\']
	});
	</script>
	<textarea name="' . $name . '" id="editor' . $editorid . '" style="width:600px;height:150px;">' . rhtmlspecialchars($value) . '</textarea>';
	tpl_form_field($title, $name, $s, $comment);
}