Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
8.4 kB
1
Indexable
Never
<?php 
    class NGUOIDUNG {
        private $id;
        private $email;
        private $matkhau;
        private $hoten;
        private $diachi;
        private $sdt;
        private $hinhanh;
        private $loai_taikhoan;

        public function getid() { return $this->id; } public function setid($value) { $this->id = $value; }
        public function getemail() { return $this->email; } public function setemail($value) { $this->email = $value; }
        public function getmatkhau() { return $this->matkhau; } public function setmatkhau($value) { $this->matkhau = $value; }
        public function gethoten() { return $this->hoten; } public function sethoten($value) { $this->hoten = $value; }
        public function getdiachi() { return $this->diachi; } public function setdiachi($value) { $this->diachi = $value; }
        public function getsdt() { return $this->sdt; } public function setsdt($value) { $this->sdt = $value; }
        public function gethinhanh() { return $this->hinhanh; } public function sethinhanh($value) { $this->hinhanh = $value; }
        public function getloaitaikhoan() { return $this->loai_taikhoan; } public function setloaitaikhoan($value) { $this->loai_taikhoan = $value; }
    
        public function checkUser($email, $matkhau){
            $db = DATABASE::connect();
            try{
                $sql = "SELECT * FROM taikhoan WHERE email=:email AND matkhau=:matkhau";
                $cmd = $db->prepare($sql);
                $cmd->bindValue(":email", $email);
                $cmd->bindValue(":matkhau", md5($matkhau));
                $cmd->execute();
                $valid = ($cmd->rowCount () == 1);
                $cmd->closeCursor ();
                return $valid;			
            }
            catch(PDOException $e){
                $error_message=$e->getMessage();
                echo "<p>Lỗi truy vấn: $error_message</p>";
                exit();
            }
        }

        public function checkUserAdmin($email, $matkhau){
            $db = DATABASE::connect();
            try{
                $sql = "SELECT * FROM taikhoan WHERE email=:email AND matkhau=:matkhau AND loai_taikhoan > 0";
                $cmd = $db->prepare($sql);
                $cmd->bindValue(":email", $email);
                $cmd->bindValue(":matkhau", md5($matkhau));
                $cmd->execute();
                $valid = ($cmd->rowCount () == 1);
                $cmd->closeCursor ();
                return $valid;			
            }
            catch(PDOException $e){
                $error_message=$e->getMessage();
                echo "<p>Lỗi truy vấn: $error_message</p>";
                exit();
            }
        }

        public function GetInfoUser($email) {
            $db = DATABASE::connect();
            try{
                $sql = "SELECT * FROM taikhoan WHERE email=:email";
                $cmd = $db->prepare($sql);
                $cmd->bindValue(":email", $email);
                $cmd->execute();
                $ketqua = $cmd->fetch();
                $cmd->closeCursor();
                return $ketqua;
            }
            catch(PDOException $e){
                $error_message=$e->getMessage();
                echo "<p>Lỗi truy vấn: $error_message</p>";
                exit();
            }
        }

        /* ĐĂNG KÝ */
        public function themtaikhoan($taikhoan) {
            $db = DATABASE::connect();
            try{
                $sql = "INSERT INTO taikhoan(email,matkhau,hoten,diachi,sdt,hinhanh,loai_taikhoan) VALUES(:email,:matkhau,:hoten,:diachi,:sdt,:hinhanh,:loai_taikhoan)";
                $cmd = $db->prepare($sql);
                $cmd->bindValue(':email',$taikhoan->email);
                $cmd->bindValue(':matkhau', md5($taikhoan->matkhau));
                $cmd->bindValue(':hoten',$taikhoan->hoten);
                $cmd->bindValue(':diachi',$taikhoan->diachi);
                $cmd->bindValue(':sdt',$taikhoan->sdt);
                $cmd->bindValue(':hinhanh',$taikhoan->hinhanh);
                $cmd->bindValue(':loai_taikhoan',$taikhoan->loai_taikhoan);
                $cmd->execute();
                $id = $db->lastInsertId();
                return $id;
            }
            catch(PDOException $e){
                $error_message=$e->getMessage();
                echo "<p>Lỗi truy vấn: $error_message</p>";
                exit();
            }
        }

        public function capnhat_taikhoan($id, $hoten, $sdt, $diachi, $hinhanh){
            $db = DATABASE::connect();
            try{
                $sql = "UPDATE taikhoan set hoten=:hoten, sdt=:sdt, diachi=:diachi, hinhanh=:hinhanh where id=:id";
                $cmd = $db->prepare($sql);
                $cmd->bindValue(':id',$id);
                $cmd->bindValue(':hoten',$hoten);
                $cmd->bindValue(':sdt',$sdt);
                $cmd->bindValue(':diachi',$diachi);
                $cmd->bindValue(':hinhanh',$hinhanh);
                $ketqua = $cmd->execute();            
                return $ketqua;
            }
            catch(PDOException $e){
                $error_message=$e->getMessage();
                echo "<p>Lỗi truy vấn: $error_message</p>";
                exit();
            }
        }

        public function doimatkhau($id, $matkhau){
            $db = DATABASE::connect();
            try{
                $sql = "UPDATE taikhoan set matkhau=:matkhau where id=:id";
                $cmd = $db->prepare($sql);
                $cmd->bindValue(':id',$id);
                $cmd->bindValue(':matkhau', md5($matkhau));
                $ketqua = $cmd->execute();            
                return $ketqua;
            }
            catch(PDOException $e){
                $error_message=$e->getMessage();
                echo "<p>Lỗi truy vấn: $error_message</p>";
                exit();
            }
        }

        /* Admin Panel */
        public function panel_user_insert($taikhoan) {
            $db = DATABASE::connect();
            try{
                $sql = "INSERT INTO taikhoan(email,matkhau) VALUES(:email,:matkhau)";
                $cmd = $db->prepare($sql);
                $cmd->bindValue(':email',$taikhoan->email);
                $cmd->bindValue(':matkhau',md5($taikhoan->matkhau));
                $cmd->execute();
                $id = $db->lastInsertId();
                return $id;
            }
            catch(PDOException $e){
                $error_message=$e->getMessage();
                echo "<p>Lỗi truy vấn: $error_message</p>";
                exit();
            }
        }

        public function panel_user_update($taikhoan){
            $dbcon = DATABASE::connect();
            try{
                $sql = "UPDATE taikhoan SET email=:email, hoten=:hoten, diachi=:diachi, sdt=:sdt, hinhanh=:hinhanh, loai_taikhoan=:loai_taikhoan WHERE id=:id";
                $cmd = $dbcon->prepare($sql);
                $cmd->bindValue(":email", $taikhoan->email);
                $cmd->bindValue(":hoten", $taikhoan->hoten);
                $cmd->bindValue(":diachi", $taikhoan->diachi);
                $cmd->bindValue(":sdt", $taikhoan->sdt);
                $cmd->bindValue(":hinhanh", $taikhoan->hinhanh);
                $cmd->bindValue(":loai_taikhoan", $taikhoan->loai_taikhoan);
                $cmd->bindValue(":id", $taikhoan->id);
                $result = $cmd->execute();            
                return $result;
            }
            catch(PDOException $e){
                $error_message = $e->getMessage();
                echo "<p>Lỗi truy vấn: $error_message</p>";
                exit();
            }
        }

        public function panel_user_delete($taikhoan){
            $dbcon = DATABASE::connect();
            try{
                $sql = "DELETE FROM taikhoan WHERE id=:id"; 
                $cmd = $dbcon->prepare($sql);
                $cmd->bindValue(":id", $taikhoan->id);
                $result = $cmd->execute();            
                return $result;
            }
            catch(PDOException $e){
                $error_message = $e->getMessage();
                echo "<p>Lỗi truy vấn: $error_message</p>";
                exit();
            }
        }
    }
?>
Leave a Comment