From 8e10948f82471ef9a239254d27fbbea70b416272 Mon Sep 17 00:00:00 2001 From: themohooks <81331307+themohooks@users.noreply.github.com> Date: Thu, 18 Jul 2024 15:10:47 +0300 Subject: [PATCH] user admin edit --- app/Controllers/Api/Register.php | 2 +- app/Core/Routes.php | 2 +- views/pages/Admin/UserEdit.php | 73 ++++++++++++++++++++++++-------- 3 files changed, 58 insertions(+), 19 deletions(-) diff --git a/app/Controllers/Api/Register.php b/app/Controllers/Api/Register.php index 1eb0bf0..31441d1 100644 --- a/app/Controllers/Api/Register.php +++ b/app/Controllers/Api/Register.php @@ -98,7 +98,7 @@ class Register ) ); - DB::query('INSERT INTO users VALUES (\'0\', :username, :email, :password, :photourl, 5, 0, :online, :content)', array(':username' => ltrim($username), ':password' => password_hash(ltrim($password), PASSWORD_BCRYPT), ':photourl'=>'/static/img/avatar.png', ':email' => $email, ':content' => $content, ':online'=>time())); + DB::query('INSERT INTO users VALUES (\'0\', :username, :email, :password, :photourl, 5, 0, :online, 0, :content)', array(':username' => ltrim($username), ':password' => password_hash(ltrim($password), PASSWORD_BCRYPT), ':photourl'=>'/static/img/avatar.png', ':email' => $email, ':content' => $content, ':online'=>time())); $cstrong = True; $token = GenerateRandomStr::gen_uuid(); $user_id = DB::query('SELECT id FROM users WHERE username=:username', array(':username' => $username))[0]['id']; diff --git a/app/Core/Routes.php b/app/Core/Routes.php index fabcd62..f885024 100644 --- a/app/Core/Routes.php +++ b/app/Core/Routes.php @@ -41,7 +41,7 @@ class Routes Router::get('/api/photo/vote', 'ApiController@photovote'); Router::get('/api/photo/comment/rate', 'ApiController@photocommentvote'); - Router::get('/admin', 'AdminController@index'); + Router::any('/admin', 'AdminController@index'); Router::get('/logout', 'MainController@logout'); Router::get('/404', 'ExceptionRegister@notfound'); diff --git a/views/pages/Admin/UserEdit.php b/views/pages/Admin/UserEdit.php index ed0025d..d983c96 100644 --- a/views/pages/Admin/UserEdit.php +++ b/views/pages/Admin/UserEdit.php @@ -1,13 +1,52 @@ i('id') === null) { die('Пользователь не найден'); } +// Функция для обновления JSON и возврата обновленных данных +function updateJson($data, $key, $value) { + $data[$key] = $value; + return $data; +} + +if (isset($_POST['subbtn'])) { + // Получение данных из формы + $premoderation = $_POST['premoderation']; + $accountstatus = $_POST['accountstatus']; + $admin = $_POST['admin']; + + // Предполагаем, что у вас есть user_id, полученный из сессии или другого источника + $userId = $_GET['user_id']; + + // Получение текущего JSON из базы данных + $currentJson = $user->i('content'); + + if (!empty($currentJson)) { + $currentJson = json_decode($currentJson, true); + + // Обновление JSON данных + $updatedJson = updateJson($currentJson, 'premoderation', $premoderation); + $updatedJsonString = json_encode($updatedJson, JSON_PRETTY_PRINT); + + // Обновление базы данных + DB::query("UPDATE users SET status = ?, admin = ?, content = ? WHERE id = ?", [ + $accountstatus, + $admin, + $updatedJsonString, + $userId + ]); + + echo "Данные успешно обновлены."; + } else { + echo "Ошибка: JSON данные не найдены."; + } +} + ?> -
\ No newline at end of file