From 277a27d7cab67a8bdfe21e96cbd9a52b21436b8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Cervi=C3=B1o?= Date: Mon, 21 Nov 2022 15:31:40 -0300 Subject: [PATCH] 21/11/2022 15:31hs --- index.php | 21 +++++++++++++++++++++ scripts/directives.php | 34 ++++++++++++++++++++++++++++++++++ scripts/filesystem.php | 7 +++++++ scripts/verifyData.php | 3 +++ 4 files changed, 65 insertions(+) diff --git a/index.php b/index.php index 14dee68..585a21a 100644 --- a/index.php +++ b/index.php @@ -607,6 +607,27 @@ echo json_encode($responses->errorTypical); return; } + if (isset($_POST['editImageDirective'])) { + if ($verifyData->issetDataPost(array('username', 'password', 'idEdit'))) { + $verifyData->checkDataTypes( + $_POST['username'], 'string-base64', + $_POST['password'], 'string-base64', + $_POST['idEdit'], 'number' + //$_FILES['image']['tmp_name'], 'file' + ); + + $idDirective = $directives->getDirectiveId($_POST['username'], $_POST['password']); + if (is_object($idDirective)) { + echo json_encode($idDirective); + return; + } + $edit = $directives->modifyImage($idDirective, $_POST['idEdit']); + echo json_encode($edit); + return; + } + echo json_encode($responses->errorTypical); + return; + } // Preferences if (isset($_POST['getPreferencesDirective'])) { diff --git a/scripts/directives.php b/scripts/directives.php index a2ed83e..9a9235a 100644 --- a/scripts/directives.php +++ b/scripts/directives.php @@ -80,6 +80,40 @@ function verifyCont($edit1) { return (strlen($edit1) != 0)? ",": ""; } return $responses->error1Data(array($idDirective, $idModify, $name, $position, $dni, $username, $password, $permissionLevel)); } } + public function modifyImage($idDirective, $idModify) { + $responses = new Responses(); + try { + $db = new DBSystem(); + $records = new RecordSystem(); + $permission = new DirectivesPermissionSystem(); + /* ################################################## */ + $verify = $permission->verify($idDirective, 3); + if (is_object($verify)) return $verify; + if (!$verify) return $responses->errorPermission; + /* ################################################## */ + $verify2 = $permission->compare($idDirective, $idModify); + if (is_object($verify2)) return $verify2; + /* ################################################## */ + $fileSystem = new FileSystem(); + $verifyData = new VerifyData(); + /* ################################################## */ + $image = ""; + if (!$verifyData->issetFilePost('image') && $verifyData->issetPosts(array('removeImage'))) { + $image = base64_encode('default-admin.png'); + } else { + $image = base64_encode($fileSystem->createDirectiveImage($_FILES['image'])); + } + $consult = $db->Query("UPDATE `directives` SET `picture`='$image' WHERE `id`=$idModify"); + if ($consult) { + $usernameDirective = base64_decode($this->getData_system($idDirective)['datas']['username']); + $records->create($idDirective, "El directivo @$usernameDirective edito la imagen de perfil del directivo #$idModify.", 1, "Editar directivo", "Directivos"); + return $responses->good; + } + return $responses->error2; + } catch (\Throwable $th) { + return $responses->error1Data($th); + } + } public function open(string $username, string $password) { $responses = new Responses(); try { diff --git a/scripts/filesystem.php b/scripts/filesystem.php index e627385..6e84b74 100644 --- a/scripts/filesystem.php +++ b/scripts/filesystem.php @@ -16,6 +16,13 @@ public function createStudentImage2($file) { $copy = imagewebp($process, './image/'.$newName, 70); return ($copy)? $newName: 'default.png'; } + public function createDirectiveImage($file) { + $ImgProcess = new ProcessImageSystem(); + $newName = 'directive_'.random_int(11111111, 99999999).'.webp'; + $process = $ImgProcess->process3($file['tmp_name'], 512, 512); + $copy = imagewebp($process, './image/'.$newName, 70); + return ($copy)? $newName: 'default-admin.png'; + } } ?> \ No newline at end of file diff --git a/scripts/verifyData.php b/scripts/verifyData.php index b4df799..58dd812 100644 --- a/scripts/verifyData.php +++ b/scripts/verifyData.php @@ -161,6 +161,9 @@ private function checkType($data, string $type) { case 'cboolean': $result = ($data == '0' || $data == '1')? true: false; break; + case 'file': + $result = is_file($data); + break; } return $result; }