Initial import
This commit is contained in:
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
namespace app\controllers;
|
||||
|
||||
use app\models\CmsRoles;
|
||||
use app\models\CmsRr;
|
||||
use app\models\Help;
|
||||
use app\models\News;
|
||||
use app\models\UserSession;
|
||||
use app\services\Auth;
|
||||
use app\services\openid\IdServer;
|
||||
|
||||
class AdminGlobalController extends BaseController
|
||||
{
|
||||
public $layout = 'cms';
|
||||
public $userTypeKey = 'admin-global';
|
||||
|
||||
public function beforeAction($action)
|
||||
{
|
||||
$admin = Auth::userAdminGlobal();
|
||||
if (!$admin) {
|
||||
$_SESSION['admin-global-page'] = $_SERVER['REQUEST_URI'];
|
||||
return $this->redirect('/admin-global');
|
||||
} else {
|
||||
if ($admin && $admin->open_id) {
|
||||
$us = UserSession::find()->where(['sub' => $admin->open_id])->one();
|
||||
if (!$us) {
|
||||
Auth::userAdminGlobalLogout();
|
||||
return $this->redirect('/admin-global');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
|
||||
public function actionIndex($page)
|
||||
{
|
||||
return $this->render('index/' . $page);
|
||||
}
|
||||
|
||||
public function actionHelpKeysRemote($page)
|
||||
{
|
||||
if ($page == 'prepare-help') {
|
||||
if (!empty($_GET['help_keys'])) {
|
||||
if ($_GET['help_keys'] == 'active') {
|
||||
$_SESSION['help_keys'] = 1;
|
||||
$message = 'Ключовете за помощна информация са показани';
|
||||
\Yii::$app->flash('success', $message);
|
||||
}
|
||||
if ($_GET['help_keys'] == 'inactive') {
|
||||
if (!empty($_SESSION['help_keys'])) {
|
||||
unset($_SESSION['help_keys']);
|
||||
}
|
||||
$message = 'Ключовете за помощна информация са скрити';
|
||||
\Yii::$app->flash('success', $message);
|
||||
}
|
||||
echo json_encode(['success' => 1]);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
if ($page == 'set-help') {
|
||||
if (!empty($_POST['key'])) {
|
||||
$help = Help::find()->where(['key' => $_POST['key']])->one();
|
||||
if (!$help) {
|
||||
$help = new Help();
|
||||
$help->key = $_POST['key'];
|
||||
if (!empty($_POST['title'])) {
|
||||
$help->title = $_POST['title'];
|
||||
}
|
||||
$help->save();
|
||||
}
|
||||
echo json_encode(['url_to' => '/admin-global/index/help/?o=w&id=' . $help->id]);
|
||||
exit;
|
||||
}
|
||||
echo json_encode(['error' => 1]);
|
||||
exit;
|
||||
}
|
||||
if ($page == 'get-list') {
|
||||
if (!empty($_GET['keys'])) {
|
||||
$helpKeys = Help::find()->where(['IN', 'key', explode(',', $_GET['keys'])])->all();
|
||||
$list = [];
|
||||
foreach ($helpKeys as $helpKey) {
|
||||
$list[] = ['key' => $helpKey->key, 'id' => $helpKey->id];
|
||||
}
|
||||
echo json_encode(['list' => $list]);
|
||||
}
|
||||
}
|
||||
if ($page == 'get-content') {
|
||||
return $this->renderPartial('help-info-content');
|
||||
}
|
||||
if ($page == 'delete-help') {
|
||||
if (!empty($_POST['id'])) {
|
||||
$help = Help::findOne($_POST['id']);
|
||||
if ($help) {
|
||||
$help->delete();
|
||||
\Yii::$app->flash('success', 'Помощната информация беше изтрита');
|
||||
echo json_encode(['url_to' => '/admin-global/index/help/']);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
public function actionWebPortal($page)
|
||||
{
|
||||
return $this->render('web-portal/' . $page);
|
||||
}
|
||||
|
||||
public function actionTour($page)
|
||||
{
|
||||
return $this->render('tour/' . $page);
|
||||
}
|
||||
|
||||
|
||||
public function actionMobileApp($page)
|
||||
{
|
||||
return $this->render('mobile-app/' . $page);
|
||||
}
|
||||
|
||||
public function actionNomenclature($page)
|
||||
{
|
||||
return $this->render('nomenclature/' . $page);
|
||||
}
|
||||
|
||||
public function actionNomenclatureRegister($page)
|
||||
{
|
||||
return $this->render('nomenclature-register/' . $page);
|
||||
}
|
||||
|
||||
|
||||
public function actionProducts($page)
|
||||
{
|
||||
return $this->render('products/' . $page);
|
||||
}
|
||||
|
||||
public function actionOrders($page)
|
||||
{
|
||||
return $this->render('orders/' . $page);
|
||||
}
|
||||
|
||||
public function actionUser($page)
|
||||
{
|
||||
return $this->render('user/' . $page);
|
||||
}
|
||||
|
||||
|
||||
public function actionRoleRights()
|
||||
{
|
||||
if (!empty($_GET['role_id'])) {
|
||||
|
||||
$roleRights = CmsRr::find()->innerJoinWith('right')->where(['role_id' => $_GET['role_id'], 'is_active' => 1])->all();
|
||||
$rightsIds = [];
|
||||
foreach ($roleRights as $rr) {
|
||||
$rightsIds[] = $rr->right_id;
|
||||
}
|
||||
|
||||
return $this->asJson(['rights' => $rightsIds]);
|
||||
}
|
||||
return $this->asJson([]);
|
||||
}
|
||||
|
||||
public function actionLogout()
|
||||
{
|
||||
$admin = Auth::userAdminGlobal();
|
||||
|
||||
if ($admin->open_id) {
|
||||
$q = "";
|
||||
if (!empty($_SESSION['id_token_hint'])) {
|
||||
$redirect = \Yii::$app->params['cms'] . '/partner-register-login/';
|
||||
$q = '?id_token_hint=' . $_SESSION['id_token_hint'] . '&post_logout_redirect_uri=' . $redirect;
|
||||
}
|
||||
header('Location: ' . \Yii::$app->params['sso_logout_url'] . $q);
|
||||
exit;
|
||||
} else {
|
||||
Auth::userAdminGlobalLogout();
|
||||
return $this->redirect('/cms-admin');
|
||||
}
|
||||
}
|
||||
|
||||
public function actionCheck()
|
||||
{
|
||||
echo password_hash('marko84', PASSWORD_DEFAULT);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user