コード例 #1
0
ファイル: table_users.php プロジェクト: lilfade/UserFrosting
$ajax = checkRequestMode("get");
if (!securePage(__FILE__)) {
    // Forward to index page
    addAlert("danger", "Whoops, looks like you don't have permission to view that page.");
    apiReturnError($ajax, ACCOUNT_ROOT);
}
// Sanitize input data
$get = filter_input_array(INPUT_GET, FILTER_SANITIZE_SPECIAL_CHARS);
// Parameters: [title, limit, columns, actions, buttons]
// title (optional): title of this table.
// limit (optional): if specified, loads only the first n rows.
// columns (optional): a list of columns to render.
// actions (optional): a list of actions to render in a dropdown in a special 'action' column.
// buttons (optional): a list of buttons to render at the bottom of the table.
// Set up Valitron validator
$v = new Valitron\DefaultValidator($get);
// Add default values
$v->setDefault('title', 'Users');
$v->setDefault('limit', null);
$v->setDefault('columns', ['user_info' => ['label' => 'User/Info', 'sort' => 'asc', 'sorter' => 'metatext', 'sort_field' => 'user_name', 'template' => "\n            <div class='h4'>\n                <a href='user_details.php?id={{user_id}}'>{{display_name}} ({{user_name}})</a>\n            </div>\n            <div>\n                <i>{{title}}</i>\n            </div>\n            <div>\n                <i class='fa fa-envelope'></i> <a href='mailto:{{email}}'>{{email}}</a>\n            </div>"], 'user_since' => ['label' => 'Registered Since', 'sorter' => 'metanum', 'sort_field' => 'sign_up_stamp', 'template' => "\n            {{sign_up_day}}<br>\n            {{sign_up_date}} {{sign_up_time}}"], 'user_sign_in' => ['label' => 'Last Sign-in', 'sorter' => 'metanum', 'sort_field' => 'last_sign_in_stamp', 'template' => "\n            {{last_sign_in_day}}<br>\n            {{last_sign_in_date}} {{last_sign_in_time}}", 'empty_field' => 'last_sign_in_stamp', 'empty_value' => '0', 'empty_template' => "<i>Brand new</i>"]]);
$v->setDefault('menu_items', ['user_activate' => ['template' => "<a href='#' data-id='{{user_id}}' class='btn-activate-user {{hide_activation}}'><i class='fa fa-bolt'></i> Activate user</a>"], 'user_edit' => ['template' => "<a href='#' data-id='{{user_id}}' class='btn-edit-user' data-target='#user-update-dialog' data-toggle='modal'><i class='fa fa-edit'></i> Edit user</a>"], 'user_disable' => ['template' => "<a href='#' data-id='{{user_id}}' class='{{toggle_disable_class}}'><i class='{{toggle_disable_icon}}'></i> {{toggle_disable_label}}</a>"], 'user_delete' => ['template' => "<a href='#' data-id='{{user_id}}' class='btn-delete-user' data-user_name='{{user_name}}' data-target='#user-delete-dialog' data-toggle='modal'><i class='fa fa-trash-o'></i> Delete user</a>"]]);
$v->setDefault('buttons', ['add' => "", 'view_all' => ""]);
// Validate!
$v->validate();
// Process errors
if (count($v->errors()) > 0) {
    foreach ($v->errors() as $idx => $error) {
        addAlert("danger", $error);
    }
    apiReturnError($ajax, ACCOUNT_ROOT);
} else {
コード例 #2
0
// Request method: GET
require_once "../models/config.php";
// Request method: GET
$ajax = checkRequestMode("get");
if (!securePage(__FILE__)) {
    apiReturnError($ajax);
}
// TODO: allow setting default groups
// Sanitize input data
$get = filter_input_array(INPUT_GET, FILTER_SANITIZE_SPECIAL_CHARS);
// Parameters: box_id, render_mode, [user_id, show_dates, disabled]
// box_id: the desired name of the div that will contain the form.
// render_mode: modal or panel
// user_id (optional): if specified, will load the relevant data for the user into the form.  Form will then be in "update" mode.
// Set up Valitron validator
$v = new Valitron\DefaultValidator($get);
$v->rule('required', 'box_id');
$v->rule('required', 'render_mode');
$v->rule('in', 'render_mode', array('modal', 'panel'));
$v->rule('integer', 'user_id');
$v->setDefault('user_id', null);
$v->setDefault('fields', array());
$v->setDefault('buttons', array());
// Validate!
$v->validate();
// Process errors
if (count($v->errors()) > 0) {
    foreach ($v->errors() as $idx => $error) {
        addAlert("danger", $error);
    }
    apiReturnError($ajax, ACCOUNT_ROOT);