Example #1
0
function action_console_doit()
{
    global $DETDB, $ACTIONS, $SCRIPTS, $BLOCK, $PAGE, $APAGES;
    set_glob_content(array('body' => array('', '')));
    if (isset($_POST['input'])) {
        $input = $_POST['input'];
        $output = $input;
        ob_start();
        $time_start = microtime(true);
        eval($output);
        $time_end = microtime(true);
        $output = ob_get_clean();
        $time = number_format($time_end - $time_start, 7);
        set_glob_content(array('body' => array($input, $output)));
        push_output_message(array('title' => 'Выполнено!', 'text' => "Время выполнения вашего запроса: <b>{$time} сек</b>.", 'type' => 'success', 'class' => 'alert alert-success'));
    }
}
Example #2
0
function action_settings_main($pre = null)
{
    $custom = array('site_name' => '', 'current_template' => '', 'default_group' => '', 'login_agent' => false, 'login_ip' => false, 'cookie_login_live' => null);
    if (!isset($_POST['site_name'])) {
        $custom['site_name'] = get_option('site_name');
        $custom['current_template'] = get_option('current_template');
        $custom['default_group'] = get_option('default_group');
        $login = get_option('admin_check_login');
        $custom['login_ip'] = $login['login_ip'];
        $custom['login_agent'] = $login['login_agent'];
        $custom['cookie_login_live'] = get_option('cookie_login_live') / 60;
        set_glob_content(array('body' => $custom));
    }
    if (isset($_POST['site_name'])) {
        $data = $pre ? $pre : $_POST;
        $custom_new = set_merge($custom, $data, false, true);
        set_glob_content(array('body' => $custom_new));
        if ($custom_new['site_name'] && $custom_new['current_template'] && $custom_new['default_group']) {
            $checker = array();
            if ($custom['site_name'] != $custom_new['site_name']) {
                $checker[] = update_option('site_name', $custom_new['site_name']);
            }
            if ($custom['current_template'] != $custom_new['current_template']) {
                $checker[] = update_option('current_template', $custom_new['current_template']);
            }
            if ($custom['default_group'] != $custom_new['default_group']) {
                $checker[] = update_option('default_group', $custom_new['default_group']);
            }
            if ($custom['login_agent'] !== $custom_new['login_agent'] || $custom['login_ip'] !== $custom_new['login_ip']) {
                $checker[] = update_option('admin_check_login', array('login_ip' => $custom_new['login_ip'] != false, 'login_agent' => $custom_new['login_agent'] != false));
            }
            if ($custom['cookie_login_live'] != $custom_new['cookie_login_live']) {
                $checker[] = update_option('cookie_login_live', $custom_new['cookie_login_live'] * 60);
            }
            $checker = array_merge($checker, actions_zone('settings_checking', $data));
            if (!in_array(false, $checker, true)) {
                push_output_message(array('title' => 'Обновлено!', 'text' => 'Поля успешно обновлены', 'class' => 'alert alert-success'));
            } else {
                push_output_message(array('title' => 'Ошибка!', 'text' => 'Поля заполнены некорректно', 'class' => 'alert alert-danger', 'type' => 'error'));
            }
        } else {
            push_output_message(array('text' => 'Поля не заполнены', 'title' => 'Ошибка!', 'class' => 'alert alert-warning', 'type' => 'warning'));
        }
    }
}
Example #3
0
function action_detblocks_type()
{
    global $DETDB, $PAGE;
    $current = isset($_GET['block_id']) && is_numeric($_GET['block_id']) ? $_GET['block_id'] : null;
    $temp = $block = (object) array('code' => '', 'name' => '', 'description' => '');
    if ($current && ($res = get_detblock_type($current))) {
        $block = set_merge($block, $res);
        $PAGE->title = 'Обновить DET-блок';
    } else {
        $current = null;
    }
    if (isset($_POST['action']) && $_POST['action'] == 'save') {
        $block = set_merge($block, $_POST);
        if ($current) {
            if (update_detblock($current, $block)) {
                push_output_message(array('text' => "DET-блок успешно обновлён", 'title' => 'Успех!', 'class' => 'alert alert-success', 'type' => 'success'));
                $block->ID = $current;
                set_glob_content(array('body' => $block));
                return true;
            }
        } elseif ($ID = add_detblock($block)) {
            push_output_message(array('text' => "DET-блок {$block->code} успешно добавлен!<br />Создана таблица {$DETDB->prefix}detblocks_content_{$ID}", 'title' => 'Успех!', 'class' => 'alert alert-success', 'type' => 'success'));
            set_glob_content(array('body' => $temp));
            return true;
        } else {
            set_glob_content(array('body' => $block));
            return false;
        }
    } elseif (isset($_POST['action']) && $_POST['action'] == 'delete') {
        if (delete_detblock($current)) {
            push_output_message(array('text' => "DET-блок {$block->code} и все его связи успешно удалены!", 'title' => 'Успех!', 'class' => 'alert alert-success', 'type' => 'success'));
            set_glob_content(array('body' => $temp));
            return true;
        }
    }
    if ($current) {
        $block->ID = $current;
    }
    set_glob_content(array('body' => $block));
    return true;
}
Example #4
0
function action_remote_keys_edit()
{
    global $PAGE;
    $current = isset($_GET['key_id']) && is_numeric($_GET['key_id']) ? $_GET['key_id'] : null;
    $temp = $key = (object) array('name' => '', 'key_value' => generate_remote_key(), 'rules' => array());
    if ($current && ($res = get_remote_key($current))) {
        $key = set_merge($key, $res);
        $PAGE->title = 'Обновить ключ';
    } else {
        $current = null;
    }
    if (isset($_POST['save'])) {
        $key = set_merge($key, $_POST);
        if ($key->name && $key->key_value && is_array($key->rules) && count($key->rules) > 0) {
            if ($current) {
                if (update_remote_key($current, $key)) {
                    push_output_message(array('text' => 'Ключ успешно обновлён', 'title' => 'Успех!', 'class' => 'alert alert-success', 'type' => 'success'));
                    $key->ID = $current;
                    set_glob_content(array('body' => $key));
                    return true;
                }
            } elseif (add_remote_key($key)) {
                push_output_message(array('text' => 'Ключ успешно добавлен', 'title' => 'Успех!', 'class' => 'alert alert-success', 'type' => 'success'));
                set_glob_content(array('body' => $temp));
                return true;
            } else {
                set_glob_content(array('body' => $key));
                return false;
            }
        } else {
            push_output_message(array('title' => 'Ошибка!', 'text' => 'Заполните все поля (имя, ключ, хотя одно право)', 'class' => 'alert alert-danger'));
        }
    }
    set_glob_content(array('body' => $key));
    return true;
}
Example #5
0
function action_edit_user()
{
    global $PAGE;
    $current = isset($_GET['user_id']) && is_numeric($_GET['user_id']) ? $_GET['user_id'] : null;
    if (!$current) {
        $PAGE->title = 'Добавить пользователя';
    }
    if (isset($_POST['action']) && $_POST['action'] == 'save') {
        $temp = $res = array('login' => '', 'code' => '', 'display_name' => '', 'mail' => '', 'groups_ID' => array(), 'rules' => array());
        $res = set_merge($res, $_POST);
        if ($password = $_POST['password']) {
            $salt = random_salt();
            $password = crypt(md5($password), $salt);
            $res['password'] = $password;
            $res['salt'] = $salt;
        }
        if ($res['login'] && $res['display_name'] && $res['mail'] && $res['code'] && count($res['groups_ID']) && (isset($res['password']) || $current)) {
            if ($current) {
                if (update_users($res, "WHERE ID='{$current}'")) {
                    push_output_message(array('title' => 'Обновлено!', 'text' => 'Пользователь успешно обновлён', 'class' => 'alert alert-success'));
                } else {
                    push_output_message(array('title' => 'Ошибка!', 'text' => 'Произошла неизвестная ошибка', 'class' => 'alert alert-danger'));
                }
                $res['ID'] = $current;
                set_glob_content(array('body' => (object) $res));
            } else {
                if (add_user($res)) {
                    push_output_message(array('title' => 'Добавлено!', 'text' => 'Пользователь успешно добавлен', 'class' => 'alert alert-success'));
                } else {
                    push_output_message(array('title' => 'Ошибка!', 'text' => 'Произошла неизвестная ошибка', 'class' => 'alert alert-danger'));
                }
            }
        } else {
            push_output_message(array('title' => 'Ошибка!', 'text' => 'Заполните все обязательные поля', 'class' => 'alert alert-danger'));
            set_glob_content(array('body' => (object) $res));
        }
    } elseif (isset($_POST['action']) && $_POST['action'] == 'delete' && $current && delete_user($current)) {
        push_output_message(array('title' => 'Удалено!', 'text' => 'Пользователь успешно удалён', 'class' => 'alert alert-success'));
        set_glob_content(array('body' => (object) $temp));
    } elseif ($current && ($user = get_user($current, 'ID, login, code, display_name, mail, groups_ID, rules', true))) {
        set_glob_content(array('body' => $user));
    }
}
Example #6
0
<?php

//Pages
add_apage(array('code' => 'modules_panel', 'title' => 'Модули', 'rule' => 'admin_modules, admin_settings', 'category' => 'admin', 'priority' => 15, 'function' => function () {
    set_glob_content(array('pagi' => true, 'limit' => 10, 'all' => get_modules_count(), 'handler' => function () {
        global $PAGE;
        return array('body' => get_modules_list($PAGE->content['limit'], $PAGE->content['offset']));
    }));
    get_template('modules/panel.php');
}));
//Others
add_action(array('code' => 'ajax_deactivate_module', 'rule' => 'admin_ajax', 'category' => 'admin', 'function' => function ($params = null) {
    if (isset($params['button']['pre']['value'])) {
        $params = $params['button']['pre']['value'];
    }
    if ($params && deactivate_module($params)) {
        echo ajax_make_res('reload', "Модуль {$params} успешно деактивирован", 'Успех!');
    } else {
        echo ajax_make_res('error', 'Произошла неизвестная ошибка', 'Ошибка!');
    }
}));
add_action(array('code' => 'ajax_activate_module', 'rule' => 'admin_ajax', 'category' => 'admin', 'function' => function ($params = null) {
    if (isset($params['button']['pre']['value'])) {
        $params = $params['button']['pre']['value'];
    }
    if ($params && activate_module($params)) {
        echo ajax_make_res('reload', "Модуль {$params} успешно активирован", 'Успех!');
    } else {
        echo ajax_make_res('error', 'Произошла неизвестная ошибка', 'Ошибка!');
    }
}));
Example #7
0
function action_calendar_event_proc()
{
    global $DETDB, $PAGE;
    $ID = null;
    $custom = array('name' => '', 'place' => '', 'worker' => '', 'date_start' => date('Y-m-d H:i:s'), 'date_end' => '', 'disable_start' => false, 'disable_end' => false);
    if (isset($_GET['event_id'])) {
        $ID = $_GET['event_id'];
        if ($DETDB->isset_cell('calendar_events', $ID)) {
            $PAGE->title = 'Редактировать событие';
            $custom['ID'] = $ID;
        } else {
            $ID = null;
        }
    }
    set_glob_content(array('body' => $custom));
    if (isset($_POST['calendar_event_submit'])) {
        if ($_POST['name'] && $_POST['worker'] && $_POST['date_start']) {
            $_POST['date_start'] = strtotime($_POST['date_start']);
            if (isset($_POST['time_start']) && $_POST['time_start']) {
                $_POST['time_start'] = explode(':', date('H:i', strtotime($_POST['time_start'])));
                for ($i = 0; $i < 1; $i++) {
                    if ($_POST['time_start'][$i][0] == '0') {
                        $_POST['time_start'][$i] = substr($_POST['time_start'][$i], 1);
                    }
                }
                $_POST['date_start'] += (intval($_POST['time_start'][0]) * 60 + intval($_POST['time_start'][1])) * 60;
            }
            $_POST['date_start'] = date('Y-m-d H:i', $_POST['date_start']);
            if (isset($_POST['date_end']) && $_POST['date_end']) {
                $_POST['date_end'] = strtotime($_POST['date_end']);
                if ($_POST['time_end']) {
                    $_POST['time_end'] = explode(':', date('H:i', strtotime($_POST['time_end'])));
                    for ($i = 0; $i < 1; $i++) {
                        if ($_POST['time_end'][$i][0] == '0') {
                            $_POST['time_end'][$i] = substr($_POST['time_start'][$i], 1);
                        }
                    }
                    $_POST['date_end'] += (intval($_POST['time_end'][0]) * 60 + intval($_POST['time_end'][1])) * 60;
                }
                $_POST['date_end'] = date('Y-m-d H:i', $_POST['date_end']);
            }
            $custom = set_merge($custom, $_POST);
            $custom['name'] = secure_text($custom['name']);
            $custom['place'] = secure_text($custom['place']);
            $custom['worker'] = secure_text($custom['worker']);
            $custom['disable_end'] = $custom['disable_end'] ? true : false;
            $custom['disable_start'] = $custom['disable_start'] ? true : false;
            if ($custom['disable_end']) {
                $custom['date_end'] = '';
            }
            $send = $custom;
            unset($send['disable_end'], $send['disable_start']);
            $send['date_params'] = json_val_encode(array($custom['disable_start'], $custom['disable_end']));
            if (strtotime($custom['date_start']) <= strtotime($custom['date_end']) || $custom['date_end'] == '') {
                if (!$ID && $DETDB->insert('calendar_events', $send)) {
                    push_output_message(array('text' => 'Событие успешно добавлено', 'title' => 'Готово!', 'class' => 'alert alert-success', 'type' => 'success'));
                } elseif ($ID && $DETDB->update('calendar_events', $send, "WHERE ID='{$ID}'")) {
                    push_output_message(array('text' => 'Событие успешно обновлено', 'title' => 'Готово!', 'class' => 'alert alert-success', 'type' => 'success'));
                    set_glob_content(array('body' => $custom));
                } else {
                    push_output_message(array('text' => 'Неизвестная ошибка', 'class' => 'alert alert-danger', 'type' => 'error'));
                    set_glob_content(array('body' => $custom));
                }
            } else {
                push_output_message(array('text' => 'Дата начала должна быть меньше или равна дате конца события', 'title' => 'Ошибка!', 'class' => 'alert alert-danger', 'type' => 'error'));
                set_glob_content(array('body' => $custom));
            }
        } else {
            push_output_message(array('text' => 'Заполните все поля', 'title' => 'Ошибка!', 'class' => 'alert alert-warning', 'type' => 'warning'));
            set_glob_content(array('body' => $custom));
        }
    } else {
        if ($ID && ($res = (array) $DETDB->select('calendar_events', '*', true, "WHERE ID='{$ID}'"))) {
            $custom = set_merge($custom, $res);
            if ($res['date_params'] && check_json($res['date_params'])) {
                $res['date_params'] = json_decode($res['date_params'], true);
                if (count($res['date_params']) == 2) {
                    $custom['disable_start'] = $res['date_params'][0];
                    $custom['disable_end'] = $res['date_params'][1];
                }
            }
        }
        set_glob_content(array('body' => $custom));
    }
}