Skip to content

Commit

Permalink
21/11/2022 15:31hs
Browse files Browse the repository at this point in the history
  • Loading branch information
cervisebas committed Nov 21, 2022
1 parent 7311f19 commit 277a27d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
21 changes: 21 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down
34 changes: 34 additions & 0 deletions scripts/directives.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions scripts/filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}

?>
3 changes: 3 additions & 0 deletions scripts/verifyData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 277a27d

Please sign in to comment.