示例#1
0
<?php

/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) PHP-Fusion Inc
| http://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: UserFields.php
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
require_once "../maincore.php";
require_once THEMES . "templates/admin_header.php";
include LOCALE . LOCALESET . "admin/fields.php";
$user_field = new PHPFusion\QuantumFields();
$user_field->setSystemTitle($locale['202']);
$user_field->setAdminRights('UFC');
$user_field->setCategoryDb(DB_USER_FIELD_CATS);
$user_field->setFieldDb(DB_USER_FIELDS);
$user_field->setMethod('input');
$user_field->setPluginFolder(INCLUDES . "user_fields/");
$user_field->setPluginLocaleFolder(LOCALE . LOCALESET . "user_fields/");
$user_field->displayQuantumAdmin();
require_once THEMES . "templates/footer.php";
示例#2
0
/**
 * Select2 hierarchy
 * Returns a full hierarchy nested dropdown.
 * @param        $input_name
 * @param string $label
 * @param bool   $input_value
 * @param array  $options
 * @param        $db - your db
 * @param        $name_col - the option text to show
 * @param        $id_col - unique id
 * @param        $cat_col - parent id
 *                         ## The rest of the Params are used by the function itself -- no need to handle ##
 * @param bool   $self_id - not required
 * @param bool   $id - not required
 * @param bool   $level - not required
 * @param bool   $index - not required
 * @param bool   $data - not required
 * @return string
 */
function form_select_tree($input_name, $label = "", $input_value = FALSE, array $options = array(), $db, $name_col, $id_col, $cat_col, $self_id = FALSE, $id = FALSE, $level = FALSE, $index = FALSE, $data = FALSE)
{
    global $defender, $locale;
    if (!defined("SELECT2")) {
        define("SELECT2", TRUE);
        add_to_footer("<script src='" . DYNAMICS . "assets/select2/select2.min.js' /></script>\n");
        add_to_head("<link href='" . DYNAMICS . "assets/select2/select2.css' rel='stylesheet' />\n");
    }
    $title = $label ? stripinput($label) : ucfirst(strtolower(str_replace("_", " ", $input_name)));
    $default_options = array('required' => FALSE, 'regex' => '', 'input_id' => $input_name, 'placeholder' => $locale['choose'], 'deactivate' => FALSE, 'safemode' => FALSE, 'allowclear' => FALSE, 'multiple' => FALSE, 'width' => '250px', 'keyflip' => FALSE, 'tags' => FALSE, 'jsonmode' => FALSE, 'chainable' => FALSE, 'maxselect' => FALSE, 'error_text' => $locale['error_input_default'], 'class' => '', 'inline' => FALSE, 'tip' => '', 'delimiter' => ',', 'callback_check' => '', 'file' => '', 'parent_value' => $locale['root'], 'add_parent_opts' => FALSE, 'disable_opts' => '', 'hide_disabled' => FALSE, 'no_root' => FALSE, 'show_current' => FALSE, 'query' => '');
    $options += $default_options;
    $options['input_id'] = trim($options['input_id'], "[]");
    if ($options['multiple']) {
        if ($input_value) {
            $input_value = construct_array($input_value, 0, $options['delimiter']);
        } else {
            $input_value = array();
        }
    }
    if (!$options['width']) {
        $options['width'] = $default_options['width'];
    }
    $allowclear = $options['placeholder'] && $options['multiple'] || $options['allowclear'] ? "allowClear:true" : '';
    $disable_opts = '';
    if ($options['disable_opts']) {
        $disable_opts = is_array($options['disable_opts']) ? $options['disable_opts'] : explode(',', $options['disable_opts']);
    }
    /* Child patern */
    $opt_pattern = str_repeat("&#8212;", $level);
    if (!$level) {
        $level = 0;
        if (!isset($index[$id])) {
            $index[$id] = array('0' => $locale['no_opts']);
        }
        $error_class = "";
        if ($defender->inputHasError($input_name)) {
            $error_class = "has-error ";
            if (!empty($options['error_text'])) {
                $new_error_text = $defender->getErrorText($input_name);
                if (!empty($new_error_text)) {
                    $options['error_text'] = $new_error_text;
                }
                addNotice("danger", "<strong>{$title}</strong> - " . $options['error_text']);
            }
        }
        $html = "<div id='" . $options['input_id'] . "-field' class='form-group " . $error_class . $options['class'] . "' " . ($options['inline'] && $options['width'] && !$label ? "style='width: " . $options['width'] . "'" : '') . ">\n";
        $html .= $label ? "<label class='control-label " . ($options['inline'] ? "col-xs-12 col-sm-3 p-l-0" : 'col-xs-12 p-l-0') . "' for='" . $options['input_id'] . "'>{$label} " . ($options['required'] == TRUE ? "<span class='required'>*</span>" : '') . " " . ($options['tip'] ? "<i class='pointer fa fa-question-circle' label=\"" . $options['tip'] . "\"></i>" : '') . "</label>\n" : '';
        $html .= $options['inline'] ? "<div class='col-xs-12 " . ($label ? "col-sm-9 col-md-9 col-lg-9" : "col-sm-12") . "'>\n" : "";
    }
    if ($level == 0) {
        $html =& $html;
        add_to_jquery("\n\t\t\$('#" . $options['input_id'] . "').select2({\n\t\tplaceholder: '" . $options['placeholder'] . "',\n\t\t{$allowclear}\n\t\t});\n\t\t");
        if (is_array($input_value) && $options['multiple']) {
            // stores as value;
            $vals = '';
            foreach ($input_value as $arr => $val) {
                $vals .= $arr == count($input_value) - 1 ? "'{$val}'" : "'{$val}',";
            }
            add_to_jquery("\$('#" . $options['input_id'] . "').select2('val', [{$vals}]);");
        }
        $html .= "<select name='{$input_name}' id='" . $options['input_id'] . "' style='width: " . ($options['width'] ? $options['width'] : $default_options['width']) . "' " . ($options['deactivate'] ? " disabled" : "") . ($options['multiple'] ? " multiple" : "") . ">";
        $html .= $options['allowclear'] ? "<option value=''></option>" : '';
        if ($options['no_root'] == FALSE) {
            // api options to remove root from selector. used in items creation.
            $this_select = '';
            if ($input_value !== NULL) {
                if ($input_value !== '') {
                    $this_select = 'selected';
                }
            }
            $html .= $options['add_parent_opts'] == TRUE ? "<option value='0' " . $this_select . ">{$opt_pattern} " . $locale['parent'] . "</option>\n" : "<option value='0' " . $this_select . " >{$opt_pattern} " . $options['parent_value'] . "</option>\n";
        }
        $index = dbquery_tree($db, $id_col, $cat_col, $options['query']);
        $data = dbquery_tree_data($db, $id_col, $cat_col, $options['query']);
    }
    if (!$id) {
        $id = 0;
    }
    if (isset($index[$id])) {
        foreach ($index[$id] as $key => $value) {
            //$hide = $disable_branch && $value == $self_id ? 1 : 0;
            $html =& $html;
            $name = $data[$value][$name_col];
            $name = PHPFusion\QuantumFields::parse_label($name);
            $select = $input_value !== "" && $input_value == $value ? 'selected' : '';
            $disabled = $disable_opts && in_array($value, $disable_opts) ? TRUE : FALSE;
            $hide = $disabled && $options['hide_disabled'] ? TRUE : FALSE;
            // do a disable for filter_opts item.
            $html .= !$hide ? "<option value='{$value}' " . $select . " " . ($disable_opts && in_array($value, $disable_opts) ? 'disabled' : '') . " >{$opt_pattern} {$name} " . ($options['show_current'] && $self_id == $value ? '(Current Item)' : '') . "</option>\n" : '';
            if (isset($index[$value]) && !$hide) {
                $html .= form_select_tree($input_name, $label, $input_value, $options, $db, $name_col, $id_col, $cat_col, $self_id, $value, $level + TRUE, $index, $data);
            }
        }
    }
    if (!$level) {
        $html =& $html;
        $html .= "</select>";
        $html .= $options['required'] == 1 && $defender->inputHasError($input_name) || $defender->inputHasError($input_name) ? "<div id='" . $options['input_id'] . "-help' class='label label-danger p-5 display-inline-block'>" . $options['error_text'] . "</div>" : "";
        $html .= $options['inline'] ? "</div>\n" : '';
        $html .= "</div>\n";
        if ($options['required']) {
            $html .= "<input class='req' id='dummy-" . $options['input_id'] . "' type='hidden'>\n";
            // for jscheck
        }
        $input_name = $options['multiple'] ? str_replace("[]", "", $input_name) : $input_name;
        $defender->add_field_session(array('input_name' => $input_name, 'title' => trim($title, '[]'), 'id' => $options['input_id'], 'type' => 'dropdown', 'regex' => $options['regex'], 'required' => $options['required'], 'safemode' => $options['safemode'], 'error_text' => $options['error_text'], 'callback_check' => $options['callback_check'], 'delimiter' => $options['delimiter']));
    }
    return $html;
}