From c3e5b151b023034e4131ec98e03d483e3213eec5 Mon Sep 17 00:00:00 2001 From: Peter Hoppe Date: Thu, 2 Mar 2023 22:02:38 +0100 Subject: [PATCH] =?UTF-8?q?prolif=20l=C3=B6schen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- php/php-dog/classes/lib.php | 12 +++++++++++- php/php-dog/deleteProfil.php | 32 +++++++++++++++++++++++++------- src/App.tsx | 2 +- src/components/DogNavbar.tsx | 28 ++++++++++++++++++++++++---- src/services/PhpApi.ts | 15 +++++++++++++++ 5 files changed, 76 insertions(+), 13 deletions(-) diff --git a/php/php-dog/classes/lib.php b/php/php-dog/classes/lib.php index 1f19dfe..9a94db1 100644 --- a/php/php-dog/classes/lib.php +++ b/php/php-dog/classes/lib.php @@ -179,5 +179,15 @@ function getDogByQrId($qr_id, $conn, $fields = null) } return $returnData; } - +function deleteDir($dir) +{ + foreach(glob($dir . '/*') as $file) + { + if(!is_dir($file)) + { + unlink($file); + } + } + return rmdir($dir); +} ?> diff --git a/php/php-dog/deleteProfil.php b/php/php-dog/deleteProfil.php index 9491722..ab6ee32 100644 --- a/php/php-dog/deleteProfil.php +++ b/php/php-dog/deleteProfil.php @@ -18,7 +18,7 @@ require __DIR__.'/classes/lib.php'; $db_connection = new Database(); $conn = $db_connection->dbConnection(); -//var_dump($_POST); +$data = json_decode(file_get_contents("php://input")); //IF REQUEST METHOD IS NOT EQUAL TO POST if($_SERVER["REQUEST_METHOD"] != "POST") @@ -28,27 +28,45 @@ if($_SERVER["REQUEST_METHOD"] != "POST") return; } +$returnData = new CMsg(0); + if( - !isset($_POST['qr_id']) - || !isset($_POST['qr_id']) + !isset($data->qr_id) + || !isset($data->qr_id) ) { $fields = ['fields' => ['qr_id']]; $returnData = new CMsg(0, 422, 'Please Fill in all Required Fields!', $fields); - echo $returnData->jsonarray(); - return; } else { try { + $qr_id = $data->qr_id; $stmt = $conn->prepare("DELETE FROM `dogs` WHERE `qr_id`=?"); $stmt->execute([$qr_id]); if($stmt->rowCount()) { - // delete upload dir + if(deleteDir('../uploads/' . $qr_id)) + { + $returnData = new CMsg(1, 200, 'Profile deleted!'); + } + else + { + $returnData = new CMsg(0, 500, 'Can\'t delete Directory: '. + '../uploads/' . $qr_id); + } } - + else + { + $returnData = new CMsg(0, 500, 'Can\'t delete Profil in Database'); + } + } + catch(PDOException $e) + { + $returnData = new CMsg(0,500,"deleteProfil ".$e->getMessage()); } } +echo $returnData->jsonarray(); +return; diff --git a/src/App.tsx b/src/App.tsx index e6c2e9d..68b8cc6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -87,7 +87,7 @@ const App: React.FC = () => padding={0} fixed navbarOffsetBreakpoint="sm" - navbar={