Skip to content

Commit

Permalink
Рефакторинг модуля админ
Browse files Browse the repository at this point in the history
  • Loading branch information
n2ref committed Sep 3, 2021
1 parent 38d296b commit 20f96d6
Show file tree
Hide file tree
Showing 40 changed files with 1,372 additions and 1,285 deletions.
6 changes: 1 addition & 5 deletions html/default/html/panel.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<div class="core-panel core-panel-default core-panel-[TYPE]-[POSITION]" id="core-panel-[RESOURCE]">
<!-- BEGIN title -->
<div class="core-panel-heading">
<!-- BEGIN back_url -->
<a href="[BACK_URL]" class="btn btn-sm btn-default">
<i class="fa fa-arrow-left"></i>
</a>
<!-- END back_url -->
<!-- BEGIN back_url --><!-- END back_url -->
[TITLE]
<!-- BEGIN description -->
<div class="core-panel-subtitle">[DESCRIPTION]</div>
Expand Down
149 changes: 90 additions & 59 deletions inc/CoreController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<?php

use Laminas\Session\Container as SessionContainer;
use Core2\Mod\Admin;

use Core2\Settings as Settings;
use Core2\Modules as Modules;
use Core2\Roles as Roles;
use Core2\Enum as Enum;
use Core2\InstallModule as Install;


require_once 'classes/Common.php';
require_once 'classes/class.list.php';
require_once 'classes/class.edit.php';
Expand All @@ -8,21 +18,12 @@

require_once 'Interfaces/File.php';

require_once DOC_ROOT . "core2/mod/admin/InstallModule.php";
require_once DOC_ROOT . "core2/mod/admin/gitlab/Gitlab.php";
require_once DOC_ROOT . "core2/mod/admin/User.php";
require_once DOC_ROOT . "core2/mod/admin/Settings.php";
require_once DOC_ROOT . "core2/mod/admin/Modules.php";
require_once DOC_ROOT . "core2/mod/admin/Roles.php";
require_once DOC_ROOT . "core2/mod/admin/Enum.php";

use Laminas\Session\Container as SessionContainer;
use Core2\User as User;
use Core2\Settings as Settings;
use Core2\Modules as Modules;
use Core2\Roles as Roles;
use Core2\Enum as Enum;
use Core2\InstallModule as Install;
require_once DOC_ROOT . "core2/mod/admin/classes/modules/InstallModule.php";
require_once DOC_ROOT . "core2/mod/admin/classes/modules/Gitlab.php";
require_once DOC_ROOT . "core2/mod/admin/classes/settings/Settings.php";
require_once DOC_ROOT . "core2/mod/admin/classes/modules/Modules.php";
require_once DOC_ROOT . "core2/mod/admin/classes/roles/Roles.php";
require_once DOC_ROOT . "core2/mod/admin/classes/enum/Enum.php";


/**
Expand All @@ -37,22 +38,24 @@
*/
class CoreController extends Common implements File {

const RP = '187777f095b3006d4dbdf3b3548ac407';
protected $tpl = '';
protected $theme = 'default';
const RP = '187777f095b3006d4dbdf3b3548ac407';
protected $tpl = '';
protected $theme = 'default';


/**
* CoreController constructor.
*/
public function __construct() {
parent::__construct();
$this->module = 'admin';
$this->path = 'core2/mod/';
$this->path .= !empty($this->module) ? $this->module . "/" : '';
if (!empty($this->config->theme)) {
$this->theme = $this->config->theme;
}

$this->module = 'admin';
$this->path = 'core2/mod/';
$this->path .= ! empty($this->module) ? $this->module . "/" : '';

if ( ! empty($this->config->theme)) {
$this->theme = $this->config->theme;
}
}


Expand All @@ -61,7 +64,9 @@ public function __construct() {
* @param array $arg
*/
public function __call ($k, $arg) {
if (!method_exists($this, $k)) return;
if ( ! method_exists($this, $k)) {
return;
}
}


Expand All @@ -76,7 +81,7 @@ public function setVars($var, $value) {

/**
* @throws Exception
* @return void
* @return string
*/
public function action_index() {

Expand All @@ -88,7 +93,9 @@ public function action_index() {
}
}

if ( ! $this->auth->ADMIN) throw new Exception(911);
if ( ! $this->auth->ADMIN) {
throw new Exception(911);
}


if (isset($_GET['data'])) {
Expand All @@ -104,6 +111,7 @@ public function action_index() {
return json_encode(['status' => 'success']);
break;
}

} catch (Exception $e) {
return json_encode([
'status' => 'error',
Expand All @@ -116,7 +124,7 @@ public function action_index() {
$tab = new tabs('mod');
$tab->beginContainer($this->_("События аудита"));

$this->printJsModule('admin', '/js/admin.index.js');
$this->printJsModule('admin', '/assets/js/admin.index.js');

try {
$changedMods = $this->checkModulesChanges();
Expand Down Expand Up @@ -152,7 +160,10 @@ public function action_index() {
* @return void|string
*/
public function action_modules() {
if (!$this->auth->ADMIN) throw new Exception(911);

if ( ! $this->auth->ADMIN) {
throw new Exception(911);
}

//проверка наличия обновлений для модулей
if ($_SERVER['REQUEST_METHOD'] == 'PUT') {
Expand Down Expand Up @@ -201,7 +212,7 @@ public function action_modules() {
if (!empty($_POST['install_from_repo'])) {
$mods->install = ['repo' => $_POST['repo'], 'install_from_repo' => $_POST['install_from_repo']];
}
$mods->dispatch();
return $mods->dispatch();
}


Expand All @@ -210,11 +221,12 @@ public function action_modules() {
* @throws Exception
* @return void
*/
public function action_switch(){
public function action_switch() {

try {
if (!isset($_POST['data'])) {
throw new Exception($this->translate->tr('Произошла ошибка! Не удалось получить данные'));
}
if ( ! isset($_POST['data'])) {
throw new Exception($this->translate->tr('Произошла ошибка! Не удалось получить данные'));
}

$res = explode('.', $_POST['data']);

Expand Down Expand Up @@ -260,7 +272,7 @@ public function action_delete(Array $params)
$sessData = $sess->$resource;
$deleteKey = $sessData['deleteKey'];
if (!$deleteKey) throw new Exception($this->translate->tr("Не удалось определить параметры удаления"), 13);
list($table, $refid) = explode(".", $deleteKey);
[$table, $refid] = explode(".", $deleteKey);
if (!$table || !$refid) throw new Exception($this->translate->tr("Не удалось определить параметры удаления"), 13);

if (($this->checkAcl($resource, 'delete_all') || $this->checkAcl($resource, 'delete_owner'))) {
Expand Down Expand Up @@ -352,11 +364,15 @@ public function action_seq () {


/**
* Субмодуль Пользователи
* Пользователи
* @throws Exception
* @return void
* @return string
*/
public function action_users () {
public function action_users(): string {

require_once __DIR__ . "/../mod/admin/classes/users/View.php";
require_once __DIR__ . "/../mod/admin/classes/users/Users.php";
require_once __DIR__ . "/../mod/admin/classes/users/User.php";

if ( ! $this->auth->ADMIN) {
throw new Exception(911);
Expand All @@ -368,8 +384,8 @@ public function action_users () {
switch ($_GET['data']) {
// Войти под пользователем
case 'login_user':
$user = new User();
$user->loginUser($_POST['user_id']);
$users = new Admin\Users\Users();
$users->loginUser($_POST['user_id']);

return json_encode([
'status' => 'success',
Expand All @@ -385,23 +401,38 @@ public function action_users () {
}
}

$app = "index.php?module=admin&action=users";
$view = new Admin\Users\View();
$panel = new Panel();

$user = new User();
$tab = new tabs('users');
$title = $this->translate->tr("Справочник пользователей системы");

if (isset($_GET['edit']) && $_GET['edit'] === '0') {
$user->create();
$title = $this->translate->tr("Создание нового пользователя");
ob_start();

} elseif ( ! empty($_GET['edit'])) {
$user->get($_GET['edit']);
$title = sprintf($this->translate->tr('Редактирование пользователя "%s"'), $user->u_login);
try {
if (isset($_GET['edit'])) {
if (empty($_GET['edit'])) {
$panel->setTitle($this->_("Создание нового пользователя"), '', $app);
echo $view->getEdit($app);

} else {
$user = new Admin\Users\User($_GET['edit']);
$panel->setTitle($user->u_login, $this->_('Редактирование пользователя'), $app);
echo $view->getEdit($app, $user);
}


} else {
$panel->setTitle($this->_("Справочник пользователей системы"));
echo $view->getList($app);
}

} catch (\Exception $e) {
echo Alert::danger($e->getMessage(), 'Ошибка');
}

$tab->beginContainer($title);
echo $user->dispatch();
$tab->endContainer();

$panel->setContent(ob_get_clean());
return $panel->render();
}


Expand Down Expand Up @@ -601,9 +632,9 @@ public function feedbackForm() {
}
}
}
$this->printJs("core2/mod/admin/feedback.js", true);
$this->printJs("core2/mod/admin/assets/js/feedback.js", true);
require_once 'classes/Templater2.php';
$tpl = new Templater2("core2/mod/admin/html/feedback.tpl");
$tpl = new Templater2("core2/mod/admin/assets/html/feedback.html");
$tpl->assign('</select>', $selectMods . '</select>');
return $tpl->parse();
}
Expand Down Expand Up @@ -704,7 +735,7 @@ public function userProfile() {
*/
public function action_roles() {
if (!$this->auth->ADMIN) throw new Exception(911);
$this->printCss($this->path . "role.css");
$this->printCss($this->path . "assets/css/role.css");
$roles = new Roles();
$roles->dispatch();
}
Expand All @@ -728,8 +759,8 @@ public function action_enum()
$title = $this->_("Создание нового справочника");
}
$tab->beginContainer($title);
$this->printJs("core2/mod/admin/enum.js");
$this->printJs("core2/mod/admin/mod.js");
$this->printJs("core2/mod/admin/assets/js/enum.js");
$this->printJs("core2/mod/admin/assets/js/mod.js");
if (!empty($_GET['edit'])) {
echo $enum->editEnum($_GET['edit']);
$tab->beginContainer(sprintf($this->translate->tr("Перечень значений справочника \"%s\""), $this->dataEnum->find($_GET['edit'])->current()->name));
Expand Down Expand Up @@ -757,7 +788,7 @@ public function action_monitoring() {
if (!$this->auth->ADMIN) throw new Exception(911);
try {
$app = "index.php?module=admin&action=monitoring";
require_once $this->path . 'monitoring.php';
require_once $this->path . 'classes/monitoring/monitoring.php';
} catch (Exception $e) {
echo Alert::danger($e->getMessage());
}
Expand All @@ -771,7 +802,7 @@ public function action_monitoring() {
public function action_audit() {
if (!$this->auth->ADMIN) throw new Exception(911);
$app = "index.php?module=admin&action=audit";
require_once $this->path . 'audit/Audit.php';
require_once $this->path . 'classes/audit/Audit.php';
$audit = new \Core2\Audit();
$tab = new tabs('audit');

Expand Down
Loading

0 comments on commit 20f96d6

Please sign in to comment.