getRightsIds(); } } echo json_encode(['rights' => $rights]); exit; } public function actionGetHistory() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $table = $_POST['table']; $id = $_POST['id']; $data = History::find()->where(['table_name' => $table, 'history_id' => $id]) ->orderBy(['date_time' => SORT_DESC])->all(); $historyData = []; foreach ($data as $d) { $row = [ '
' . ($d->action == 1 ? 'Създаване' : 'Редакция') . '
', '
' . $d->user . '
', '
' . date('d.m.Y H:i', strtotime($d->date_time)) . '
' ]; $historyData[] = implode('', $row); } if (sizeof($historyData) == 0) { $historyData[] = 'Историята е празна'; } return $this->asJson($historyData); } return $this->asJson([]); } public function actionNewArticlePosition() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!empty($_POST['group_id'])) { $model = Positions::findOne($_POST['group_id']); if ($model) { $newPosition = new Positions(); $newPosition->group_id = $model->id; $newPosition->order_index = $model->getNextOrderIndex(); $newPosition->save(); \Yii::$app->flash('success', 'Позицията е добавена успешно'); echo json_encode(['success' => true]); exit; } } \Yii::$app->flash('error', 'Възникна грешка, позицията не беше добавена'); echo json_encode(['success' => false]); exit; } exit; } public function actionNewSubCategory() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!empty($_POST['parent_id'])) { $model = Categories::findOne($_POST['parent_id']); if ($model) { $orderIndex = 0; if ($model->id) { $last = Categories::find()->where(['parent_id' => $model->id])->orderBy(['order_index' => SORT_DESC])->one(); if ($last) $orderIndex = $last->order_index; } $subCategory = new Categories(); $subCategory->parent_id = $model->id; $subCategory->order_index = ++$orderIndex; $subCategory->save(); echo json_encode([ 'success' => true, 'id' => $subCategory->id, 'orderIndex' => $subCategory->order_index, 'msg' => 'Подкатегорията е добавена успешно' ]); exit; } } echo json_encode(['success' => false, 'msg' => 'Възникна грешка, подкатегорията не беше добавена']); exit; } exit; } public function actionNewCommonFieldOption() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!empty($_POST['parent_id'])) { $model = CommonFields::findOne($_POST['parent_id']); if ($model) { $orderIndex = 0; if ($model->id) { $last = CommonFields::find()->where(['parent_id' => $model->id])->orderBy(['order_index' => SORT_DESC])->one(); if ($last) $orderIndex = $last->order_index; } $commonFieldOption = new CommonFields(); $commonFieldOption->parent_id = $model->id; $commonFieldOption->order_index = ++$orderIndex; $commonFieldOption->save(); echo json_encode([ 'success' => true, 'id' => $commonFieldOption->id, 'orderIndex' => $commonFieldOption->order_index, 'msg' => 'Опцията е добавена успешно' ]); exit; } } echo json_encode(['success' => false, 'msg' => 'Възникна грешка, полето не беше добавено']); exit; } exit; } public function actionNewDynamicField() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!empty($_POST['ot_id'])) { $model = ObjectTemplate::findOne($_POST['ot_id']); if ($model) { $orderIndex = ObjectTemplateField::getNextOrderIndex($_POST['ot_id']); $objectType = new ObjectTemplateField(); $objectType->ot_id = $model->id; $objectType->order_index = $orderIndex; $objectType->save(); echo json_encode([ 'success' => true, 'id' => $objectType->id, 'orderIndex' => $objectType->order_index, 'msg' => 'Динамичното поле е добавена успешно' ]); exit; } } echo json_encode(['success' => false, 'msg' => 'Възникна грешка, динамичното поле не беше добавено']); exit; } exit; } public function actionUpdateCategoryIndexes() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { echo json_encode($_POST); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $indexes = json_decode($_POST['indexes']); foreach ($indexes as $index) { $file = Categories::findOne($index->id); $file->order_index = $index->order_index; $file->save(); } echo json_encode(['success' => true]); } exit; } public function actionUpdatePositionsIndexes() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { echo json_encode($_POST); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $indexes = json_decode($_POST['indexes']); foreach ($indexes as $index) { $position = Positions::findOne($index->id); $position->order_index = $index->order_index; $position->save(); } echo json_encode(['success' => true]); } exit; } public function actionUpdateCommonFieldIndexes() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { echo json_encode($_POST); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $indexes = json_decode($_POST['indexes']); foreach ($indexes as $index) { $file = CommonFields::findOne($index->id); $file->order_index = $index->order_index; $file->save(); } echo json_encode(['success' => true]); } exit; } public function actionUpdateDynamicFieldsIndexes() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $indexes = json_decode($_POST['indexes']); foreach ($indexes as $index) { $model = ObjectTemplateField::findOne($index->id); $model->order_index = $index->order_index; $model->save(); } echo json_encode(['success' => true]); } exit; } public function actionUpdateDynamicTypeValues() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $option = null; if (!empty($_POST['id'])) { $option = ObjectTemplateField::findOne($_POST['id']); if (empty($_POST['remove'])) { //UPDATE if (!empty($_POST['bg'])) $option->name = $_POST['bg']; if (!empty($_POST['en'])) $option->ts_en_name = $_POST['en']; $option->save(); } else { //DELETE $option->delete(); } } //CREATE else if (!empty($_POST['parent_id'])) { $model = ObjectTemplateField::findOne($_POST['parent_id']); if ($model) { $option = new ObjectTemplateField(); if (!empty($_POST['bg'])) $option->name = $_POST['bg']; if (!empty($_POST['en'])) $option->ts_en_name = $_POST['en']; $option->parent_id = $_POST['parent_id']; $option->save(); } } $response = ['success' => true]; if ($option) { $response['id'] = $option->id; } echo json_encode($response); } exit; } public function actionGetArticlePositions() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $positionGroups = []; foreach (Positions::find()->where(['IS', 'group_id', null])->all() as $group) { $positions = []; foreach ($group->positions as $position) { $positions[] = [ 'id' => $position->id, 'checked' => $position->{'position_article_key'} == $_POST['article_key'], 'checked_fa' => !empty($position->{'position_article_key'}) && $position->{'position_article_key'} != $_POST['article_key'] ]; } $positionGroups[] = [ "group" => $group->group_name, 'positions' => $positions ]; } echo json_encode($positionGroups); } exit; } public function actionUpdateArticlePosition() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $position = Positions::findOne($_POST['id']); if ($position) { if ($_POST['checked'] == "true") { $position->{'position_article_key'} = $_POST['article_key']; } else { $position->{'position_article_key'} = NULL; } $position->save(); echo json_encode(['message' => 'Позицията е актуализирана успешно']); } } exit; } public function actionUpdateListIndexes() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { echo json_encode(['message' => 'Позицията е актуализирана успешно']); } exit; } public function actionGetObjectTypes() { //return $this->asJson(ObjectTemplate::getResponseData()); } public function actionGetAutocompleteObjects() { if (!empty($_GET['q'])) { $ekatte = RegisterObjects::find()->where(['LIKE', 'name', $_GET['q'] . '%', false])->limit(10)->all(); $data = []; foreach ($ekatte as $row) { $data[] = [ 'object_id' => $row->id, 'name' => '
' . $row->name . '
', ]; } return $this->asJson($data); } if (!empty($_GET['settlement_id'])) { $row = RegisterObjects::findOne($_GET['settlement_id']); if ($row) return $this->asJson([ 'object_id' => $row->id, 'name' => $row->name . '', ]); die('Wrong settlement_id'); } die('Missing get parameter "q" or "settlement_id"'); } public function actionGetExpositionObjects() { if (!empty($_GET['exposition_remote_list'])) { $id = $_GET['exposition_remote_list']; $exposition = Expositions::findOne($id); $html = ''; foreach ($exposition->objectList as $expositionObject) { $html .= ''; } echo $html; exit; } } public function actionAddObjectToExposition() { $p = (object)$_POST; if (!empty($p->{'exposition_id'}) && !empty($p->{'object_id'}) && empty($p->{'delete'})) { $eo = ExpositionsObjects::find()->where(['exposition_id' => $p->{'exposition_id'}, 'object_id' => $p->{'object_id'}])->one(); if (!$eo) { $eo = new ExpositionsObjects(); $eo->object_id = $p->{'object_id'}; $eo->exposition_id = $p->{'exposition_id'}; $eo->save(); echo json_encode(['success' => 1, 'message' => '']); exit; } else { echo json_encode(['error' => 1, 'message' => 'Object already added']); exit; } } } public function actionRemoveObjectFromExposition() { $p = (object)$_POST; if (!empty($p->{'exposition_id'}) && !empty($p->{'object_id'})) { $eo = ExpositionsObjects::find()->where(['exposition_id' => $p->{'exposition_id'}, 'object_id' => $p->{'object_id'}])->one(); if ($eo) $eo->delete(); echo json_encode(['success' => 1, 'message' => 'Object is removed']); exit; } } public function actionCheckActivity() { $admin = Auth::userAdminGlobal(); if ($admin && $admin->open_id) { $us = UserSession::find()->where(['sub' => $admin->open_id])->one(); if (!$us) { Auth::userAdminGlobalLogout(); return $this->asJson(['status' => 'inactive', 'redirect' => '/admin-global/']); } else { return $this->asJson(['status' => 'active']); } } $partner = Auth::userPartner(); if ($partner && $partner->open_id) { $us = UserSession::find()->where(['sub' => $partner->open_id])->one(); if (!$us) { Auth::userPartnerLogout(); return $this->asJson(['status' => 'inactive', 'redirect' => '/partner/']); } else { return $this->asJson(['status' => 'active']); } } } public function actionGetIp() { echo $_SERVER['REMOTE_ADDR']; exit; } 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 actionChangeLocale() { if (!empty($_POST['lg'])) { setcookie('cookie_lg', $_POST['lg'], time() + (86400 * 1), "/"); echo json_encode(['success' => true, 'lg' => $_POST['lg']]); exit; } } public function actionUpdateQrValidators() { if (!empty($_POST['partner_id'])) { $partner_id = $_POST['partner_id']; if(!empty($_POST['validators'])) { $validators = explode(',', $_POST['validators']); /** @var \app\models\QrValidators[] $added */ $added = QrValidators::find()->where(['partner_id' => $partner_id])->all(); $current = []; //delete; foreach ($added as $v) { $current[] = $v->user_id; if (!in_array($v->user_id, $validators)) { $v->delete(); } } //add new foreach ($validators as $id) { if (!in_array($id, $current)) { $qrv = new QrValidators(); $qrv->partner_id = $partner_id; $qrv->user_id = $id; $qrv->save(); } } echo json_encode(['success' => 1]); } else { $added = QrValidators::find()->where(['partner_id' => $partner_id])->all(); foreach ($added as $item) { $item->delete(); } echo json_encode(['success' => 1]); } //add new } exit; } }