From c3371e41f122cd096663292035dbeecb366698fe Mon Sep 17 00:00:00 2001 From: marian1010 <79144276+marian1010@users.noreply.github.com> Date: Wed, 5 May 2021 19:23:09 +0200 Subject: [PATCH] Add/edit/del manager todavia incompleto falta terminar y probar --- assets/php/common/manager.php | 36 ++++++ assets/php/common/manager_dao.php | 91 +++++++++++++ panel_admin/includes/formManager.php | 148 +++++++++++++++++++++ panel_admin/manage_managers.php | 186 +++++++++++++++++++++++++++ 4 files changed, 461 insertions(+) create mode 100644 assets/php/common/manager.php create mode 100644 assets/php/common/manager_dao.php create mode 100644 panel_admin/includes/formManager.php create mode 100644 panel_admin/manage_managers.php diff --git a/assets/php/common/manager.php b/assets/php/common/manager.php new file mode 100644 index 0000000..4a80b49 --- /dev/null +++ b/assets/php/common/manager.php @@ -0,0 +1,36 @@ +_id = $id; + $this->_username = $username; + $this->_email = $email; + $this->_pass = $pass; + $this->_roll = $roll; + } + + //Methods: + + //Getters && Setters: + public function setId($id){ $this->_id = $id; } + public function getId(){ return $this->_id; } + public function setUsername($username){$this->_username = $username; } + public function getUsername(){ return $this->_username = $username; } + public function setEmail($email){$this->_email = $email;} + public function getEmail(){return $this->_email = $email;} + public function setPass($pass){$this->_pass = $pass;} + public function getPass(){return $this->pass;} + public function setRoll($roll){$this->_roll = $roll;} + public function getRoll(){return $this->_roll = $roll;} + + } +?> \ No newline at end of file diff --git a/assets/php/common/manager_dao.php b/assets/php/common/manager_dao.php new file mode 100644 index 0000000..67d4f71 --- /dev/null +++ b/assets/php/common/manager_dao.php @@ -0,0 +1,91 @@ +get_prefix(); + include_once($prefix.'assets/php/dao.php'); + + class Manager_DAO extends DAO { + + //Constructor: + function __construct($bd_name){ + parent::__construct($bd_name); + } + + //Methods: + + //Create a new user Manager. + public function createManager($id, $username, $email, $pass, $rol){ + $sql = sprintf( "INSERT INTO `users`( `id`, `username`, `email`, `password`, `rol`) + VALUES ( '%d', '%s', '%s', '%s', '%s')", + $id, $username, $email, $pass, $rol); + + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + return $resul; + } + + + //Returns a query to get All the managers. + public function allManagersData(){ + $sql = sprintf( "SELECT * FROM users WHERE users.rol=manager"); + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + while($fila=$resul->fetch_assoc()){ + $managers[] = $this->loadManager($fila["id"], $fila["username"], $fila["email"], $fila["password"], $fila["rol"]); + } + $resul->free(); + return $managers; + } + + //Returns a manager data . + public function GetManager($id){ + $sql = sprintf( "SELECT * FROM users WHERE users.id = '%d'", $id ); + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + return $resul; + } + + public function selectManager($username){ + $username = $this->mysqli->real_escape_string($username); + + $sql = sprintf( "SELECT * FROM users WHERE username = '%s'", $username ); + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + $resul->data_seek(0); + while ($fila = $resul->fetch_assoc()) { + $user = $this->loadUser($fila['id'], $fila['username'], $fila['email'], $fila['passwd'], $fila['rol']); + } + + //mysqli_free_result($selectUser); + $resul->free(); + + return $user; + } + + + //Deleted manager by "id". + public function deleteManager($id){ + $sql = sprintf( "DELETE FROM users WHERE users.id = '%d' ;",$id); + + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + return $resul; + } + + //Edit manager. + public function editManager($id, $username, $email, $pass, $rol){ + $sql = sprintf( "UPDATE users SET email = '%s' , pass = '%s', + WHERE users.id = '%d';", + $email, $pass, $id); + + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + return $resul; + } + + //Create a new Manager Data Transfer Object. + public function loadManager($id, $username, $email, $pass, $rol){ + return new Manager($id, $username, $email, $pass, $rol); + } + + } + +?> diff --git a/panel_admin/includes/formManager.php b/panel_admin/includes/formManager.php new file mode 100644 index 0000000..106fcdd --- /dev/null +++ b/panel_admin/includes/formManager.php @@ -0,0 +1,148 @@ +reply = array(); + } + + public function getReply() { + if($this->correct){ + if($this->option == "new"){ + $this->reply = "
Id | +Nombre | +password | +Rol | +|||
---|---|---|---|---|---|---|
'. $ids[$i] .' | +'. $usernames[$i] .' | +'. $email[$i] .' | +'. $pass[$i] .' | +'. $rol[$i] .' | ++ + | ++ + | +