diff --git a/Controllers/ManageUserController.php b/Controllers/ManageUserController.php new file mode 100644 index 0000000..4695201 --- /dev/null +++ b/Controllers/ManageUserController.php @@ -0,0 +1,40 @@ +searchUsers($S_query); + + var_dump($A_results); + + echo "Terme de recherche choisi: $S_query"; + + View::show("manageUser/search"); + } + +} diff --git a/Kernel/Session.php b/Kernel/Session.php index ed67da9..cc70040 100644 --- a/Kernel/Session.php +++ b/Kernel/Session.php @@ -64,4 +64,15 @@ final class Session die(); } } + + public static function admin_or_die(){ + Session::login_or_die(); + + $O_userModel = new UserModel(); + if (!$O_userModel->isUserAdmin($_SESSION["ID"])) { + header("Location: /"); + die(); + } + } + } diff --git a/Models/UserModel.php b/Models/UserModel.php index 43ff52d..55c9f10 100644 --- a/Models/UserModel.php +++ b/Models/UserModel.php @@ -69,6 +69,18 @@ final class UserModel if ($row === false) return false; return $row["DISABLED"] !== 1; } + + public function isUserAdmin($I_id) + { + $O_model = Model::get(); + $stmt = $O_model->prepare("SELECT ADMIN FROM USER WHERE ID=:id"); + $stmt->bindParam("id", $I_id); + $stmt->execute(); + + $row = $stmt->fetch(); + if ($row === false) return false; + return $row["ADMIN"] === 1; + } public function updateEmailByID($I_id, $S_newEmail){ $O_model = Model::get(); @@ -92,4 +104,22 @@ final class UserModel $stmt->bindParam("id", $I_id); $stmt->execute(); } + + public function searchUsers($S_query) + { + $O_model = Model::get(); + $stmt = $O_model->prepare(" + SELECT * FROM USER + WHERE USER.USERNAME LIKE :full_query + OR USER.EMAIL LIKE :full_query + LIMIT 10 + "); + $S_full_query = "%".$S_query."%"; + $stmt->bindParam("full_query", $S_full_query); + $stmt->execute(); + + $rows = $stmt->fetchAll(); + + return $rows; + } } diff --git a/Views/manageUser/search.php b/Views/manageUser/search.php new file mode 100644 index 0000000..ebea856 --- /dev/null +++ b/Views/manageUser/search.php @@ -0,0 +1,7 @@ +

Default view

+ +

Please search :

+
+ + +