<?php
    session_start();
    class Rights {
        public $role_id ;
        public $db;
        public $menu_rights;
        public $id;
        public function __set($name,$value){
            $this->$name = $value;
        }
        public function __get($name){
            return $this->$name;
        }
        public function fill_rights_arr ($db){
            
            $menu_rights = array ();
            $query = "SELECT rights.right_name,u_rights.state FROM wm_users AS users LEFT JOIN wm_user_rights AS u_rights ON u_rights.user_id = users.id LEFT JOIN wm_rights AS rights ON u_rights.right_id = rights.id WHERE users.id = ? ";
            if ($stmt = $db->prepare($query)){
                $stmt->bind_param('s', $this->id);
                $stmt->execute();
                $stmt->bind_result($menu_name,$menu_status);
                while ($result = $stmt->fetch()) {
                    $this->menu_rights[$menu_name]=$menu_status;
                }
                    
            }
            $db->close();
            return $this->menu_rights;
        }
        public function hasAccess ($permission_name) {
            return $this->menu_rights[$permission_name];
        }
    }
?>
