From 042333b96c0b4e884bc081980dec5c80e13f56c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mu=C3=B1oz=20Garcia?= <73303506+danimu03@users.noreply.github.com> Date: Thu, 6 May 2021 12:16:37 +0200 Subject: [PATCH] Debud / new function in user_dao.php --- assets/php/common/manager.php | 15 ++++---- assets/php/common/manager_dao.php | 61 +++++++++++++++---------------- assets/php/common/user_dao.php | 12 ++++++ 3 files changed, 48 insertions(+), 40 deletions(-) diff --git a/assets/php/common/manager.php b/assets/php/common/manager.php index 4a80b49..6c79ae9 100644 --- a/assets/php/common/manager.php +++ b/assets/php/common/manager.php @@ -6,15 +6,14 @@ private $_id; //Manager ID. private $_username; //Manager username. private $_email; //Email. - private $_pass; //Pass. private $_roll; //Roll //Constructor: - function __construct($id, $username, $email, $pass, $roll){ + function __construct($id, $idcinema, $username, $email, $roll){ $this->_id = $id; + $this->_idcinema = $idcinema; $this->_username = $username; $this->_email = $email; - $this->_pass = $pass; $this->_roll = $roll; } @@ -23,14 +22,14 @@ //Getters && Setters: public function setId($id){ $this->_id = $id; } public function getId(){ return $this->_id; } + public function setIdcinema($idcinema){ $this->_idcinema = $idcinema; } + public function getIdcinema(){ return $this->_idcinema; } public function setUsername($username){$this->_username = $username; } - public function getUsername(){ return $this->_username = $username; } + public function getUsername(){ return $this->_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 getEmail(){return $this->_email;} public function setRoll($roll){$this->_roll = $roll;} - public function getRoll(){return $this->_roll = $roll;} + public function getRoll(){return $this->_roll;} } ?> \ No newline at end of file diff --git a/assets/php/common/manager_dao.php b/assets/php/common/manager_dao.php index d4002e4..d646bcc 100644 --- a/assets/php/common/manager_dao.php +++ b/assets/php/common/manager_dao.php @@ -12,33 +12,14 @@ } //Methods: - - //Create a new user Manager. - public function createManager($id, $username, $email, $pass, $rol){ - $password = $this->encryptPass($pass); - $sql = sprintf( "INSERT INTO `users`( `id`, `username`, `email`, `passwd`, `rol`) - VALUES ( '%d', '%s', '%s', '%s', '%s')", - $id, $username, $email, $password, $rol); - - $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); - return $resul; - } - - private function encryptPass($password){ - //$password = hash('sha256', $password); - $password = password_hash($password, PASSWORD_DEFAULT); - - return $password; - } - //Returns a query to get All the managers. public function allManagersData(){ - $sql = sprintf( "SELECT * FROM users WHERE users.rol=manager"); + $sql = sprintf( "SELECT * FROM `users` JOIN `manager` ON manager.id = users.id"); $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"]); + $managers[] = $this->loadManager($fila["id"], $fila["idcinema"], $fila["username"], $fila["email"], $fila["rol"]); } $resul->free(); return $managers; @@ -46,12 +27,29 @@ //Returns a manager data . public function GetManager($id){ - $sql = sprintf( "SELECT * FROM users WHERE users.id = '%d'", $id ); + $sql = sprintf( "SELECT * FROM `manager` WHERE manager.id = '%d'", $id ); + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + return $resul; + } + + //Returns a manager data . + public function GetManagerCinema($id, $idcinema){ + $sql = sprintf( "SELECT * FROM `manager` WHERE manager.id = '%d' AND manager.idcinema ='%d'", $id, $idcinema ); + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + return $resul; + } + + //Create a new Session. + public function createManager($id, $idcinema){ + $sql = sprintf( "INSERT INTO `manager`( `id`, `idcinema`) + VALUES ( '%d', '%d')", + $id, $idcinema); + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); return $resul; } - public function selectManager($username){ + /*public function selectManager($username){ $username = $this->mysqli->real_escape_string($username); $sql = sprintf( "SELECT * FROM users WHERE username = '%s'", $username ); @@ -66,12 +64,12 @@ $resul->free(); return $user; - } + } */ //Deleted manager by "id". public function deleteManager($id){ - $sql = sprintf( "DELETE FROM users WHERE users.id = '%d' ;",$id); + $sql = sprintf( "DELETE FROM `manager` WHERE manager.id = '%d' ;",$id); $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); @@ -79,11 +77,10 @@ } //Edit manager. - public function editManager($id, $username, $email, $pass, $rol){ - $password = $this->encryptPass($pass); - $sql = sprintf( "UPDATE users SET email = '%s' , passwd = '%s', - WHERE users.id = '%d';", - $email, $password, $id); + public function editManager($id, $idcinema){ + $sql = sprintf( "UPDATE `manager` SET manager.idcinema = '%d' + WHERE manager.id = '%d';", + $idcinema, $id); $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); @@ -91,8 +88,8 @@ } //Create a new Manager Data Transfer Object. - public function loadManager($id, $username, $email, $pass, $rol){ - return new Manager($id, $username, $email, $pass, $rol); + public function loadManager($id, $idcinema, $username, $email, $rol){ + return new Manager($id, $idcinema, $username, $email, $rol); } } diff --git a/assets/php/common/user_dao.php b/assets/php/common/user_dao.php index 3c8f7e3..23a8fce 100644 --- a/assets/php/common/user_dao.php +++ b/assets/php/common/user_dao.php @@ -31,6 +31,18 @@ return password_verify($password, $passwd); } + + //All users + public function allUsersNotM(){ + $sql = sprintf( "SELECT * FROM `users` WHERE users.id NOT IN (SELECT id FROM `manager`)"); + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + while($fila=$resul->fetch_assoc()){ + $users[] = $this->loadUser($fila['id'], $fila['username'], $fila['email'], $fila['passwd'], $fila['rol']); + } + $resul->free(); + return $users; + } //Create a new User. public function createUser($id, $username, $email, $password, $rol){ $password = $this->encryptPass($password);