8 isset(
$user) or require
$_SERVER[
'DOCUMENT_ROOT'] .
'/page/404.php';
10 if (empty($_FILES) || !preg_match(
'#\.zip$#', $_FILES[
'file'][
'name'])) {
11 exit(json_encode([
'error' =>
'Ошибка, zip архив не найден']));
15 $res =
$zip->open($_FILES[
'file'][
'tmp_name']);
17 exit(json_encode([
'error' =>
'Ошибка открытия архива']));
24 if (in_array(!
$table, [
'actions',
'modals',
'selects',
'templates',
'pages',
'crontabs'])) {
25 exit(json_encode([
'error' =>
'Ошибка, таблица не существует']));
31 exit(json_encode([
'error' =>
'Ошибка парсинга модели']));
34 $fields =
$dbh->query(
"SHOW COLUMNS FROM $table")->fetchAll(PDO::FETCH_COLUMN);
38 exit(json_encode([
'error' =>
'Ошибка парсинга модели, ключи объектов не совпадают!']));
41 if (empty(
$model->owner_group) || (!in_array(
$model->owner_group,
$user->subordinate_groups) &&
$model->owner_group !=
$user->main_group_id)) {
42 exit(json_encode([
'error' =>
'Недостаточно прав для импорта модели с данной группой владельцем']));
45 if (
$model->owner_group == 1) {
49 if (($models_limit = Wrong\Database\Controller::find(
$model->owner_group,
'id',
'groups')->models_limit) && $models_limit <= Wrong\Rights\Group::count_all_owner_models(
$model->owner_group)) {
50 exit(json_encode([
'error' =>
'Лимит моделей для данной группы исчерпан']));
55 $model->request .=
'-copy';
56 }
while (Wrong\Database\Controller::count(
$model->request,
'request',
$table));
60 $file_data =
$zip->getFromName(basename(
$model->file));
62 exit(json_encode([
'error' =>
'Ошибка парсинга php файла']));
66 $model->file = dirname(
$model->file) .
'/' . basename(
$model->file,
'.php') .
'-copy.php';
67 }
while (Wrong\Database\Controller::count(
$model->file,
'file',
$table));
70 if (!file_exists($dir) && !mkdir($dir, 0755,
true)) {
71 exit(json_encode([
'error' =>
'Ошибка при создании каталога ' . $dir]));
79 $model->name .=
' - копия';
80 }
while (Wrong\Database\Controller::count(
$model->name,
'name',
$table));
89 $sql =
"INSERT INTO $table (" . implode(
', ', array_keys(get_object_vars(
$model))) .
") VALUES (" . implode(
', ', array_map(
function ($item) {
91 }, array_keys(get_object_vars(
$model)))) .
")";
94 foreach (
$model as $key => $value) {
95 $sth->bindValue(
":$key", $value);
98 if ($id =
$dbh->lastInsertId()) {
100 $dbh->query(
"DELETE FROM $table WHERE `id` = $id");
101 exit(json_encode([
'error' =>
'Ошибка импорта']));
103 exit(json_encode([
'result' =>
'ok',
'message' =>
'Импорт успешно завершен!',
'location' =>
'/' .
$table]));
106 exit(json_encode([
'error' =>
'Ошибка импорта']));
if($model->act && $table !='templates') $sql
if(empty($_FILES)||!preg_match('#\.zip$#', $_FILES['file']['name'])) $zip
if(in_array(! $table, ['actions', 'modals', 'selects', 'templates', 'pages', 'crontabs'])) $model
if(!($row=Wrong\Database\Controller::find($_REQUEST['id'], 'id', $_REQUEST['table']))) if(! $user->access() ->write($row, true)) if(!isset($_POST['copy'])) $zipname
setcookie('FROM_UID', $uid, [ 'expires'=> time()+31536000, 'path'=> '/', 'domain'=> $_SERVER['HTTP_HOST'], 'secure'=> Wrong\Start\Env::$e->IS_SECURE, 'httponly'=> false, 'samesite'=> Wrong\Start\Env::$e->IS_SECURE ? 'None' :'Lax']) or setcookie('FROM_UID' $_SERVER['HTTP_HOST']
if(($dbh=Connect::getInstance(true) ->dbh) && $dbh->query("SHOW TABLES") ->fetchAll() && $dbh->query("SELECT COUNT(*) FROM `users`") ->fetchColumn()) if(!empty($_POST)) exit