/var/www/myprog.com.ua/site/libs
Edit: /var/www/myprog.com.ua/site/libs/class.model.php (1734B)
database = new database(DB_TYPE,DB_HOST,DB_NAME,DB_USER,DB_PASS,ENCODE);
$this->form = form::getInstance();
}
final private function getRolePerms($role_id) {
$sql = "SELECT p.alias
FROM `role_perm` AS rp
INNER JOIN `permissions` as p ON(rp.perm_id=p.perm_id)
WHERE rp.role_id= :role";
$sth = $this->database->prepare($sql);
$sth->execute(array(':role'=>$role_id));
while($row = $sth->fetch() ){
$this->_permissions[$row["alias"]] = true;
}
return $this->_permissions;
}
final private function initRoles (){
$sql = "SELECT ur.role_id, r.role_name
FROM `user_role` AS ur
INNER JOIN `roles` AS r ON(ur.role_id=r.role_id)
WHERE ur.user_id =:uid";
$sth= $this->database->prepare($sql);
$sth->execute(array(':uid'=>session::get('id_user')));
while($row = $sth->fetch(PDO::FETCH_ASSOC)) {
$this->roles[$row["role_name"]] = $this->getRolePerms($row["role_id"]);
}
}
// Проверка установленных полномочий
final private function hasPerm($permission) {
return isset($this->_permissions[$permission]);
}
final public function hasPrivilege($perm) {
$this->initRoles();
foreach ($this->roles as $role) {
if ($this->hasPerm($perm)) {
return true;
}
}
return false;
}
}
?>