id) header('Location: ' . explode('?', $_SERVER['REQUEST_URI'])[0]); } } if ($_SERVER['REQUEST_METHOD'] == 'POST') { switch ($_GET['o']) { case 'w': if (empty($_GET['id']) && !UserRight::add()) die('You have no permission to operate'); if (!empty($_GET['id']) && !UserRight::edit()) die('You have no permission to operate'); if ($validation) Validate::defaultValidation($validation((object)$_POST, (object)$_FILES)); if ($dataModel) { $postService((object)$_POST, $dataModel); } else { $postService((object)$_POST); } break; case 'u': // UPDATE STATUS foreach (['model', 'id', 'key'] as $p) { if (empty($_POST[$p])) { echo json_encode(['error' => 'Missing parameter: ' . $p]); exit; } } /** * @var $modelStr \yii\db\ActiveRecord; * @var $remoteUpdateModel \yii\db\ActiveRecord; */ $modelStr = $_POST['model']; $remoteUpdateModel = $modelStr::findOne($_POST['id']); $remoteUpdateModel->{$_POST['key']} = $_POST['value'] == 'null' ? NULL : 1; if ($remoteUpdateModel->hasProperty('publish_date') && $_POST['key'] == 'is_active' && $_POST['value'] == 1) { if ($remoteUpdateModel->{'publish_date'}) { $dateRecorded = strtotime($remoteUpdateModel->{'publish_date'}); $dateNow = strtotime(date('Y-m-d')); if ($dateNow > $dateRecorded) { $remoteUpdateModel->{'publish_date'} = date('Y-m-d H:i:s'); } } else { $remoteUpdateModel->{'publish_date'} = date('Y-m-d H:i:s'); } } $remoteUpdateModel->save(); if ($remoteUpdateModel->hasProperty('article_key')) \app\models\Articles::updateArticle($remoteUpdateModel); echo json_encode(['successMsg' => Yii::t('cms', 'The status has been successfully updated')]); exit; break; case 'd': if (isset($_POST['ids']) && isset($_POST['model'])) { $ids = json_decode($_POST['ids']); /** @var \yii\db\ActiveRecord $model */ $model = $_POST['model']; $table = $model::getTableSchema()->name; $dataToDelete = $model::find()->where(['IN', 'id', $ids])->all(); foreach ($dataToDelete as $dtd) { if ($dtd->hasProperty('media_key') && !empty($dtd->media_key)) { FileCms::deleteAll(['media_key' => $dtd->media_key]); $raw = $_SERVER['DOCUMENT_ROOT'] . '/_files/raw/' . $dtd->media_key; $public = $_SERVER['DOCUMENT_ROOT'] . '/_files/ready/' . $dtd->media_key; if (file_exists($raw)) system("rm -rf " . escapeshellarg($raw)); if (file_exists($public)) system("rm -rf " . escapeshellarg($public)); } \app\models\History::deleteAll(['table_name' => $table, 'history_id' => $dtd->id]); if ($dtd->hasProperty('article_key')) { $articleForDelete = \app\models\Articles::find()->where(['key' => $dtd->{'article_key'}])->one(); if ($articleForDelete) $articleForDelete->delete(); } $dtd->delete(); } $count = sizeof($ids); $msg = $count == 1 ? '{count} record has been successfully deleted' : '{count} records have been successfully deleted'; if (empty($_POST['noFlash'])) Yii::$app->flash('success', Yii::t('cms', $msg, ['count' => $count])); echo json_encode(['success' => true, 'message' => Yii::t('cms', $msg, ['count' => $count])]); exit; } } exit; } $controller = Yii::$app->controller->id; Includes::top($top['title'], $top['data'], $top['title_edit'] ?? null); Includes::setTabs($tabs); if ($model) { $modelInfoKey = strtolower(substr(strrchr($model, "\\"), 1)); echo '
'; } echo $this->render('/' . $controller . '/' . $writeView, ['model' => $dataModel]); ?>